From: Miguel Angel Ajo Date: Tue, 18 Mar 2014 12:33:19 +0000 (+0100) Subject: fixes broken neutron-netns-cleanup X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5417220fc50fb31218ed1ed2aba6b926591c5f81;p=openstack-build%2Fneutron-build.git fixes broken neutron-netns-cleanup Some configuration parameters used in neutron.agent.linux.utils were missing. The namespace attribute in the FakeNetwork object was missing, and used in neutron.agent.linux.dhcp. Also, the plugin object was missing for release_dhcp_port operation. We provide a fake plugin object to accept current and any future plugin calls as this is meant to be an standalone tool that should work without any RPC connectivity. FakeNetwork was switched for neutron.agent.linux.dhcp.NetModel to follow any future changes in NetModel. Two wrong called_once_with_args calls without assert were fixed. Change-Id: Ia51ea9bd4c8eea6b250858964ad5286c933702e0 Closes-Bug: #1291915 Partial-Bug: #1297875 (cherry picked from commit 907bf41afbdb9f565c45a535f637c8928d0be52a) --- diff --git a/neutron/agent/netns_cleanup_util.py b/neutron/agent/netns_cleanup_util.py index 2551299cd..f43efd384 100644 --- a/neutron/agent/netns_cleanup_util.py +++ b/neutron/agent/netns_cleanup_util.py @@ -21,8 +21,10 @@ import eventlet from oslo.config import cfg from neutron.agent.common import config as agent_config +from neutron.agent import dhcp_agent from neutron.agent import l3_agent from neutron.agent.linux import dhcp +from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.agent.linux import ovs_lib from neutron.api.v2 import attributes @@ -36,9 +38,12 @@ NS_MANGLING_PATTERN = ('(%s|%s)' % (dhcp.NS_PREFIX, l3_agent.NS_PREFIX) + attributes.UUID_PATTERN) -class FakeNetwork(object): - def __init__(self, id): - self.id = id +class FakeDhcpPlugin(object): + """Fake RPC plugin to bypass any RPC calls.""" + def __getattribute__(self, name): + def fake_method(*args): + pass + return fake_method def setup_conf(): @@ -54,18 +59,14 @@ def setup_conf(): help=_('Delete the namespace by removing all devices.')), ] - opts = [ - cfg.StrOpt('dhcp_driver', - default='neutron.agent.linux.dhcp.Dnsmasq', - help=_("The driver used to manage the DHCP server.")), - ] - conf = cfg.CONF conf.register_cli_opts(cli_opts) - conf.register_opts(opts) agent_config.register_interface_driver_opts_helper(conf) + agent_config.register_use_namespaces_opts_helper(conf) agent_config.register_root_helper(conf) conf.register_opts(dhcp.OPTS) + conf.register_opts(dhcp_agent.DhcpAgent.OPTS) + conf.register_opts(interface.OPTS) return conf @@ -76,9 +77,10 @@ def kill_dhcp(conf, namespace): dhcp_driver = importutils.import_object( conf.dhcp_driver, - conf, - FakeNetwork(network_id), - root_helper) + conf=conf, + network=dhcp.NetModel(conf.use_namespaces, {'id': network_id}), + root_helper=root_helper, + plugin=FakeDhcpPlugin()) if dhcp_driver.active: dhcp_driver.disable() diff --git a/neutron/tests/unit/test_agent_netns_cleanup.py b/neutron/tests/unit/test_agent_netns_cleanup.py index dddd48373..71b1cd6da 100644 --- a/neutron/tests/unit/test_agent_netns_cleanup.py +++ b/neutron/tests/unit/test_agent_netns_cleanup.py @@ -17,12 +17,18 @@ import mock +from neutron.agent.linux import interface from neutron.agent import netns_cleanup_util as util from neutron.tests import base class TestNetnsCleanup(base.BaseTestCase): + def test_setup_conf(self): + expected_opts = interface.OPTS + conf = util.setup_conf() + self.assertTrue(all([opt.name in conf for opt in expected_opts])) + def test_kill_dhcp(self, dhcp_active=True): conf = mock.Mock() conf.AGENT.root_helper = 'sudo', @@ -37,9 +43,10 @@ class TestNetnsCleanup(base.BaseTestCase): util.kill_dhcp(conf, 'ns') - import_object.called_once_with('driver', conf, mock.ANY, - conf.AGENT.root_helper, - mock.ANY) + expected_params = {'conf': conf, 'network': mock.ANY, + 'root_helper': conf.AGENT.root_helper, + 'plugin': mock.ANY} + import_object.assert_called_once_with('driver', **expected_params) if dhcp_active: driver.assert_has_calls([mock.call.disable()]) @@ -104,7 +111,8 @@ class TestNetnsCleanup(base.BaseTestCase): mock_get_bridge_for_iface.assert_called_once_with( conf.AGENT.root_helper, 'tap1') - ovs_br_cls.called_once_with('br-int', conf.AGENT.root_helper) + ovs_br_cls.assert_called_once_with('br-int', + conf.AGENT.root_helper) ovs_bridge.assert_has_calls( [mock.call.delete_port(device.name)])