Merge "tests/unit: Initialize core plugin in TestL3GwModeMixin"

This commit is contained in:
Jenkins 2014-02-21 01:45:48 +00:00 committed by Gerrit Code Review
commit 7711351cd5
15 changed files with 29 additions and 47 deletions

View File

@ -26,6 +26,7 @@ import fixtures
from oslo.config import cfg from oslo.config import cfg
import testtools import testtools
from neutron import manager
from neutron.tests import post_mortem_debug from neutron.tests import post_mortem_debug
@ -40,6 +41,16 @@ def fake_use_fatal_exceptions(*args):
class BaseTestCase(testtools.TestCase): class BaseTestCase(testtools.TestCase):
def _cleanup_coreplugin(self):
manager.NeutronManager._instance = self._saved_instance
def setup_coreplugin(self, core_plugin=None):
self._saved_instance = manager.NeutronManager._instance
self.addCleanup(self._cleanup_coreplugin)
manager.NeutronManager._instance = None
if core_plugin is not None:
cfg.CONF.set_override('core_plugin', core_plugin)
def setUp(self): def setUp(self):
super(BaseTestCase, self).setUp() super(BaseTestCase, self).setUp()

View File

@ -99,6 +99,8 @@ class MetaNeutronPluginV2Test(base.BaseTestCase):
self.client_inst.delete_network.return_value = True self.client_inst.delete_network.return_value = True
self.client_inst.delete_port.return_value = True self.client_inst.delete_port.return_value = True
self.client_inst.delete_subnet.return_value = True self.client_inst.delete_subnet.return_value = True
plugin = MetaPluginV2.__module__ + '.' + MetaPluginV2.__name__
self.setup_coreplugin(plugin)
self.plugin = MetaPluginV2(configfile=None) self.plugin = MetaPluginV2(configfile=None)
def _fake_network(self, flavor): def _fake_network(self, flavor):

View File

@ -68,8 +68,6 @@ class NetworkGatewayExtensionTestCase(base.BaseTestCase):
plugin = '%s.%s' % (networkgw.__name__, plugin = '%s.%s' % (networkgw.__name__,
networkgw.NetworkGatewayPluginBase.__name__) networkgw.NetworkGatewayPluginBase.__name__)
self._resource = networkgw.RESOURCE_NAME.replace('-', '_') self._resource = networkgw.RESOURCE_NAME.replace('-', '_')
# Ensure 'stale' patched copies of the plugin are never returned
manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
@ -79,7 +77,7 @@ class NetworkGatewayExtensionTestCase(base.BaseTestCase):
config.parse(args=args) config.parse(args=args)
# Update the plugin and extensions path # Update the plugin and extensions path
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
self.addCleanup(cfg.CONF.reset) self.addCleanup(cfg.CONF.reset)
_plugin_patcher = mock.patch(plugin, autospec=True) _plugin_patcher = mock.patch(plugin, autospec=True)

View File

@ -26,7 +26,6 @@ from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
from neutron.common import config from neutron.common import config
from neutron.extensions import loadbalancer from neutron.extensions import loadbalancer
from neutron import manager
from neutron.openstack.common import uuidutils from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants from neutron.plugins.common import constants
from neutron.tests.unit import test_api_v2 from neutron.tests.unit import test_api_v2
@ -62,8 +61,6 @@ class LoadBalancerExtensionTestCase(testlib_api.WebTestCase):
def setUp(self): def setUp(self):
super(LoadBalancerExtensionTestCase, self).setUp() super(LoadBalancerExtensionTestCase, self).setUp()
plugin = 'neutron.extensions.loadbalancer.LoadBalancerPluginBase' plugin = 'neutron.extensions.loadbalancer.LoadBalancerPluginBase'
# Ensure 'stale' patched copies of the plugin are never returned
manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
@ -73,7 +70,7 @@ class LoadBalancerExtensionTestCase(testlib_api.WebTestCase):
config.parse(args) config.parse(args)
#just stubbing core plugin with LoadBalancer plugin #just stubbing core plugin with LoadBalancer plugin
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('service_plugins', [plugin]) cfg.CONF.set_override('service_plugins', [plugin])
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)

