]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Big Switch: Catch exceptions in watchdog thread
authorKevin Benton <blak111@gmail.com>
Mon, 9 Jun 2014 07:59:40 +0000 (00:59 -0700)
committerKevin Benton <blak111@gmail.com>
Mon, 9 Jun 2014 08:23:10 +0000 (01:23 -0700)
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
neutron/tests/unit/bigswitch/test_servermanager.py

index 42d89222f4dce9b76317fdea5ba3cd0b5b7062f6..c39c4e9f09518a1d25017b51de07f5669147e702 100644 (file)
@@ -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):
index 6c7640fbafacd1b26b9751c6ab73b7c456b08a52..3a54e315b8c234e27b9ab417b81e4260e1df82f2 100644 (file)
@@ -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