]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add ability for core plugin to implement advanced services
authorEugene Nikanorov <enikanorov@mirantis.com>
Fri, 3 May 2013 14:57:00 +0000 (18:57 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Mon, 13 May 2013 10:20:00 +0000 (14:20 +0400)
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

quantum/manager.py
quantum/plugins/common/constants.py
quantum/tests/unit/test_quantum_manager.py
quantum/tests/unit/test_routerserviceinsertion.py

index f9430cbd54b4e1fe2eda697b9857f24d5b086749..d014b7dd3791a11bbec98e8fd4fc571768d86383 100644 (file)
@@ -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:
index 650fa40517193807df865db1d0c7cfa8b4acd846..53b273e2f9383b93f1ba0fed5ed3db9daddca16b 100644 (file)
@@ -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]
 
index c172673705275bf7e32c67740d5651f19f9046a6..705f3a196751cae726b480dd71640b5140a25ea2 100644 (file)
@@ -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())
index 7e1f2b2819f84f6e6c3afb852099e688edc63f35..f7494ae282ba8b8b000f8a5df09307eb616d9636 100644 (file)
@@ -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)