Skip to content

Commit

Permalink
Pass metadata port to metadata proxy
Browse files Browse the repository at this point in the history
Make the l3 agent pass the port used by the metadata service to the router namespace proxy when
creating it and add also new tests for this.

Fixes LP# 1160955
Change-Id: Iec8a5238345b26e70b0aa1dc96a896e26af34722
  • Loading branch information
mouadino authored and Gary Kotton committed Apr 5, 2013
1 parent cf4d1d8 commit c82d72f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
5 changes: 2 additions & 3 deletions quantum/agent/l3_agent.py
Expand Up @@ -19,8 +19,6 @@
#
"""

import sys

import eventlet
from eventlet import semaphore
import netaddr
Expand Down Expand Up @@ -257,7 +255,8 @@ def callback(pid_file):
proxy_cmd = ['quantum-ns-metadata-proxy',
'--pid_file=%s' % pid_file,
'--router_id=%s' % router_info.router_id,
'--state_path=%s' % self.conf.state_path]
'--state_path=%s' % self.conf.state_path,
'--metadata_port=%s' % self.conf.metadata_port]
proxy_cmd.extend(config.get_log_args(
cfg.CONF, 'quantum-ns-metadata-proxy%s.log' %
router_info.router_id))
Expand Down
84 changes: 84 additions & 0 deletions quantum/tests/unit/test_l3_agent.py
Expand Up @@ -428,3 +428,87 @@ def __init__(self, name):
agent._destroy_router_namespaces(self.conf.router_id)

self.assertEqual(agent._destroy_router_namespace.call_count, 1)


class TestL3AgentEventHandler(base.BaseTestCase):

def setUp(self):
super(TestL3AgentEventHandler, self).setUp()
cfg.CONF.register_opts(l3_agent.L3NATAgent.OPTS)
cfg.CONF.set_override(
'interface_driver', 'quantum.agent.linux.interface.NullDriver'
)
cfg.CONF.set_override('use_namespaces', True)
agent_config.register_root_helper(cfg.CONF)

self.device_exists_p = mock.patch(
'quantum.agent.linux.ip_lib.device_exists')
self.device_exists = self.device_exists_p.start()

self.utils_exec_p = mock.patch(
'quantum.agent.linux.utils.execute')
self.utils_exec = self.utils_exec_p.start()

self.drv_cls_p = mock.patch('quantum.agent.linux.interface.NullDriver')
driver_cls = self.drv_cls_p.start()
self.mock_driver = mock.MagicMock()
self.mock_driver.DEV_NAME_LEN = (
interface.LinuxInterfaceDriver.DEV_NAME_LEN)
driver_cls.return_value = self.mock_driver

self.l3_plugin_p = mock.patch(
'quantum.agent.l3_agent.L3PluginApi')
l3_plugin_cls = self.l3_plugin_p.start()
self.plugin_api = mock.Mock()
l3_plugin_cls.return_value = self.plugin_api

self.external_process_p = mock.patch(
'quantum.agent.linux.external_process.ProcessManager'
)
self.external_process = self.external_process_p.start()

self.agent = l3_agent.L3NATAgent(HOSTNAME)

def tearDown(self):
self.device_exists_p.stop()
self.utils_exec_p.stop()
self.drv_cls_p.stop()
self.l3_plugin_p.stop()
self.external_process_p.stop()
super(TestL3AgentEventHandler, self).tearDown()

def test_spawn_metadata_proxy(self):
router_id = _uuid()
metadata_port = 8080
ip_class_path = 'quantum.agent.linux.ip_lib.IPWrapper'

cfg.CONF.set_override('metadata_port', metadata_port)
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()
try:
with mock.patch(ip_class_path) as ip_mock:
self.agent._spawn_metadata_proxy(router_info)
ip_mock.assert_has_calls([
mock.call(
'sudo',
'qrouter-' + router_id
),
mock.call().netns.execute([
'quantum-ns-metadata-proxy',
mock.ANY,
'--router_id=%s' % router_id,
mock.ANY,
'--metadata_port=%s' % metadata_port,
'--debug',
'--log-file=quantum-ns-metadata-proxy%s.log' %
router_id
])
])
finally:
self.external_process_p.start()

0 comments on commit c82d72f

Please sign in to comment.