]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Removes unnecessary Embrane module-level mocks
authorKevin Benton <blak111@gmail.com>
Fri, 30 May 2014 03:55:21 +0000 (20:55 -0700)
committerKevin Benton <blak111@gmail.com>
Tue, 3 Jun 2014 09:17:43 +0000 (09:17 +0000)
The embrane unit tests install a magicmock into
the system modules at the module level which
persists across all unit tests and isn't required.
This patch removes the unnecessary and limits the
life of the module mocks where they are necessary.

Partial-Bug: #1316401
Change-Id: Iaa38ee0c6821d46a6d78eefef39006df2c1c47e5

neutron/tests/unit/embrane/test_embrane_defaults.py
neutron/tests/unit/embrane/test_embrane_l3_plugin.py
neutron/tests/unit/embrane/test_embrane_neutron_plugin.py
neutron/tests/unit/services/loadbalancer/drivers/embrane/test_embrane_defaults.py
neutron/tests/unit/services/loadbalancer/drivers/embrane/test_plugin_driver.py

index 1bb6a565ec6baeafc3207a4cb7839416c916e5c4..ea84d63abfd32ec1099e5924dbe4048847b5c469 100644 (file)
 #
 # @author:  Ivar Lazzaro, Embrane, Inc.
 
-import sys
-
-import mock
 from oslo.config import cfg
 
 from neutron.plugins.embrane.common import config  # noqa
 from neutron.tests import base
 
-# Need to mock heleosapi.
-sys.modules["heleosapi"] = mock.Mock()
-
 
 class ConfigurationTest(base.BaseTestCase):
 
index 5bdc9f8808c046728945d624cbca9117709c8119..548a1d432483e09c8a539d87aa27cf705f1410e3 100644 (file)
@@ -17,9 +17,6 @@
 #
 # @author:  Ivar Lazzaro, Embrane, Inc.
 
-import sys
-
-import mock
 from oslo.config import cfg
 
 from neutron.db import api as db
@@ -29,7 +26,6 @@ from neutron.tests.unit import test_l3_plugin as router_test
 
 PLUGIN_NAME = ('neutron.plugins.embrane.plugins.embrane_fake_plugin.'
                'EmbraneFakePlugin')
-sys.modules["heleosapi"] = mock.Mock()
 
 
 class TestEmbraneL3NatDBTestCase(router_test.L3NatDBIntTestCase):
index bc96b2681db2c7108aaa1954f20dd4632d8e3f6e..74b64e4151239757392e332bdd27d309245869a9 100644 (file)
@@ -16,7 +16,6 @@
 #    under the License.
 #
 # @author:  Ivar Lazzaro, Embrane, Inc.
-
 import sys
 
 import mock
@@ -28,7 +27,6 @@ from neutron.tests.unit import test_db_plugin as test_plugin
 
 PLUGIN_NAME = ('neutron.plugins.embrane.plugins.embrane_fake_plugin.'
                'EmbraneFakePlugin')
-sys.modules["heleosapi"] = mock.Mock()
 
 
 class EmbranePluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
@@ -36,7 +34,11 @@ class EmbranePluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
 
     def setUp(self):
         cfg.CONF.set_override('admin_password', "admin123", 'heleos')
+        p = mock.patch.dict(sys.modules, {'heleosapi': mock.Mock()})
+        p.start()
         self.addCleanup(db.clear_db)
+        # dict patches must be explicitly stopped
+        self.addCleanup(p.stop)
         super(EmbranePluginV2TestCase, self).setUp(self._plugin_name)
 
 
index d3588f8b7e882a74ffab9e0249b2a7cdd3604aba..cffb2ae3731eb5f4002f6cffcee805289b29ac7b 100644 (file)
 #
 # @author:  Ivar Lazzaro, Embrane, Inc.
 
-import sys
-
-import mock
 from oslo.config import cfg
 
 from neutron.services.loadbalancer.drivers.embrane import config  # noqa
 from neutron.tests import base
 
-sys.modules["heleosapi"] = mock.Mock()
-
 
 class ConfigurationTest(base.BaseTestCase):
 
index c98ef5f13259d297d784feab22793fa681425ba4..56a02a2082dc4461e10d460bb6b5722d44075060 100644 (file)
 import sys
 
 import mock
-sys.modules["heleosapi"] = mock.Mock()
 from oslo.config import cfg
 
 from neutron import context
 from neutron.openstack.common.db import exception as n_exc
+from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
+
+HELEOSAPIMOCK = mock.Mock()
+sys.modules["heleosapi"] = HELEOSAPIMOCK
 from neutron.services.loadbalancer.drivers.embrane import config  # noqa
 from neutron.services.loadbalancer.drivers.embrane import constants as h_con
 from neutron.services.loadbalancer.drivers.embrane import db as h_db
-from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
-
+# Stop the mock from persisting indefinitely in the global modules space
+del sys.modules["heleosapi"]
 
 EMBRANE_PROVIDER = ('LOADBALANCER:lbaas:neutron.services.'
                     'loadbalancer.drivers.embrane.driver.'
@@ -42,10 +45,12 @@ class TestLoadBalancerPluginBase(
     def setUp(self):
         cfg.CONF.set_override('admin_password', "admin123", 'heleoslb')
         cfg.CONF.set_override('sync_interval', 0, 'heleoslb')
-
+        mock.patch.dict(sys.modules, {'heleosapi': HELEOSAPIMOCK}).start()
         super(TestLoadBalancerPluginBase, self).setUp(
             lbaas_provider=EMBRANE_PROVIDER)
         self.driver = self.plugin.drivers['lbaas']
+        # prevent module mock from saving calls between tests
+        self.addCleanup(HELEOSAPIMOCK.reset_mock)
 
 
 class TestLoadBalancerPlugin(test_db_loadbalancer.TestLoadBalancer,