DVR: Don't clean snat-ns of DVR HA router when fullsync

Since [1], when the l3 agent does fullsync, for every router, it calls
ensure_snat_cleanup depending on whether the agent is dvr_snat or not.
However, DVR+HA routers always have snat namespaces on dvr_snat agents
holding themselves for keepalived. Therefore, the cleanup call is
unexpected and will cause a series of issues.

This patch ensures that snat namespaces of DVR+HA routers will not be
cleaned when the agent do fullsync.

[1] https://review.openstack.org/#/c/326729/

Change-Id: I5df0a1404f1a80ab0b226d7a60c2885e24247e02
Closes-Bug: #1632540
(cherry picked from commit 1346b4a657)
This commit is contained in:
Quan Tian 2017-02-16 20:28:45 +08:00 committed by Swaminathan Vasudevan
parent 9587efc01b
commit 4318de7add
2 changed files with 24 additions and 1 deletions

View File

@ -586,7 +586,7 @@ class L3NATAgent(ha.AgentMixin,
lib_const.L3_AGENT_MODE_DVR_SNAT)
if ext_net_id:
ns_manager.keep_ext_net(ext_net_id)
elif is_snat_agent:
elif is_snat_agent and not r.get('ha'):
ns_manager.ensure_snat_cleanup(r['id'])
# For HA routers check that DB state matches actual state
if r.get('ha'):

View File

@ -36,6 +36,7 @@ from neutron.agent.l3 import dvr_edge_router as dvr_router
from neutron.agent.l3 import dvr_snat_ns
from neutron.agent.l3 import legacy_router
from neutron.agent.l3 import link_local_allocator as lla
from neutron.agent.l3 import namespace_manager
from neutron.agent.l3 import namespaces
from neutron.agent.l3 import router_info as l3router
from neutron.agent.l3 import router_processing_queue
@ -298,6 +299,28 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
agent.periodic_sync_routers_task(agent.context)
self.assertFalse(agent.namespaces_manager._clean_stale)
def test_periodic_sync_routers_task_call_ensure_snat_cleanup(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
agent.conf.agent_mode = 'dvr_snat'
dvr_ha_router = {'id': _uuid(),
'external_gateway_info': {},
'routes': [],
'distributed': True,
'ha': True}
dvr_router = {'id': _uuid(),
'external_gateway_info': {},
'routes': [],
'distributed': True,
'ha': False}
routers = [dvr_router, dvr_ha_router]
self.plugin_api.get_router_ids.return_value = [r['id'] for r
in routers]
self.plugin_api.get_routers.return_value = routers
with mock.patch.object(namespace_manager.NamespaceManager,
'ensure_snat_cleanup') as ensure_snat_cleanup:
agent.periodic_sync_routers_task(agent.context)
ensure_snat_cleanup.assert_called_once_with(dvr_router['id'])
def test_periodic_sync_routers_task_call_clean_stale_meta_proxies(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
stale_router_ids = [_uuid(), _uuid()]