diff --git a/etc/l3_agent.ini b/etc/l3_agent.ini index 133576c3f..962c3afbe 100644 --- a/etc/l3_agent.ini +++ b/etc/l3_agent.ini @@ -51,3 +51,7 @@ interface_driver = quantum.agent.linux.interface.OVSInterfaceDriver # seconds to start to sync routers' data after # starting agent # periodic_fuzzy_delay = 5 + +# enable_metadata_proxy, which is true by default, can be set to False +# if the Nova metadata server is not available +# enable_metadata_proxy = True \ No newline at end of file diff --git a/quantum/agent/l3_agent.py b/quantum/agent/l3_agent.py index 368cfb5c6..55bfe2908 100644 --- a/quantum/agent/l3_agent.py +++ b/quantum/agent/l3_agent.py @@ -139,6 +139,8 @@ class L3NATAgent(manager.Manager): cfg.StrOpt('gateway_external_network_id', default='', help=_("UUID of external network for routers implemented " "by the agents.")), + cfg.BoolOpt('enable_metadata_proxy', default=True, + help=_("Allow running metadata proxy.")), ] def __init__(self, host, conf=None): @@ -232,7 +234,8 @@ class L3NATAgent(manager.Manager): for c, r in self.metadata_nat_rules(): ri.iptables_manager.ipv4['nat'].add_rule(c, r) ri.iptables_manager.apply() - self._spawn_metadata_proxy(ri) + if self.conf.enable_metadata_proxy: + self._spawn_metadata_proxy(ri) def _router_removed(self, router_id): ri = self.router_info[router_id] @@ -245,7 +248,8 @@ class L3NATAgent(manager.Manager): for c, r in self.metadata_nat_rules(): ri.iptables_manager.ipv4['nat'].remove_rule(c, r) ri.iptables_manager.apply() - self._destroy_metadata_proxy(ri) + if self.conf.enable_metadata_proxy: + self._destroy_metadata_proxy(ri) del self.router_info[router_id] self._destroy_router_namespace(ri.ns_name()) diff --git a/quantum/tests/unit/test_l3_agent.py b/quantum/tests/unit/test_l3_agent.py index 0ac24a2c0..95211f3ca 100644 --- a/quantum/tests/unit/test_l3_agent.py +++ b/quantum/tests/unit/test_l3_agent.py @@ -429,6 +429,35 @@ class TestBasicRouterOperations(base.BaseTestCase): self.assertEqual(agent._destroy_router_namespace.call_count, 1) + def _configure_metadata_proxy(self, enableflag=True): + if not enableflag: + self.conf.set_override('enable_metadata_proxy', False) + agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) + router_id = _uuid() + router = {'id': _uuid(), + 'external_gateway_info': {}, + 'routes': []} + with mock.patch.object( + agent, '_destroy_metadata_proxy') as destroy_proxy: + with mock.patch.object( + agent, '_spawn_metadata_proxy') as spawn_proxy: + agent._router_added(router_id, router) + if enableflag: + spawn_proxy.assert_called_with(mock.ANY) + else: + self.assertFalse(spawn_proxy.call_count) + agent._router_removed(router_id) + if enableflag: + destroy_proxy.assert_called_with(mock.ANY) + else: + self.assertFalse(destroy_proxy.call_count) + + def test_enable_metadata_proxy(self): + self._configure_metadata_proxy() + + def test_disable_metadata_proxy_spawn(self): + self._configure_metadata_proxy(enableflag=False) + class TestL3AgentEventHandler(base.BaseTestCase):