From 2a23527a9a55fe8634c9255ca7ab969918de511a Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Mon, 25 Jul 2016 16:52:05 +0200 Subject: [PATCH] tests: stop using ml2 plugin full import paths in tests Stevedore documentation suggest that full import paths are not supposed to be user visible. Since unit tests emulate users when configuring oslo.config, we better off relying on well known plugin aliases than internal details. For in-tree that may be not a big deal, but with it we set a bad example for third parties that may later find their tests broken eg. when we decide to move code around. TrivialFix Change-Id: I7bd036ac3df7e7f4c678356d0a793e7d38599dda --- neutron/tests/fullstack/resources/config.py | 2 +- neutron/tests/functional/db/test_migrations.py | 4 +--- neutron/tests/functional/pecan_wsgi/test_functional.py | 2 +- .../functional/scheduler/test_l3_agent_scheduler.py | 3 +-- neutron/tests/functional/test_server.py | 4 ++-- neutron/tests/unit/db/test_agentschedulers_db.py | 10 +++------- neutron/tests/unit/db/test_ipam_backend_mixin.py | 3 +-- neutron/tests/unit/db/test_l3_dvr_db.py | 3 +-- neutron/tests/unit/db/test_l3_hamode_db.py | 2 +- .../tests/unit/extensions/test_availability_zone.py | 3 +-- neutron/tests/unit/extensions/test_quotasv2.py | 2 +- neutron/tests/unit/extensions/test_segment.py | 8 +++----- neutron/tests/unit/plugins/ml2/test_plugin.py | 2 +- neutron/tests/unit/plugins/ml2/test_port_binding.py | 7 +------ neutron/tests/unit/plugins/ml2/test_security_group.py | 4 +--- .../tests/unit/scheduler/test_dhcp_agent_scheduler.py | 3 +-- .../tests/unit/scheduler/test_l3_agent_scheduler.py | 7 +++---- 17 files changed, 24 insertions(+), 45 deletions(-) diff --git a/neutron/tests/fullstack/resources/config.py b/neutron/tests/fullstack/resources/config.py index ff89ff41d97..1db48bae6ea 100644 --- a/neutron/tests/fullstack/resources/config.py +++ b/neutron/tests/fullstack/resources/config.py @@ -65,7 +65,7 @@ class NeutronConfigFixture(ConfigFixture): 'lock_path': '$state_path/lock', 'api_paste_config': self._generate_api_paste(), 'policy_file': self._generate_policy_json(), - 'core_plugin': 'neutron.plugins.ml2.plugin.Ml2Plugin', + 'core_plugin': 'ml2', 'service_plugins': ','.join(service_plugins), 'auth_strategy': 'noauth', 'debug': 'True', diff --git a/neutron/tests/functional/db/test_migrations.py b/neutron/tests/functional/db/test_migrations.py index 0957e9e471e..250e2baf04f 100644 --- a/neutron/tests/functional/db/test_migrations.py +++ b/neutron/tests/functional/db/test_migrations.py @@ -37,8 +37,6 @@ from neutron.tests.unit import testlib_api cfg.CONF.import_opt('core_plugin', 'neutron.common.config') -CORE_PLUGIN = 'neutron.plugins.ml2.plugin.Ml2Plugin' - CREATION_OPERATIONS = { 'sqla': (sqla_ddl.CreateIndex, sqla_ddl.CreateTable, @@ -128,7 +126,7 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync): def setUp(self): super(_TestModelsMigrations, self).setUp() self.cfg = self.useFixture(config_fixture.Config()) - self.cfg.config(core_plugin=CORE_PLUGIN) + self.cfg.config(core_plugin='ml2') self.alembic_config = migration.get_neutron_config() self.alembic_config.neutron_config = cfg.CONF diff --git a/neutron/tests/functional/pecan_wsgi/test_functional.py b/neutron/tests/functional/pecan_wsgi/test_functional.py index 5c26464fed4..13ca6f0c82b 100644 --- a/neutron/tests/functional/pecan_wsgi/test_functional.py +++ b/neutron/tests/functional/pecan_wsgi/test_functional.py @@ -30,7 +30,7 @@ from neutron.tests.unit import testlib_api class PecanFunctionalTest(testlib_api.SqlTestCase): def setUp(self, service_plugins=None, extensions=None): - self.setup_coreplugin('neutron.plugins.ml2.plugin.Ml2Plugin') + self.setup_coreplugin('ml2') super(PecanFunctionalTest, self).setUp() self.addCleanup(exts.PluginAwareExtensionManager.clear_instance) self.addCleanup(set_config, {}, overwrite=True) diff --git a/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py b/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py index b3b4c76c0f3..14422cb3952 100644 --- a/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py @@ -280,8 +280,7 @@ class L3LeastRoutersSchedulerTestCase(L3SchedulerBaseTest): class L3AZSchedulerBaseTest(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def setUp(self): - core_plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin' - super(L3AZSchedulerBaseTest, self).setUp(plugin=core_plugin) + super(L3AZSchedulerBaseTest, self).setUp(plugin='ml2') self.l3_plugin = l3_router_plugin.L3RouterPlugin() self.l3_plugin.router_scheduler = None diff --git a/neutron/tests/functional/test_server.py b/neutron/tests/functional/test_server.py index 7c8c79d43a9..aa4a5e00614 100644 --- a/neutron/tests/functional/test_server.py +++ b/neutron/tests/functional/test_server.py @@ -223,7 +223,7 @@ class TestRPCServer(TestNeutronServer): def setUp(self): super(TestRPCServer, self).setUp() - self.setup_coreplugin(TARGET_PLUGIN) + self.setup_coreplugin('ml2') self._plugin_patcher = mock.patch(TARGET_PLUGIN, autospec=True) self.plugin = self._plugin_patcher.start() self.plugin.return_value.rpc_workers_supported = True @@ -257,7 +257,7 @@ class TestPluginWorker(TestNeutronServer): def setUp(self): super(TestPluginWorker, self).setUp() - self.setup_coreplugin(TARGET_PLUGIN) + self.setup_coreplugin('ml2') self._plugin_patcher = mock.patch(TARGET_PLUGIN, autospec=True) self.plugin = self._plugin_patcher.start() diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 374f2ffc97c..88de36598e6 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -225,7 +225,6 @@ class OvsAgentSchedulerTestCaseBase(test_l3.L3NatTestCaseMixin, AgentSchedulerTestMixIn, test_plugin.NeutronDbPluginV2TestCase): fmt = 'json' - plugin_str = 'neutron.plugins.ml2.plugin.Ml2Plugin' l3_plugin = ('neutron.tests.unit.extensions.test_l3.' 'TestL3NatAgentSchedulingServicePlugin') @@ -241,7 +240,7 @@ class OvsAgentSchedulerTestCaseBase(test_l3.L3NatTestCaseMixin, mock.patch('neutron.common.rpc.get_client' ).start().return_value = self.client_mock super(OvsAgentSchedulerTestCaseBase, self).setUp( - self.plugin_str, service_plugins=service_plugins) + 'ml2', service_plugins=service_plugins) mock.patch.object( self.plugin, 'filter_hosts_with_network_access', side_effect=lambda context, network_id, hosts: hosts).start() @@ -1292,11 +1291,9 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn, AgentSchedulerTestMixIn, test_plugin.NeutronDbPluginV2TestCase): - plugin_str = 'neutron.plugins.ml2.plugin.Ml2Plugin' - def setUp(self): self.useFixture(tools.AttributeMapMemento()) - super(OvsDhcpAgentNotifierTestCase, self).setUp(self.plugin_str) + super(OvsDhcpAgentNotifierTestCase, self).setUp('ml2') mock.patch.object( self.plugin, 'filter_hosts_with_network_access', side_effect=lambda context, network_id, hosts: hosts).start() @@ -1437,7 +1434,6 @@ class OvsL3AgentNotifierTestCase(test_l3.L3NatTestCaseMixin, test_agent.AgentDBTestMixIn, AgentSchedulerTestMixIn, test_plugin.NeutronDbPluginV2TestCase): - plugin_str = 'neutron.plugins.ml2.plugin.Ml2Plugin' l3_plugin = ('neutron.tests.unit.extensions.test_l3.' 'TestL3NatAgentSchedulingServicePlugin') @@ -1456,7 +1452,7 @@ class OvsL3AgentNotifierTestCase(test_l3.L3NatTestCaseMixin, else: service_plugins = None super(OvsL3AgentNotifierTestCase, self).setUp( - self.plugin_str, service_plugins=service_plugins) + 'ml2', service_plugins=service_plugins) ext_mgr = extensions.PluginAwareExtensionManager.get_instance() self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr) self.adminContext = context.get_admin_context() diff --git a/neutron/tests/unit/db/test_ipam_backend_mixin.py b/neutron/tests/unit/db/test_ipam_backend_mixin.py index 66113dd459d..6e2be7ce295 100644 --- a/neutron/tests/unit/db/test_ipam_backend_mixin.py +++ b/neutron/tests/unit/db/test_ipam_backend_mixin.py @@ -222,5 +222,4 @@ class TestPortUpdateIpam(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): class TestPortUpdateIpamML2(TestPortUpdateIpam): def setUp(self): - super(TestPortUpdateIpamML2, self).setUp( - plugin='neutron.plugins.ml2.plugin.Ml2Plugin') + super(TestPortUpdateIpamML2, self).setUp(plugin='ml2') diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 91443307349..6885c5e4130 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -42,8 +42,7 @@ class FakeL3Plugin(common_db_mixin.CommonDbMixin, class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def setUp(self): - core_plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin' - super(L3DvrTestCase, self).setUp(plugin=core_plugin) + super(L3DvrTestCase, self).setUp(plugin='ml2') self.core_plugin = manager.NeutronManager.get_plugin() self.ctx = context.get_admin_context() self.mixin = FakeL3Plugin() diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index 60106b349c7..51ebe6b609e 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -54,7 +54,7 @@ class L3HATestFramework(testlib_api.SqlTestCase): super(L3HATestFramework, self).setUp() self.admin_ctx = context.get_admin_context() - self.setup_coreplugin('neutron.plugins.ml2.plugin.Ml2Plugin') + self.setup_coreplugin('ml2') self.core_plugin = manager.NeutronManager.get_plugin() notif_p = mock.patch.object(l3_hamode_db.L3_HA_NAT_db_mixin, '_notify_ha_interfaces_updated') diff --git a/neutron/tests/unit/extensions/test_availability_zone.py b/neutron/tests/unit/extensions/test_availability_zone.py index 32e202e7a60..918bf439c42 100644 --- a/neutron/tests/unit/extensions/test_availability_zone.py +++ b/neutron/tests/unit/extensions/test_availability_zone.py @@ -94,9 +94,8 @@ class TestAZAgentCase(AZTestCommon): class TestAZNetworkCase(AZTestCommon): def setUp(self): - plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin' ext_mgr = AZExtensionManager() - super(TestAZNetworkCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr) + super(TestAZNetworkCase, self).setUp(plugin='ml2', ext_mgr=ext_mgr) def test_availability_zones_in_create_response(self): with self.network() as net: diff --git a/neutron/tests/unit/extensions/test_quotasv2.py b/neutron/tests/unit/extensions/test_quotasv2.py index 402fd381683..4d1adafbde1 100644 --- a/neutron/tests/unit/extensions/test_quotasv2.py +++ b/neutron/tests/unit/extensions/test_quotasv2.py @@ -54,7 +54,7 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase): self.config_parse() # Update the plugin and extensions path - self.setup_coreplugin(TARGET_PLUGIN) + self.setup_coreplugin('ml2') quota.QUOTAS = quota.QuotaEngine() self._plugin_patcher = mock.patch(TARGET_PLUGIN, autospec=True) self.plugin = self._plugin_patcher.start() diff --git a/neutron/tests/unit/extensions/test_segment.py b/neutron/tests/unit/extensions/test_segment.py index 0a3f7ceaa4b..0645086e9eb 100644 --- a/neutron/tests/unit/extensions/test_segment.py +++ b/neutron/tests/unit/extensions/test_segment.py @@ -199,8 +199,7 @@ class TestSegment(SegmentTestCase): class TestSegmentML2(SegmentTestCase): def setUp(self): - super(TestSegmentML2, self).setUp( - plugin='neutron.plugins.ml2.plugin.Ml2Plugin') + super(TestSegmentML2, self).setUp(plugin='ml2') def test_segment_notification_on_create_network(self): with mock.patch.object(registry, 'notify') as notify: @@ -305,7 +304,7 @@ class HostSegmentMappingTestCase(SegmentTestCase): self._mechanism_drivers, group='ml2') if not plugin: - plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin' + plugin = 'ml2' super(HostSegmentMappingTestCase, self).setUp(plugin=plugin) db.subscribe() @@ -1039,8 +1038,7 @@ class TestSegmentAwareIpam(SegmentTestCase): class TestSegmentAwareIpamML2(TestSegmentAwareIpam): def setUp(self): - super(TestSegmentAwareIpamML2, self).setUp( - plugin='neutron.plugins.ml2.plugin.Ml2Plugin') + super(TestSegmentAwareIpamML2, self).setUp(plugin='ml2') class TestDhcpAgentSegmentScheduling(HostSegmentMappingTestCase): diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 15c89f255cc..afd2f68aa53 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -76,7 +76,7 @@ config.cfg.CONF.import_opt('network_vlan_ranges', group='ml2_type_vlan') -PLUGIN_NAME = 'neutron.plugins.ml2.plugin.Ml2Plugin' +PLUGIN_NAME = 'ml2' DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' HOST = 'fake_host' diff --git a/neutron/tests/unit/plugins/ml2/test_port_binding.py b/neutron/tests/unit/plugins/ml2/test_port_binding.py index b4e177a64ee..f4fd1419dcd 100644 --- a/neutron/tests/unit/plugins/ml2/test_port_binding.py +++ b/neutron/tests/unit/plugins/ml2/test_port_binding.py @@ -25,13 +25,8 @@ from neutron.plugins.ml2 import models as ml2_models from neutron.tests.unit.db import test_db_base_plugin_v2 as test_plugin -PLUGIN_NAME = 'neutron.plugins.ml2.plugin.Ml2Plugin' - - class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase): - _plugin_name = PLUGIN_NAME - def setUp(self): # Enable the test mechanism driver to ensure that # we can successfully call through to all mechanism @@ -42,7 +37,7 @@ class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase): config.cfg.CONF.set_override('network_vlan_ranges', ['physnet1:1000:1099'], group='ml2_type_vlan') - super(PortBindingTestCase, self).setUp(PLUGIN_NAME) + super(PortBindingTestCase, self).setUp('ml2') self.port_create_status = 'DOWN' self.plugin = manager.NeutronManager.get_plugin() self.plugin.start_rpc_listeners() diff --git a/neutron/tests/unit/plugins/ml2/test_security_group.py b/neutron/tests/unit/plugins/ml2/test_security_group.py index 67e0f5428f1..cc1056ccd75 100644 --- a/neutron/tests/unit/plugins/ml2/test_security_group.py +++ b/neutron/tests/unit/plugins/ml2/test_security_group.py @@ -27,12 +27,10 @@ from neutron.tests.unit.agent import test_securitygroups_rpc as test_sg_rpc from neutron.tests.unit.api.v2 import test_base from neutron.tests.unit.extensions import test_securitygroup as test_sg -PLUGIN_NAME = 'neutron.plugins.ml2.plugin.Ml2Plugin' NOTIFIER = 'neutron.plugins.ml2.rpc.AgentNotifierApi' class Ml2SecurityGroupsTestCase(test_sg.SecurityGroupDBTestCase): - _plugin_name = PLUGIN_NAME def setUp(self, plugin=None): test_sg_rpc.set_firewall_driver(test_sg_rpc.FIREWALL_HYBRID_DRIVER) @@ -41,7 +39,7 @@ class Ml2SecurityGroupsTestCase(test_sg.SecurityGroupDBTestCase): self.notifier = mock.Mock() notifier_cls.return_value = self.notifier self.useFixture(tools.AttributeMapMemento()) - super(Ml2SecurityGroupsTestCase, self).setUp(PLUGIN_NAME) + super(Ml2SecurityGroupsTestCase, self).setUp('ml2') def tearDown(self): super(Ml2SecurityGroupsTestCase, self).tearDown() diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py index c4ed58a846f..8f68a379664 100644 --- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py @@ -618,8 +618,7 @@ class DHCPAgentAZAwareWeightSchedulerTestCase(TestDhcpSchedulerBaseTestCase): def setUp(self): super(DHCPAgentAZAwareWeightSchedulerTestCase, self).setUp() - DB_PLUGIN_KLASS = 'neutron.plugins.ml2.plugin.Ml2Plugin' - self.setup_coreplugin(DB_PLUGIN_KLASS) + self.setup_coreplugin('ml2') cfg.CONF.set_override("network_scheduler_driver", 'neutron.scheduler.dhcp_agent_scheduler.AZAwareWeightScheduler') self.plugin = importutils.import_object('neutron.plugins.ml2.plugin.' diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index b2bf5705c56..25beda58874 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -863,8 +863,7 @@ class L3DvrScheduler(l3_db.L3_NAT_db_mixin, class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): def setUp(self): - plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin' - self.setup_coreplugin(plugin) + self.setup_coreplugin('ml2') super(L3DvrSchedulerTestCase, self).setUp() self.adminContext = n_context.get_admin_context() self.dut = L3DvrScheduler() @@ -1418,7 +1417,7 @@ class L3HATestCaseMixin(testlib_api.SqlTestCase, mock.patch('neutron.common.rpc.get_client').start() self.plugin = L3HAPlugin() - self.setup_coreplugin('neutron.plugins.ml2.plugin.Ml2Plugin') + self.setup_coreplugin('ml2') cfg.CONF.set_override('service_plugins', ['neutron.services.l3_router.' 'l3_router_plugin.L3RouterPlugin']) @@ -1821,7 +1820,7 @@ class TestGetL3AgentsWithAgentModeFilter(testlib_api.SqlTestCase, def setUp(self): super(TestGetL3AgentsWithAgentModeFilter, self).setUp() self.plugin = L3HAPlugin() - self.setup_coreplugin('neutron.plugins.ml2.plugin.Ml2Plugin') + self.setup_coreplugin('ml2') self.adminContext = n_context.get_admin_context() hosts = ['host_1', 'host_2', 'host_3', 'host_4', 'host_5'] agent_modes = ['legacy', 'dvr_snat', 'dvr', 'fake_mode', 'legacy']