ns_to_ignore = self._get_routers_namespaces(router_ids)
ns_to_destroy = router_namespaces - ns_to_ignore
- self._destroy_stale_router_namespaces(ns_to_destroy)
-
- def _destroy_stale_router_namespaces(self, router_namespaces):
- """Destroys the stale router namespaces
-
- The argumenet router_namespaces is a list of stale router namespaces
-
- As some stale router namespaces may not be able to be deleted, only
- one attempt will be made to delete them.
- """
- for ns in router_namespaces:
+ for ns in ns_to_destroy:
try:
self._destroy_namespace(ns)
except RuntimeError:
while True:
pool.spawn_n(self._process_router_update)
- def _router_ids(self):
- if not self.conf.use_namespaces:
- return [self.conf.router_id]
-
@periodic_task.periodic_task
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)
- LOG.debug("Starting _sync_routers_task - fullsync:%s",
+ LOG.debug("Starting periodic_sync_routers_task - fullsync:%s",
self.fullsync)
if not self.fullsync:
return
prev_router_ids = set(self.router_info)
try:
- router_ids = self._router_ids()
timestamp = timeutils.utcnow()
- routers = self.plugin_rpc.get_routers(
- context, router_ids)
+ if self.conf.use_namespaces:
+ routers = self.plugin_rpc.get_routers(context)
+ else:
+ routers = self.plugin_rpc.get_routers(context,
+ [self.conf.router_id])
LOG.debug('Processing :%r', routers)
for r in routers:
timestamp=timestamp)
self._queue.add(update)
self.fullsync = False
- LOG.debug("_sync_routers_task successfully completed")
+ LOG.debug("periodic_sync_routers_task successfully completed")
except messaging.MessagingException:
LOG.exception(_LE("Failed synchronizing routers due to RPC error"))
self.fullsync = True
return agent, ri, port
- def test__sync_routers_task_raise_exception(self):
+ def test_periodic_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)
+ agent.periodic_sync_routers_task(agent.context)
self.assertFalse(f.called)
- def test__sync_routers_task_call_clean_stale_namespaces(self):
+ def test_periodic_sync_routers_task_call_clean_stale_namespaces(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
self.plugin_api.get_routers.return_value = []
with mock.patch.object(agent, '_cleanup_namespaces') as f:
- agent._sync_routers_task(agent.context)
+ agent.periodic_sync_routers_task(agent.context)
self.assertTrue(f.called)
def test_router_info_create(self):
# The unexpected exception has been fixed manually
internal_network_added.side_effect = None
- # _sync_routers_task finds out that _rpc_loop failed to process the
- # router last time, it will retry in the next run.
+ # periodic_sync_routers_task finds out that _rpc_loop failed to
+ # process the router last time, it will retry in the next run.
agent.process_router(ri)
# We were able to add the port to ri.internal_ports
self.assertIn(
# The unexpected exception has been fixed manually
internal_net_removed.side_effect = None
- # _sync_routers_task finds out that _rpc_loop failed to process the
- # router last time, it will retry in the next run.
+ # periodic_sync_routers_task finds out that _rpc_loop failed to
+ # process the router last time, it will retry in the next run.
agent.process_router(ri)
# We were able to remove the port from ri.internal_ports
self.assertNotIn(
self.conf.set_override('router_id', '1234')
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
- self.assertEqual(['1234'], agent._router_ids())
+ self.assertEqual('1234', agent.conf.router_id)
self.assertFalse(agent._clean_stale_namespaces)
def test_process_router_if_compatible_with_no_ext_net_in_conf(self):