]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Tighten up try/except block around rpc call
authorCarl Baldwin <carl.baldwin@hp.com>
Tue, 21 Oct 2014 19:44:18 +0000 (19:44 +0000)
committerCedric Brandily <zzelle@gmail.com>
Fri, 21 Nov 2014 09:13:56 +0000 (10:13 +0100)
The try is too broad.  This commit moves code outside of the try block
where exceptions are not expected to be raised.  This only leaves the
rpc call in the current code.  In legacy code, there used to be more
but now this code merely queues updates for workers to handle
in other threads.

Change-Id: I15407553fc6ad6eeb5b483499fe1a5adffe1edca

neutron/agent/l3_agent.py

index 912a029f285c58489257c50ec4dc263883680bac..fab376c257e3782010c09528c70181f802daf400 100644 (file)
@@ -1850,15 +1850,22 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
         if self._clean_stale_namespaces:
             namespaces = self._list_namespaces()
         prev_router_ids = set(self.router_info)
+        timestamp = timeutils.utcnow()
 
         try:
-            timestamp = timeutils.utcnow()
             if self.conf.use_namespaces:
                 routers = self.plugin_rpc.get_routers(context)
             else:
                 routers = self.plugin_rpc.get_routers(context,
                                                       [self.conf.router_id])
 
+        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:
                 update = RouterUpdate(r['id'],
@@ -1868,13 +1875,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
                 self._queue.add(update)
             self.fullsync = False
             LOG.debug("periodic_sync_routers_task successfully completed")
-        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:
+
             # Resync is not necessary for the cleanup of stale namespaces
             curr_router_ids = set([r['id'] for r in routers])