Skip to content

Commit

Permalink
Call _destroy_metadata_proxy from _destroy_router_namespaces
Browse files Browse the repository at this point in the history
Refactor _spawn/destroy_metadata_proxy so that it can be called
with only the namespace and the router_id.

Change-Id: Id1c33b22c7c3bd35c54a7c9ad419831bfed8746b
Closes-Bug: #1252856
  • Loading branch information
Carl Baldwin committed Nov 19, 2013
1 parent bc18247 commit 07d5970
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
28 changes: 16 additions & 12 deletions neutron/agent/l3_agent.py
Expand Up @@ -243,14 +243,18 @@ def _destroy_router_namespaces(self, only_router_id=None):
If only_router_id is passed, only destroy single namespace, to allow
for multiple l3 agents on the same host, without stepping on each
other's toes on init. This only makes sense if router_id is set.
other's toes on init. This only makes sense if only_router_id is set.
"""
root_ip = ip_lib.IPWrapper(self.root_helper)
for ns in root_ip.get_namespaces(self.root_helper):
if ns.startswith(NS_PREFIX):
if only_router_id and not ns.endswith(only_router_id):
router_id = ns[len(NS_PREFIX):]
if only_router_id and not only_router_id == router_id:
continue

if self.conf.enable_metadata_proxy:
self._destroy_metadata_proxy(router_id, ns)

try:
self._destroy_router_namespace(ns)
except Exception:
Expand Down Expand Up @@ -304,7 +308,7 @@ def _router_added(self, router_id, router):
ri.iptables_manager.apply()
super(L3NATAgent, self).process_router_add(ri)
if self.conf.enable_metadata_proxy:
self._spawn_metadata_proxy(ri)
self._spawn_metadata_proxy(ri.router_id, ri.ns_name())

def _router_removed(self, router_id):
ri = self.router_info.get(router_id)
Expand All @@ -322,37 +326,37 @@ def _router_removed(self, router_id):
ri.iptables_manager.ipv4['nat'].remove_rule(c, r)
ri.iptables_manager.apply()
if self.conf.enable_metadata_proxy:
self._destroy_metadata_proxy(ri)
self._destroy_metadata_proxy(ri.router_id, ri.ns_name())
del self.router_info[router_id]
self._destroy_router_namespace(ri.ns_name())

def _spawn_metadata_proxy(self, router_info):
def _spawn_metadata_proxy(self, router_id, ns_name):
def callback(pid_file):
metadata_proxy_socket = cfg.CONF.metadata_proxy_socket
proxy_cmd = ['neutron-ns-metadata-proxy',
'--pid_file=%s' % pid_file,
'--metadata_proxy_socket=%s' % metadata_proxy_socket,
'--router_id=%s' % router_info.router_id,
'--router_id=%s' % router_id,
'--state_path=%s' % self.conf.state_path,
'--metadata_port=%s' % self.conf.metadata_port]
proxy_cmd.extend(config.get_log_args(
cfg.CONF, 'neutron-ns-metadata-proxy-%s.log' %
router_info.router_id))
router_id))
return proxy_cmd

pm = external_process.ProcessManager(
self.conf,
router_info.router_id,
router_id,
self.root_helper,
router_info.ns_name())
ns_name)
pm.enable(callback)

def _destroy_metadata_proxy(self, router_info):
def _destroy_metadata_proxy(self, router_id, ns_name):
pm = external_process.ProcessManager(
self.conf,
router_info.router_id,
router_id,
self.root_helper,
router_info.ns_name())
ns_name)
pm.disable()

def _set_subnet_info(self, port):
Expand Down
4 changes: 2 additions & 2 deletions neutron/services/firewall/agents/varmour/varmour_router.py
Expand Up @@ -88,10 +88,10 @@ def _router_removed(self, router_id):

del self.router_info[router_id]

def _spawn_metadata_proxy(self, router_info):
def _spawn_metadata_proxy(self, router_id, ns_name):
return

def _destroy_metadata_proxy(self, router_info):
def _destroy_metadata_proxy(self, router_id, ns_name):
return

def _set_subnet_info(self, port):
Expand Down
16 changes: 5 additions & 11 deletions neutron/tests/unit/test_l3_agent.py
Expand Up @@ -696,12 +696,12 @@ def _configure_metadata_proxy(self, enableflag=True):
agent, '_spawn_metadata_proxy') as spawn_proxy:
agent._router_added(router_id, router)
if enableflag:
spawn_proxy.assert_called_with(mock.ANY)
spawn_proxy.assert_called_with(mock.ANY, mock.ANY)
else:
self.assertFalse(spawn_proxy.call_count)
agent._router_removed(router_id)
if enableflag:
destroy_proxy.assert_called_with(mock.ANY)
destroy_proxy.assert_called_with(mock.ANY, mock.ANY)
else:
self.assertFalse(destroy_proxy.call_count)

Expand Down Expand Up @@ -811,19 +811,13 @@ def test_spawn_metadata_proxy(self):
cfg.CONF.set_override('log_file', 'test.log')
cfg.CONF.set_override('debug', True)

router_info = l3_agent.RouterInfo(
router_id, cfg.CONF.root_helper, cfg.CONF.use_namespaces, None
)

self.external_process_p.stop()
ns = 'qrouter-' + router_id
try:
with mock.patch(ip_class_path) as ip_mock:
self.agent._spawn_metadata_proxy(router_info)
self.agent._spawn_metadata_proxy(router_id, ns)
ip_mock.assert_has_calls([
mock.call(
'sudo',
'qrouter-' + router_id
),
mock.call('sudo', ns),
mock.call().netns.execute([
'neutron-ns-metadata-proxy',
mock.ANY,
Expand Down

0 comments on commit 07d5970

Please sign in to comment.