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:
return os.path.join(ETCDIR, *p)
+class MultiServiceCorePlugin(object):
+ supported_extension_aliases = ['lbaas', 'dummy']
+
+
class QuantumManagerTestCase(base.BaseTestCase):
def setUp(self):
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'))
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())