View File

@ -28,7 +28,6 @@ from neutron.api import extensions
from neutron.api.v2 import attributes from neutron.api.v2 import attributes
from neutron.common import config from neutron.common import config
from neutron.extensions import vpnaas from neutron.extensions import vpnaas
from neutron import manager
from neutron.openstack.common import uuidutils from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants from neutron.plugins.common import constants
from neutron import quota from neutron import quota
@ -65,8 +64,6 @@ class VpnaasExtensionTestCase(testlib_api.WebTestCase):
def setUp(self): def setUp(self):
super(VpnaasExtensionTestCase, self).setUp() super(VpnaasExtensionTestCase, self).setUp()
plugin = 'neutron.extensions.vpnaas.VPNPluginBase' plugin = 'neutron.extensions.vpnaas.VPNPluginBase'
# Ensure 'stale' patched copies of the plugin are never returned
manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
@ -76,7 +73,7 @@ class VpnaasExtensionTestCase(testlib_api.WebTestCase):
config.parse(args) config.parse(args)
#just stubbing core plugin with LoadBalancer plugin #just stubbing core plugin with LoadBalancer plugin
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('service_plugins', [plugin]) cfg.CONF.set_override('service_plugins', [plugin])
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)

View File

@ -97,15 +97,13 @@ class APIv2TestBase(base.BaseTestCase):
super(APIv2TestBase, self).setUp() super(APIv2TestBase, self).setUp()
plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2' plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2'
# Ensure 'stale' patched copies of the plugin are never returned
NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
PluginAwareExtensionManager._instance = None PluginAwareExtensionManager._instance = None
# Create the default configurations # Create the default configurations
args = ['--config-file', etcdir('neutron.conf.test')] args = ['--config-file', etcdir('neutron.conf.test')]
config.parse(args=args) config.parse(args=args)
# Update the plugin # Update the plugin
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('allow_pagination', True) cfg.CONF.set_override('allow_pagination', True)
cfg.CONF.set_override('allow_sorting', True) cfg.CONF.set_override('allow_sorting', True)
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)
@ -1130,7 +1128,6 @@ class SubresourceTest(base.BaseTestCase):
super(SubresourceTest, self).setUp() super(SubresourceTest, self).setUp()
plugin = 'neutron.tests.unit.test_api_v2.TestSubresourcePlugin' plugin = 'neutron.tests.unit.test_api_v2.TestSubresourcePlugin'
NeutronManager._instance = None
PluginAwareExtensionManager._instance = None PluginAwareExtensionManager._instance = None
# Save the global RESOURCE_ATTRIBUTE_MAP # Save the global RESOURCE_ATTRIBUTE_MAP
@ -1140,7 +1137,7 @@ class SubresourceTest(base.BaseTestCase):
args = ['--config-file', etcdir('neutron.conf.test')] args = ['--config-file', etcdir('neutron.conf.test')]
config.parse(args=args) config.parse(args=args)
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)
self.plugin = self._plugin_patcher.start() self.plugin = self._plugin_patcher.start()
@ -1354,9 +1351,6 @@ class ExtensionTestCase(base.BaseTestCase):
super(ExtensionTestCase, self).setUp() super(ExtensionTestCase, self).setUp()
plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2' plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2'
# Ensure 'stale' patched copies of the plugin are never returned
NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
PluginAwareExtensionManager._instance = None PluginAwareExtensionManager._instance = None
@ -1370,7 +1364,7 @@ class ExtensionTestCase(base.BaseTestCase):
config.parse(args=args) config.parse(args=args)
# Update the plugin and extensions path # Update the plugin and extensions path
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('api_extensions_path', EXTDIR) cfg.CONF.set_override('api_extensions_path', EXTDIR)
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)

View File

