From 636d4a5d204e1d2690594881631a2fa8d84d0b6c Mon Sep 17 00:00:00 2001 From: Quan Tian Date: Thu, 16 Feb 2017 20:28:45 +0800 Subject: [PATCH] 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 1346b4a65701aaec667c8a8a2790ffa345e0efad) --- neutron/agent/l3/agent.py | 2 +- neutron/tests/unit/agent/l3/test_agent.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 93637b855de..33d7148c237 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -578,7 +578,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'): diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 47177e59be5..e0412945814 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -37,6 +37,7 @@ from neutron.agent.l3 import dvr_snat_ns from neutron.agent.l3 import ha 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()]