Removes unnecessary Embrane module-level mocks

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
This commit is contained in:
Kevin Benton 2014-05-29 20:55:21 -07:00
parent 4e84a2da94
commit a853147220
5 changed files with 13 additions and 21 deletions

View File

@ -17,17 +17,11 @@
#
# @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):

View 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):

View 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)

View File

@ -17,16 +17,11 @@
#
# @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):

View File

@ -20,16 +20,19 @@
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,