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
This commit is contained in:
Miguel Angel Ajo 2014-03-18 13:33:19 +01:00 committed by Gerrit Code Review
parent f1de09d60b
commit 907bf41afb
2 changed files with 27 additions and 17 deletions

View File

@ -21,8 +21,10 @@ import eventlet
from oslo.config import cfg from oslo.config import cfg
from neutron.agent.common import config as agent_config from neutron.agent.common import config as agent_config
from neutron.agent import dhcp_agent
from neutron.agent import l3_agent from neutron.agent import l3_agent
from neutron.agent.linux import dhcp from neutron.agent.linux import dhcp
from neutron.agent.linux import interface
from neutron.agent.linux import ip_lib from neutron.agent.linux import ip_lib
from neutron.agent.linux import ovs_lib from neutron.agent.linux import ovs_lib
from neutron.api.v2 import attributes 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) attributes.UUID_PATTERN)
class FakeNetwork(object): class FakeDhcpPlugin(object):
def __init__(self, id): """Fake RPC plugin to bypass any RPC calls."""
self.id = id def __getattribute__(self, name):
def fake_method(*args):
pass
return fake_method
def setup_conf(): def setup_conf():
@ -54,18 +59,14 @@ def setup_conf():
help=_('Delete the namespace by removing all devices.')), 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 = cfg.CONF
conf.register_cli_opts(cli_opts) conf.register_cli_opts(cli_opts)
conf.register_opts(opts)
agent_config.register_interface_driver_opts_helper(conf) agent_config.register_interface_driver_opts_helper(conf)
agent_config.register_use_namespaces_opts_helper(conf)
agent_config.register_root_helper(conf) agent_config.register_root_helper(conf)
conf.register_opts(dhcp.OPTS) conf.register_opts(dhcp.OPTS)
conf.register_opts(dhcp_agent.DhcpAgent.OPTS)
conf.register_opts(interface.OPTS)
return conf return conf
@ -76,9 +77,10 @@ def kill_dhcp(conf, namespace):
dhcp_driver = importutils.import_object( dhcp_driver = importutils.import_object(
conf.dhcp_driver, conf.dhcp_driver,
conf, conf=conf,
FakeNetwork(network_id), network=dhcp.NetModel(conf.use_namespaces, {'id': network_id}),
root_helper) root_helper=root_helper,
plugin=FakeDhcpPlugin())
if dhcp_driver.active: if dhcp_driver.active:
dhcp_driver.disable() dhcp_driver.disable()

View File

@ -17,12 +17,18 @@
import mock import mock
from neutron.agent.linux import interface
from neutron.agent import netns_cleanup_util as util from neutron.agent import netns_cleanup_util as util
from neutron.tests import base from neutron.tests import base
class TestNetnsCleanup(base.BaseTestCase): 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): def test_kill_dhcp(self, dhcp_active=True):
conf = mock.Mock() conf = mock.Mock()
conf.AGENT.root_helper = 'sudo', conf.AGENT.root_helper = 'sudo',
@ -37,9 +43,10 @@ class TestNetnsCleanup(base.BaseTestCase):
util.kill_dhcp(conf, 'ns') util.kill_dhcp(conf, 'ns')
import_object.called_once_with('driver', conf, mock.ANY, expected_params = {'conf': conf, 'network': mock.ANY,
conf.AGENT.root_helper, 'root_helper': conf.AGENT.root_helper,
mock.ANY) 'plugin': mock.ANY}
import_object.assert_called_once_with('driver', **expected_params)
if dhcp_active: if dhcp_active:
driver.assert_has_calls([mock.call.disable()]) driver.assert_has_calls([mock.call.disable()])
@ -104,7 +111,8 @@ class TestNetnsCleanup(base.BaseTestCase):
mock_get_bridge_for_iface.assert_called_once_with( mock_get_bridge_for_iface.assert_called_once_with(
conf.AGENT.root_helper, 'tap1') 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( ovs_bridge.assert_has_calls(
[mock.call.delete_port(device.name)]) [mock.call.delete_port(device.name)])