Clean out namespaces even if we don't delete namespaces

Even when we don't enable namespace deletion, we still want to run the
code that cleans out the namespaces so that the devices get unplugged,
etc.  Otherwise, routers deleted while the agent is down will continue
to operate as if they were never deleted.

The trade-off to consider here is that if there are many stale
namespaces this will slow down the restart of the L3 agent.  The best
option is to get namespace deletion working correctly.  However, where
that has not been worked out yet, this patch provides the cleaning
service for deleted routers.

Change-Id: Ic7b4608a23c4d9530f521d5faff3f8526200b92e
Closes-Bug: #1301042
Related-Bug: #1052535
This commit is contained in:
Carl Baldwin 2014-04-01 22:16:59 +00:00
parent a86bc415b6
commit 8ab6fd6d7e
2 changed files with 7 additions and 8 deletions

View File

@ -220,8 +220,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
self.removed_routers = set()
self.sync_progress = False
self._delete_stale_namespaces = (self.conf.use_namespaces and
self.conf.router_delete_namespaces)
self._clean_stale_namespaces = self.conf.use_namespaces
self.rpc_loop = loopingcall.FixedIntervalLoopingCall(
self._rpc_loop)
@ -249,7 +248,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
def _cleanup_namespaces(self, routers):
"""Destroy stale router namespaces on host when L3 agent restarts
This routine is called when self._delete_stale_namespaces is True.
This routine is called when self._clean_stale_namespaces is True.
The argument routers is the list of routers that are recorded in
the database as being hosted on this node.
@ -285,7 +284,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
except RuntimeError:
LOG.exception(_('Failed to destroy stale router namespace '
'%s'), ns)
self._delete_stale_namespaces = False
self._clean_stale_namespaces = False
def _destroy_router_namespace(self, namespace):
ns_ip = ip_lib.IPWrapper(self.root_helper, namespace=namespace)
@ -864,7 +863,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
# Resync is not necessary for the cleanup of stale
# namespaces.
if self._delete_stale_namespaces:
if self._clean_stale_namespaces:
self._cleanup_namespaces(routers)
def after_start(self):

View File

@ -984,7 +984,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
self.conf.set_override('router_id', '1234')
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
self.assertEqual(['1234'], agent._router_ids())
self.assertFalse(agent._delete_stale_namespaces)
self.assertFalse(agent._clean_stale_namespaces)
def test_process_routers_with_no_ext_net_in_conf(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
@ -1130,7 +1130,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
self.assertTrue(agent._delete_stale_namespaces)
self.assertTrue(agent._clean_stale_namespaces)
pm = self.external_process.return_value
pm.reset_mock()
@ -1144,7 +1144,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
expected_args = [mock.call(ns) for ns in stale_namespace_list]
agent._destroy_router_namespace.assert_has_calls(expected_args,
any_order=True)
self.assertFalse(agent._delete_stale_namespaces)
self.assertFalse(agent._clean_stale_namespaces)
def test_cleanup_namespace(self):
self.conf.set_override('router_id', None)