From: Carl Baldwin Date: Tue, 28 Oct 2014 17:30:55 +0000 (+0000) Subject: Remove broad exception catch from periodic_sync_routers_task X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=45340e5e7ddb1b1ba98d8bcf1153769b98ca0084;p=openstack-build%2Fneutron-build.git Remove broad exception catch from periodic_sync_routers_task Although this change removes a broad exception from periodic_sync_routers_task (neutron.agent.l3_agent), the implementation still ensures if an exception --caught or uncaught -- prevents a call to the method to disable the fullsync, then the next call to the method will perform a fullsync again. Author: Cedric Brandily Co-Authored-By: Carl Baldwin Change-Id: I6281886f3334100a18952578250c8154a0ed15a9 --- diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 9ddf430f9..7013d311e 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -1560,6 +1560,10 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, if not self.fullsync: return + # self.fullsync is True at this point. If an exception -- caught or + # uncaught -- prevents setting it to False below then the next call + # to periodic_sync_routers_task will re-enter this code and try again. + # Capture a picture of namespaces *before* fetching the full list from # the database. This is important to correctly identify stale ones. namespaces = set() @@ -1577,10 +1581,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, except messaging.MessagingException: LOG.exception(_LE("Failed synchronizing routers due to RPC error")) - self.fullsync = True - except Exception: - LOG.exception(_LE("Failed synchronizing routers")) - self.fullsync = True else: LOG.debug('Processing :%r', routers) for r in routers: diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index e50eda7cc..23ae1a31c 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -271,9 +271,11 @@ class TestBasicRouterOperations(base.BaseTestCase): def test_periodic_sync_routers_task_raise_exception(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) - self.plugin_api.get_routers.side_effect = Exception() + self.plugin_api.get_routers.side_effect = ValueError() with mock.patch.object(agent, '_cleanup_namespaces') as f: - agent.periodic_sync_routers_task(agent.context) + self.assertRaises(ValueError, agent.periodic_sync_routers_task, + agent.context) + self.assertTrue(agent.fullsync) self.assertFalse(f.called) def test_periodic_sync_routers_task_call_clean_stale_namespaces(self):