@ -78,8 +78,6 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
ext_mgr=None): ext_mgr=None):
super(NeutronDbPluginV2TestCase, self).setUp() super(NeutronDbPluginV2TestCase, self).setUp()
# Make sure at each test a new instance of the plugin is returned
NeutronManager._instance = None
# Make sure at each test according extensions for the plugin is loaded # Make sure at each test according extensions for the plugin is loaded
PluginAwareExtensionManager._instance = None PluginAwareExtensionManager._instance = None
# Save the attributes map in case the plugin will alter it # Save the attributes map in case the plugin will alter it
@ -104,7 +102,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
args.extend(['--config-file', config_file]) args.extend(['--config-file', config_file])
config.parse(args=args) config.parse(args=args)
# Update the plugin # Update the plugin
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override( cfg.CONF.set_override(
'service_plugins', 'service_plugins',
[test_config.get(key, default) [test_config.get(key, default)

View File

@ -82,6 +82,8 @@ class TestL3GwModeMixin(base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestL3GwModeMixin, self).setUp() super(TestL3GwModeMixin, self).setUp()
plugin = __name__ + '.' + TestDbIntPlugin.__name__
self.setup_coreplugin(plugin)
self.target_object = TestDbIntPlugin() self.target_object = TestDbIntPlugin()
# Patch the context # Patch the context
ctx_patcher = mock.patch('neutron.context', autospec=True) ctx_patcher = mock.patch('neutron.context', autospec=True)

View File

@ -80,9 +80,7 @@ class ExtensionExtendedAttributeTestCase(base.BaseTestCase):
args = ['--config-file', test_api_v2.etcdir('neutron.conf.test')] args = ['--config-file', test_api_v2.etcdir('neutron.conf.test')]
config.parse(args=args) config.parse(args=args)
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
manager.NeutronManager._instance = None
ext_mgr = extensions.PluginAwareExtensionManager( ext_mgr = extensions.PluginAwareExtensionManager(
extensions_path, extensions_path,

View File

@ -28,7 +28,6 @@ from neutron.api import extensions
from neutron.api.v2 import attributes from neutron.api.v2 import attributes
from neutron.common import config from neutron.common import config
from neutron.extensions import firewall from neutron.extensions import firewall
from neutron import manager
from neutron.openstack.common import uuidutils from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants from neutron.plugins.common import constants
from neutron.tests import base from neutron.tests import base
@ -65,8 +64,6 @@ class FirewallExtensionTestCase(testlib_api.WebTestCase):
def setUp(self): def setUp(self):
super(FirewallExtensionTestCase, self).setUp() super(FirewallExtensionTestCase, self).setUp()
plugin = 'neutron.extensions.firewall.FirewallPluginBase' plugin = 'neutron.extensions.firewall.FirewallPluginBase'
# Ensure 'stale' patched copies of the plugin are never returned
manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
@ -76,7 +73,7 @@ class FirewallExtensionTestCase(testlib_api.WebTestCase):
config.parse(args) config.parse(args)
# Stubbing core plugin with Firewall plugin # Stubbing core plugin with Firewall plugin
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('service_plugins', [plugin]) cfg.CONF.set_override('service_plugins', [plugin])
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)

View File

@ -58,8 +58,6 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase):
super(ProvidernetExtensionTestCase, self).setUp() super(ProvidernetExtensionTestCase, self).setUp()
plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2' plugin = 'neutron.neutron_plugin_base_v2.NeutronPluginBaseV2'
# Ensure 'stale' patched copies of the plugin are never returned
NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
@ -70,7 +68,7 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase):
self.saved_attr_map[resource] = attrs.copy() self.saved_attr_map[resource] = attrs.copy()
# Update the plugin and extensions path # Update the plugin and extensions path
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('allow_pagination', True) cfg.CONF.set_override('allow_pagination', True)
cfg.CONF.set_override('allow_sorting', True) cfg.CONF.set_override('allow_sorting', True)
self._plugin_patcher = mock.patch(plugin, autospec=True) self._plugin_patcher = mock.patch(plugin, autospec=True)

View File

@ -58,7 +58,7 @@ class NeutronManagerTestCase(base.BaseTestCase):
args = ['--config-file', etcdir('neutron.conf.test')] args = ['--config-file', etcdir('neutron.conf.test')]
# If test_config specifies some config-file, use it, as well # If test_config specifies some config-file, use it, as well
config.parse(args=args) config.parse(args=args)
NeutronManager._instance = None self.setup_coreplugin()
self.addCleanup(cfg.CONF.reset) self.addCleanup(cfg.CONF.reset)
self.useFixture( self.useFixture(
fixtures.MonkeyPatch('neutron.manager.NeutronManager._instance')) fixtures.MonkeyPatch('neutron.manager.NeutronManager._instance'))

View File

@ -29,7 +29,6 @@ from neutron.common import exceptions
from neutron import context from neutron import context
from neutron.db import api as db from neutron.db import api as db
from neutron.db import quota_db from neutron.db import quota_db
from neutron import manager
from neutron.plugins.linuxbridge.db import l2network_db_v2 from neutron.plugins.linuxbridge.db import l2network_db_v2
from neutron import quota from neutron import quota
from neutron.tests import base from neutron.tests import base
@ -47,9 +46,6 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase):
def setUp(self): def setUp(self):
super(QuotaExtensionTestCase, self).setUp() super(QuotaExtensionTestCase, self).setUp()
# Ensure 'stale' patched copies of the plugin are never returned
manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
@ -63,7 +59,7 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase):
config.parse(args=args) config.parse(args=args)
# Update the plugin and extensions path # Update the plugin and extensions path
cfg.CONF.set_override('core_plugin', TARGET_PLUGIN) self.setup_coreplugin(TARGET_PLUGIN)
cfg.CONF.set_override( cfg.CONF.set_override(
'quota_items', 'quota_items',
['network', 'subnet', 'port', 'extra1'], ['network', 'subnet', 'port', 'extra1'],

View File

@ -167,14 +167,11 @@ class RouterServiceInsertionTestCase(base.BaseTestCase):
config.parse(args=args) config.parse(args=args)
#just stubbing core plugin with LoadBalancer plugin #just stubbing core plugin with LoadBalancer plugin
cfg.CONF.set_override('core_plugin', plugin) self.setup_coreplugin(plugin)
cfg.CONF.set_override('service_plugins', []) cfg.CONF.set_override('service_plugins', [])
cfg.CONF.set_override('quota_router', -1, group='QUOTAS') cfg.CONF.set_override('quota_router', -1, group='QUOTAS')
self.addCleanup(cfg.CONF.reset) self.addCleanup(cfg.CONF.reset)
# Ensure 'stale' patched copies of the plugin are never returned
neutron.manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
ext_mgr = extensions.PluginAwareExtensionManager( ext_mgr = extensions.PluginAwareExtensionManager(

View File

@ -30,7 +30,6 @@ from neutron import context
from neutron.db import api as db_api from neutron.db import api as db_api
from neutron.db import servicetype_db as st_db from neutron.db import servicetype_db as st_db
from neutron.extensions import servicetype from neutron.extensions import servicetype
from neutron import manager
from neutron.plugins.common import constants from neutron.plugins.common import constants
from neutron.services import provider_configuration as provconf from neutron.services import provider_configuration as provconf
from neutron.tests import base from neutron.tests import base
@ -175,14 +174,12 @@ class ServiceTypeExtensionTestCaseBase(testlib_api.WebTestCase):
def setUp(self): def setUp(self):
# This is needed because otherwise a failure will occur due to # This is needed because otherwise a failure will occur due to
# nonexisting core_plugin # nonexisting core_plugin
cfg.CONF.set_override('core_plugin', test_db_plugin.DB_PLUGIN_KLASS) self.setup_coreplugin(test_db_plugin.DB_PLUGIN_KLASS)
cfg.CONF.set_override('service_plugins', cfg.CONF.set_override('service_plugins',
["%s.%s" % (dp.__name__, ["%s.%s" % (dp.__name__,
dp.DummyServicePlugin.__name__)]) dp.DummyServicePlugin.__name__)])
self.addCleanup(cfg.CONF.reset) self.addCleanup(cfg.CONF.reset)
# Make sure at each test a new instance of the plugin is returned
manager.NeutronManager._instance = None
# Ensure existing ExtensionManager is not used # Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None extensions.PluginAwareExtensionManager._instance = None
ext_mgr = TestServiceTypeExtensionManager() ext_mgr = TestServiceTypeExtensionManager()