@periodic_task.periodic_task
@lockutils.synchronized('l3-agent', 'neutron-')
+ def periodic_sync_routers_task(self, context):
+ self._sync_routers_task(context)
+
def _sync_routers_task(self, context):
if self.services_sync:
super(L3NATAgent, self).process_services_sync(context)
except n_rpc.RPCException:
LOG.exception(_("Failed synchronizing routers due to RPC error"))
self.fullsync = True
- return
except Exception:
LOG.exception(_("Failed synchronizing routers"))
self.fullsync = True
-
- # Resync is not necessary for the cleanup of stale
- # namespaces.
- if self._clean_stale_namespaces:
- self._cleanup_namespaces(routers)
+ else:
+ # Resync is not necessary for the cleanup of stale namespaces
+ if self._clean_stale_namespaces:
+ self._cleanup_namespaces(routers)
def after_start(self):
LOG.info(_("L3 agent started"))
'neutron.openstack.common.loopingcall.FixedIntervalLoopingCall')
self.looping_call_p.start()
+ def test__sync_routers_task_raise_exception(self):
+ agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
+ self.plugin_api.get_routers.side_effect = Exception()
+ with mock.patch.object(agent, '_cleanup_namespaces') as f:
+ agent._sync_routers_task(agent.context)
+ self.assertFalse(f.called)
+
+ def test__sync_routers_task_call_clean_stale_namespaces(self):
+ agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
+ self.plugin_api.get_routers.return_value = mock.ANY
+ with mock.patch.object(agent, '_cleanup_namespaces') as f:
+ with mock.patch.object(agent, '_process_routers') as g:
+ agent._sync_routers_task(agent.context)
+ self.assertTrue(f.called)
+ g.assert_called_with(mock.ANY, all_routers=True)
+
def test_router_info_create(self):
id = _uuid()
ri = l3_agent.RouterInfo(id, self.conf.root_helper,