Skip to content

Commit c82d72f

Browse files
mouadinoGary Kotton
authored andcommitted
Pass metadata port to metadata proxy
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
1 parent cf4d1d8 commit c82d72f

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

quantum/agent/l3_agent.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#
2020
"""
2121

22-
import sys
23-
2422
import eventlet
2523
from eventlet import semaphore
2624
import netaddr
@@ -257,7 +255,8 @@ def callback(pid_file):
257255
proxy_cmd = ['quantum-ns-metadata-proxy',
258256
'--pid_file=%s' % pid_file,
259257
'--router_id=%s' % router_info.router_id,
260-
'--state_path=%s' % self.conf.state_path]
258+
'--state_path=%s' % self.conf.state_path,
259+
'--metadata_port=%s' % self.conf.metadata_port]
261260
proxy_cmd.extend(config.get_log_args(
262261
cfg.CONF, 'quantum-ns-metadata-proxy%s.log' %
263262
router_info.router_id))

quantum/tests/unit/test_l3_agent.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,87 @@ def __init__(self, name):
428428
agent._destroy_router_namespaces(self.conf.router_id)
429429

430430
self.assertEqual(agent._destroy_router_namespace.call_count, 1)
431+
432+
433+
class TestL3AgentEventHandler(base.BaseTestCase):
434+
435+
def setUp(self):
436+
super(TestL3AgentEventHandler, self).setUp()
437+
cfg.CONF.register_opts(l3_agent.L3NATAgent.OPTS)
438+
cfg.CONF.set_override(
439+
'interface_driver', 'quantum.agent.linux.interface.NullDriver'
440+
)
441+
cfg.CONF.set_override('use_namespaces', True)
442+
agent_config.register_root_helper(cfg.CONF)
443+
444+
self.device_exists_p = mock.patch(
445+
'quantum.agent.linux.ip_lib.device_exists')
446+
self.device_exists = self.device_exists_p.start()
447+
448+
self.utils_exec_p = mock.patch(
449+
'quantum.agent.linux.utils.execute')
450+
self.utils_exec = self.utils_exec_p.start()
451+
452+
self.drv_cls_p = mock.patch('quantum.agent.linux.interface.NullDriver')
453+
driver_cls = self.drv_cls_p.start()
454+
self.mock_driver = mock.MagicMock()
455+
self.mock_driver.DEV_NAME_LEN = (
456+
interface.LinuxInterfaceDriver.DEV_NAME_LEN)
457+
driver_cls.return_value = self.mock_driver
458+
459+
self.l3_plugin_p = mock.patch(
460+
'quantum.agent.l3_agent.L3PluginApi')
461+
l3_plugin_cls = self.l3_plugin_p.start()
462+
self.plugin_api = mock.Mock()
463+
l3_plugin_cls.return_value = self.plugin_api
464+
465+
self.external_process_p = mock.patch(
466+
'quantum.agent.linux.external_process.ProcessManager'
467+
)
468+
self.external_process = self.external_process_p.start()
469+
470+
self.agent = l3_agent.L3NATAgent(HOSTNAME)
471+
472+
def tearDown(self):
473+
self.device_exists_p.stop()
474+
self.utils_exec_p.stop()
475+
self.drv_cls_p.stop()
476+
self.l3_plugin_p.stop()
477+
self.external_process_p.stop()
478+
super(TestL3AgentEventHandler, self).tearDown()
479+
480+
def test_spawn_metadata_proxy(self):
481+
router_id = _uuid()
482+
metadata_port = 8080
483+
ip_class_path = 'quantum.agent.linux.ip_lib.IPWrapper'
484+
485+
cfg.CONF.set_override('metadata_port', metadata_port)
486+
cfg.CONF.set_override('log_file', 'test.log')
487+
cfg.CONF.set_override('debug', True)
488+
489+
router_info = l3_agent.RouterInfo(
490+
router_id, cfg.CONF.root_helper, cfg.CONF.use_namespaces, None
491+
)
492+
493+
self.external_process_p.stop()
494+
try:
495+
with mock.patch(ip_class_path) as ip_mock:
496+
self.agent._spawn_metadata_proxy(router_info)
497+
ip_mock.assert_has_calls([
498+
mock.call(
499+
'sudo',
500+
'qrouter-' + router_id
501+
),
502+
mock.call().netns.execute([
503+
'quantum-ns-metadata-proxy',
504+
mock.ANY,
505+
'--router_id=%s' % router_id,
506+
mock.ANY,
507+
'--metadata_port=%s' % metadata_port,
508+
'--debug',
509+
'--log-file=quantum-ns-metadata-proxy%s.log' %
510+
router_id
511+
])
512+
])
513+
finally:
514+
self.external_process_p.start()

0 commit comments

Comments
 (0)