]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fixes broken neutron-netns-cleanup
authorMiguel Angel Ajo <mangelajo@redhat.com>
Tue, 18 Mar 2014 12:33:19 +0000 (13:33 +0100)
committerMark McClain <mmcclain@yahoo-inc.com>
Fri, 4 Apr 2014 22:32:55 +0000 (18:32 -0400)
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)

neutron/agent/netns_cleanup_util.py
neutron/tests/unit/test_agent_netns_cleanup.py

index 2551299cda8a4aff7e499b1d8e64a10c5206e9eb..f43efd38493f6e696efda5f60bbf9b090cb0e782 100644 (file)
@@ -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()
index dddd4837334888476b037378232ce4be759dfb66..71b1cd6daa6203dce37a7150875fe7a30749fd21 100644 (file)
 
 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)])