From: Eugene Nikanorov Date: Fri, 3 May 2013 14:57:00 +0000 (+0400) Subject: Add ability for core plugin to implement advanced services X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=738aa4133c740163c2ca3e44827e3b317f3ffd5d;p=openstack-build%2Fneutron-build.git Add ability for core plugin to implement advanced services implements blueprint api-core-for-services Add check for supported_extension_aliases in QuantumManager. If core plugin supports certain service extension, then core plugin is stored in service_plugins for the service type of this extension so corresponding extension could set it as a controller for REST calls. Change-Id: I9c883491f6f13770371e3444e7c17bd2164a7c07 --- diff --git a/quantum/manager.py b/quantum/manager.py index f9430cbd5..d014b7dd3 100644 --- a/quantum/manager.py +++ b/quantum/manager.py @@ -102,7 +102,29 @@ class QuantumManager(object): self.service_plugins = {constants.CORE: self.plugin} self._load_service_plugins() + def _load_services_from_core_plugin(self): + """Puts core plugin in service_plugins for supported services.""" + LOG.debug(_("Loading services supported by the core plugin")) + + # supported service types are derived from supported extensions + if not hasattr(self.plugin, "supported_extension_aliases"): + return + for ext_alias in self.plugin.supported_extension_aliases: + if ext_alias in constants.EXT_TO_SERVICE_MAPPING: + service_type = constants.EXT_TO_SERVICE_MAPPING[ext_alias] + self.service_plugins[service_type] = self.plugin + LOG.info(_("Service %s is supported by the core plugin"), + service_type) + def _load_service_plugins(self): + """Loads service plugins. + + Starts from the core plugin and checks if it supports + advanced services then loads classes provided in configuration. + """ + # load services from the core plugin first + self._load_services_from_core_plugin() + plugin_providers = cfg.CONF.service_plugins LOG.debug(_("Loading service plugins: %s"), plugin_providers) for provider in plugin_providers: diff --git a/quantum/plugins/common/constants.py b/quantum/plugins/common/constants.py index 650fa4051..53b273e2f 100644 --- a/quantum/plugins/common/constants.py +++ b/quantum/plugins/common/constants.py @@ -20,6 +20,12 @@ CORE = "CORE" DUMMY = "DUMMY" LOADBALANCER = "LOADBALANCER" +#maps extension alias to service type +EXT_TO_SERVICE_MAPPING = { + 'dummy': DUMMY, + 'lbaas': LOADBALANCER +} + # TODO(salvatore-orlando): Move these (or derive them) from conf file ALLOWED_SERVICES = [CORE, DUMMY, LOADBALANCER] diff --git a/quantum/tests/unit/test_quantum_manager.py b/quantum/tests/unit/test_quantum_manager.py index c17267370..705f3a196 100644 --- a/quantum/tests/unit/test_quantum_manager.py +++ b/quantum/tests/unit/test_quantum_manager.py @@ -41,6 +41,10 @@ def etcdir(*p): return os.path.join(ETCDIR, *p) +class MultiServiceCorePlugin(object): + supported_extension_aliases = ['lbaas', 'dummy'] + + class QuantumManagerTestCase(base.BaseTestCase): def setUp(self): @@ -48,6 +52,7 @@ class QuantumManagerTestCase(base.BaseTestCase): args = ['--config-file', etcdir('quantum.conf.test')] # If test_config specifies some config-file, use it, as well config.parse(args=args) + QuantumManager._instance = None self.addCleanup(cfg.CONF.reset) self.useFixture( fixtures.MonkeyPatch('quantum.manager.QuantumManager._instance')) @@ -70,14 +75,30 @@ class QuantumManagerTestCase(base.BaseTestCase): def test_multiple_plugins_specified_for_service_type(self): cfg.CONF.set_override("service_plugins", ["quantum.tests.unit.dummy_plugin." - "QuantumDummyPlugin", + "DummyServicePlugin", "quantum.tests.unit.dummy_plugin." - "QuantumDummyPlugin"]) - - try: - QuantumManager.get_instance().get_service_plugins() - self.assertTrue(False, - "Shouldn't load multiple plugins " - "for the same type") - except Exception as e: - LOG.debug(str(e)) + "DummyServicePlugin"]) + cfg.CONF.set_override("core_plugin", + test_config.get('plugin_name_v2', + DB_PLUGIN_KLASS)) + self.assertRaises(Exception, QuantumManager.get_instance) + + def test_service_plugin_conflicts_with_core_plugin(self): + cfg.CONF.set_override("service_plugins", + ["quantum.tests.unit.dummy_plugin." + "DummyServicePlugin"]) + cfg.CONF.set_override("core_plugin", + "quantum.tests.unit.test_quantum_manager." + "MultiServiceCorePlugin") + self.assertRaises(Exception, QuantumManager.get_instance) + + def test_core_plugin_supports_services(self): + cfg.CONF.set_override("core_plugin", + "quantum.tests.unit.test_quantum_manager." + "MultiServiceCorePlugin") + mgr = QuantumManager.get_instance() + svc_plugins = mgr.get_service_plugins() + self.assertEqual(3, len(svc_plugins)) + self.assertIn(constants.CORE, svc_plugins.keys()) + self.assertIn(constants.LOADBALANCER, svc_plugins.keys()) + self.assertIn(constants.DUMMY, svc_plugins.keys()) diff --git a/quantum/tests/unit/test_routerserviceinsertion.py b/quantum/tests/unit/test_routerserviceinsertion.py index 7e1f2b281..f7494ae28 100644 --- a/quantum/tests/unit/test_routerserviceinsertion.py +++ b/quantum/tests/unit/test_routerserviceinsertion.py @@ -168,7 +168,7 @@ class RouterServiceInsertionTestCase(base.BaseTestCase): #just stubbing core plugin with LoadBalancer plugin cfg.CONF.set_override('core_plugin', plugin) - cfg.CONF.set_override('service_plugins', [plugin]) + cfg.CONF.set_override('service_plugins', []) cfg.CONF.set_override('quota_router', -1, group='QUOTAS') self.addCleanup(cfg.CONF.reset)