]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove broad exception catch from periodic_sync_routers_task
authorCarl Baldwin <carl.baldwin@hp.com>
Tue, 28 Oct 2014 17:30:55 +0000 (17:30 +0000)
committerCedric Brandily <zzelle@gmail.com>
Thu, 11 Dec 2014 15:37:05 +0000 (15:37 +0000)
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 <zzelle@gmail.com>
Co-Authored-By: Carl Baldwin <carl.baldwin@hp.com>
Change-Id: I6281886f3334100a18952578250c8154a0ed15a9

neutron/agent/l3/agent.py
neutron/tests/unit/test_l3_agent.py

index 9ddf430f92a7bcad4decc34179b2b7db405cd309..7013d311e5dc778e9c2c24543724e5ceb96ff936 100644 (file)
@@ -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:
index e50eda7cc00aef1119f083500bb39b989fe9edeb..23ae1a31cfa20d12ed0febf792416d23571e4449 100644 (file)
@@ -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):