summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-17 13:58:56 +0000
committerGerrit Code Review <review@openstack.org>2017-06-17 13:58:56 +0000
commit90db5afe2baffd5489d0a8d5d671905937a26aa1 (patch)
treee24e6c1f98511f279054362826e45edb74239072
parent26537ac05f46d691ce4bcd0e130bf203a54c1afd (diff)
parent8815e9e86755d2b253642949faec5de39e92f991 (diff)
Merge "Don't add duplicate metadata rules after router update" into stable/ocata
-rw-r--r--neutron/agent/metadata/driver.py10
-rw-r--r--neutron/tests/unit/agent/metadata/test_driver.py19
2 files changed, 27 insertions, 2 deletions
diff --git a/neutron/agent/metadata/driver.py b/neutron/agent/metadata/driver.py
index 92e4ba2..7133725 100644
--- a/neutron/agent/metadata/driver.py
+++ b/neutron/agent/metadata/driver.py
@@ -170,8 +170,14 @@ def after_router_added(resource, event, l3_agent, **kwargs):
170def after_router_updated(resource, event, l3_agent, **kwargs): 170def after_router_updated(resource, event, l3_agent, **kwargs):
171 router = kwargs['router'] 171 router = kwargs['router']
172 proxy = l3_agent.metadata_driver 172 proxy = l3_agent.metadata_driver
173 if not proxy.monitors.get(router.router_id): 173 if (not proxy.monitors.get(router.router_id) and
174 after_router_added(resource, event, l3_agent, **kwargs) 174 not isinstance(router, ha_router.HaRouter)):
175 proxy.spawn_monitored_metadata_proxy(
176 l3_agent.process_monitor,
177 router.ns_name,
178 proxy.metadata_port,
179 l3_agent.conf,
180 router_id=router.router_id)
175 181
176 182
177def before_router_removed(resource, event, l3_agent, **kwargs): 183def before_router_removed(resource, event, l3_agent, **kwargs):
diff --git a/neutron/tests/unit/agent/metadata/test_driver.py b/neutron/tests/unit/agent/metadata/test_driver.py
index 35b951e..96993aa 100644
--- a/neutron/tests/unit/agent/metadata/test_driver.py
+++ b/neutron/tests/unit/agent/metadata/test_driver.py
@@ -20,6 +20,7 @@ from oslo_utils import uuidutils
20from neutron.agent.common import config as agent_config 20from neutron.agent.common import config as agent_config
21from neutron.agent.l3 import agent as l3_agent 21from neutron.agent.l3 import agent as l3_agent
22from neutron.agent.l3 import router_info 22from neutron.agent.l3 import router_info
23from neutron.agent.linux import iptables_manager
23from neutron.agent.metadata import driver as metadata_driver 24from neutron.agent.metadata import driver as metadata_driver
24from neutron.common import constants 25from neutron.common import constants
25from neutron.conf.agent.l3 import config as l3_config 26from neutron.conf.agent.l3 import config as l3_config
@@ -93,6 +94,24 @@ class TestMetadataDriverProcess(base.BaseTestCase):
93 f.assert_called_once_with( 94 f.assert_called_once_with(
94 'router', 'after_update', agent, router=ri) 95 'router', 'after_update', agent, router=ri)
95 96
97 def test_after_router_updated_should_not_call_add_metadata_rules(self):
98 with mock.patch.object(iptables_manager.IptablesTable,
99 'add_rule') as f,\
100 mock.patch.object(iptables_manager.IptablesManager,
101 'apply'),\
102 mock.patch.object(metadata_driver.MetadataDriver,
103 'spawn_monitored_metadata_proxy'),\
104 mock.patch.object(router_info.RouterInfo, 'process'):
105 agent = l3_agent.L3NATAgent('localhost')
106 router_id = _uuid()
107 router = {'id': router_id}
108 ri = router_info.RouterInfo(mock.Mock(), router_id, router,
109 agent.conf, mock.ANY)
110 agent.router_info[router_id] = ri
111 f.reset_mock()
112 agent._process_updated_router(router)
113 f.assert_not_called()
114
96 def _test_spawn_metadata_proxy(self, expected_user, expected_group, 115 def _test_spawn_metadata_proxy(self, expected_user, expected_group,
97 user='', group='', watch_log=True): 116 user='', group='', watch_log=True):
98 router_id = _uuid() 117 router_id = _uuid()