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
#
# @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):
#
# @author: Ivar Lazzaro, Embrane, Inc.
-import sys
-
-import mock
from oslo.config import cfg
from neutron.db import api as db
PLUGIN_NAME = ('neutron.plugins.embrane.plugins.embrane_fake_plugin.'
'EmbraneFakePlugin')
-sys.modules["heleosapi"] = mock.Mock()
class TestEmbraneL3NatDBTestCase(router_test.L3NatDBIntTestCase):
# under the License.
#
# @author: Ivar Lazzaro, Embrane, Inc.
-
import sys
import mock
PLUGIN_NAME = ('neutron.plugins.embrane.plugins.embrane_fake_plugin.'
'EmbraneFakePlugin')
-sys.modules["heleosapi"] = mock.Mock()
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)
#
# @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):
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.'
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,