From f89a6bd30b6f99bc39f266ae8d3880380379f8b9 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Mon, 9 Jun 2014 00:59:40 -0700 Subject: [PATCH] Big Switch: Catch exceptions in watchdog thread Catch and log exceptions in the watchdog greenthread to prevent them from stopping the periodic consistency checks. Closes-Bug: #1330135 Change-Id: I6834c0fee0429bb72b8c61307be7bdca77f6de9b --- neutron/plugins/bigswitch/servermanager.py | 6 +++++- neutron/tests/unit/bigswitch/test_servermanager.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/neutron/plugins/bigswitch/servermanager.py b/neutron/plugins/bigswitch/servermanager.py index 42d89222f..c39c4e9f0 100644 --- a/neutron/plugins/bigswitch/servermanager.py +++ b/neutron/plugins/bigswitch/servermanager.py @@ -556,7 +556,11 @@ class ServerPool(object): # doesn't match, the backend will return a synchronization error # that will be handled by the rest_action. eventlet.sleep(polling_interval) - self.rest_action('GET', HEALTH_PATH) + try: + self.rest_action('GET', HEALTH_PATH) + except Exception: + LOG.exception(_("Encountered an error checking controller " + "health.")) class HTTPSConnectionWithValidation(httplib.HTTPSConnection): diff --git a/neutron/tests/unit/bigswitch/test_servermanager.py b/neutron/tests/unit/bigswitch/test_servermanager.py index 6c7640fba..3a54e315b 100644 --- a/neutron/tests/unit/bigswitch/test_servermanager.py +++ b/neutron/tests/unit/bigswitch/test_servermanager.py @@ -83,17 +83,22 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase): mock.patch( SERVERMANAGER + '.ServerPool.rest_call', side_effect=servermanager.RemoteRestError( - reason='Failure to break loop' + reason='Failure to trigger except clause.' ) + ), + mock.patch( + SERVERMANAGER + '.LOG.exception', + side_effect=KeyError('Failure to break loop') ) - ) as (smock, rmock): + ) as (smock, rmock, lmock): # should return immediately without consistency capability pl.servers._consistency_watchdog() self.assertFalse(smock.called) pl.servers.capabilities = ['consistency'] - self.assertRaises(servermanager.RemoteRestError, + self.assertRaises(KeyError, pl.servers._consistency_watchdog) rmock.assert_called_with('GET', '/health', '', {}, [], False) + self.assertEqual(1, len(lmock.mock_calls)) def test_consistency_hash_header(self): # mock HTTP class instead of rest_call so we can see headers -- 2.45.2