]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow unit tests to be run independently
authorHenry Gessau <gessau@cisco.com>
Tue, 31 Mar 2015 14:54:51 +0000 (10:54 -0400)
committerHenry Gessau <gessau@cisco.com>
Wed, 13 May 2015 15:16:59 +0000 (15:16 +0000)
Add various initializations and imports so that unit tests can be run
independently.

This change fixes the following test cases which could not be run
independently, that is running any individual unit test case by going
in to the py27 venv and running
"unit2 neutron.tests.unit.module.Class.test_case":

 neutron.tests.unit.plugins.ml2.drivers.arista.test_mechanism_arista.*
 neutron.tests.unit.plugins.ml2.drivers.cisco.apic.*
 neutron.tests.unit.plugins.ml2.test_rpc.RpcCallbacksTestCase.*
 neutron.tests.unit.services.l3_router.test_l3_apic.*
 neutron.tests.unit.agent.dhcp.test_agent.TestDhcpAgentEventHandler.*

(Note that these issues are not seen when running tox because the
initializations occur when all test modules are imported for test
discovery.)

Closes-bug: 1438463
Closes-bug: 1454640

Change-Id: I681caa66b51ce9a7bfbee5dfc43d534ba0d51947

neutron/tests/unit/agent/dhcp/test_agent.py
neutron/tests/unit/plugins/ml2/drivers/arista/test_mechanism_arista.py
neutron/tests/unit/plugins/ml2/drivers/cisco/apic/base.py
neutron/tests/unit/plugins/ml2/test_rpc.py

index afc7cf7d258628d5348e0381833560d23be22482..2dcda88f662071cd1274740e17275a7edf9d5615 100644 (file)
@@ -540,8 +540,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
         config.register_interface_driver_opts_helper(cfg.CONF)
         cfg.CONF.set_override('interface_driver',
                               'neutron.agent.linux.interface.NullDriver')
-        cfg.CONF.register_opts(dhcp_config.DHCP_AGENT_OPTS)
-        cfg.CONF.register_opts(dhcp_config.DHCP_OPTS)
+        entry.register_options()  # register all dhcp cfg options
 
         self.plugin_p = mock.patch(DHCP_PLUGIN)
         plugin_cls = self.plugin_p.start()
index 6c6ecd64028df4fa5a3fcdec39738f6742162243..d743d6aa4833dc00bf34f9cb49560cca79083b31 100644 (file)
@@ -18,12 +18,13 @@ import sys
 import mock
 
 from neutron.extensions import portbindings
+from neutron.tests.unit import testlib_api
+
 with mock.patch.dict(sys.modules,
                      {'networking_arista': mock.Mock(),
                       'networking_arista.ml2': mock.Mock(),
                       'networking_arista.common': mock.Mock()}):
     from neutron.plugins.ml2.drivers.arista import mechanism_arista
-from neutron.tests.unit import testlib_api
 
 
 class AristaDriverTestCase(testlib_api.SqlTestCase):
index b4bc05e413fc0c58d97db93b16518bfdf86aa775..889a32e43856c543a68bb42da07d2a9276387b11 100644 (file)
@@ -90,6 +90,9 @@ SERVICE_PEER_PORT_DESC = ('topology/pod-1/paths-%s/pathep-[%s]' %
                           (APIC_EXT_SWITCH, SERVICE_PEER_PORT_LOCAL.lower()))
 
 
+cfg.CONF.import_group('ml2', 'neutron.plugins.ml2.config')
+
+
 class ControllerMixin(object):
 
     """Mock the controller for APIC driver and service unit tests."""
index 56cbdbcb97947cd7baa3f439af7f48a177fb451b..17d09328c306587cd26ab3615a5acdde996f90a1 100644 (file)
@@ -21,6 +21,7 @@ import collections
 import contextlib
 
 import mock
+from oslo_config import cfg
 from oslo_context import context as oslo_context
 from sqlalchemy.orm import exc
 
@@ -34,6 +35,9 @@ from neutron.plugins.ml2 import rpc as plugin_rpc
 from neutron.tests import base
 
 
+cfg.CONF.import_group('ml2', 'neutron.plugins.ml2.config')
+
+
 class RpcCallbacksTestCase(base.BaseTestCase):
 
     def setUp(self):