Improve module-level mocks in midonet tests
Remove unnecessary module-level mocks and replace them with test-specific mocks so they don't persist through the entire test suite. Partial-Bug: #1316401 Change-Id: I49039749bb700ec0a88639f4772701ba3b920352
This commit is contained in:
parent
4e84a2da94
commit
16dcfcd9ec
@ -19,8 +19,6 @@
|
|||||||
# @author: Rossella Sblendido, Midokura Japan KK
|
# @author: Rossella Sblendido, Midokura Japan KK
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import sys
|
|
||||||
sys.modules["midonetclient"] = mock.Mock()
|
|
||||||
|
|
||||||
from neutron.agent.common import config
|
from neutron.agent.common import config
|
||||||
from neutron.agent.linux import dhcp
|
from neutron.agent.linux import dhcp
|
||||||
|
@ -18,15 +18,15 @@
|
|||||||
#
|
#
|
||||||
# @author: Ryu Ishimoto, Midokura Japan KK
|
# @author: Ryu Ishimoto, Midokura Japan KK
|
||||||
# @author: Tomoe Sugihara, Midokura Japan KK
|
# @author: Tomoe Sugihara, Midokura Japan KK
|
||||||
|
import sys
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import sys
|
|
||||||
sys.modules["midonetclient"] = mock.Mock()
|
|
||||||
import testtools
|
import testtools
|
||||||
import webob.exc as w_exc
|
import webob.exc as w_exc
|
||||||
|
|
||||||
from neutron.openstack.common import uuidutils
|
from neutron.openstack.common import uuidutils
|
||||||
from neutron.plugins.midonet import midonet_lib
|
with mock.patch.dict(sys.modules, {'midonetclient': mock.Mock()}):
|
||||||
|
from neutron.plugins.midonet import midonet_lib
|
||||||
import neutron.tests.unit.midonet.mock_lib as mock_lib
|
import neutron.tests.unit.midonet.mock_lib as mock_lib
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,9 +35,6 @@ import neutron.tests.unit.test_l3_plugin as test_l3_plugin
|
|||||||
MIDOKURA_PKG_PATH = "neutron.plugins.midonet.plugin"
|
MIDOKURA_PKG_PATH = "neutron.plugins.midonet.plugin"
|
||||||
MIDONET_PLUGIN_NAME = ('%s.MidonetPluginV2' % MIDOKURA_PKG_PATH)
|
MIDONET_PLUGIN_NAME = ('%s.MidonetPluginV2' % MIDOKURA_PKG_PATH)
|
||||||
|
|
||||||
# Need to mock the midonetclient module since the plugin will try to load it.
|
|
||||||
sys.modules["midonetclient"] = mock.Mock()
|
|
||||||
|
|
||||||
|
|
||||||
class MidonetPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
|
class MidonetPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
|
||||||
|
|
||||||
@ -51,6 +48,10 @@ class MidonetPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
|
|||||||
test_lib.test_config['config_files'] = [os.path.join(
|
test_lib.test_config['config_files'] = [os.path.join(
|
||||||
etc_path, 'midonet.ini.test')]
|
etc_path, 'midonet.ini.test')]
|
||||||
|
|
||||||
|
p = mock.patch.dict(sys.modules, {'midonetclient': mock.Mock()})
|
||||||
|
p.start()
|
||||||
|
# dict patches must be explicitly stopped
|
||||||
|
self.addCleanup(p.stop)
|
||||||
self.instance = self.mock_api.start()
|
self.instance = self.mock_api.start()
|
||||||
mock_cfg = mock_lib.MidonetLibMockConfig(self.instance.return_value)
|
mock_cfg = mock_lib.MidonetLibMockConfig(self.instance.return_value)
|
||||||
mock_cfg.setup()
|
mock_cfg.setup()
|
||||||
@ -68,8 +69,8 @@ class TestMidonetNetworksV2(test_plugin.TestNetworksV2,
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestMidonetL3NatTestCase(test_l3_plugin.L3NatDBIntTestCase,
|
class TestMidonetL3NatTestCase(MidonetPluginV2TestCase,
|
||||||
MidonetPluginV2TestCase):
|
test_l3_plugin.L3NatDBIntTestCase):
|
||||||
def setUp(self,
|
def setUp(self,
|
||||||
plugin=MIDONET_PLUGIN_NAME,
|
plugin=MIDONET_PLUGIN_NAME,
|
||||||
ext_mgr=None,
|
ext_mgr=None,
|
||||||
@ -147,6 +148,10 @@ class TestMidonetSecurityGroupsTestCase(sg.SecurityGroupDBTestCase):
|
|||||||
self.instance = self.mock_api.start()
|
self.instance = self.mock_api.start()
|
||||||
mock_cfg = mock_lib.MidonetLibMockConfig(self.instance.return_value)
|
mock_cfg = mock_lib.MidonetLibMockConfig(self.instance.return_value)
|
||||||
mock_cfg.setup()
|
mock_cfg.setup()
|
||||||
|
p = mock.patch.dict(sys.modules, {'midonetclient': mock.Mock()})
|
||||||
|
p.start()
|
||||||
|
# dict patches must be explicitly stopped
|
||||||
|
self.addCleanup(p.stop)
|
||||||
super(TestMidonetSecurityGroupsTestCase, self).setUp(self._plugin_name)
|
super(TestMidonetSecurityGroupsTestCase, self).setUp(self._plugin_name)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user