Merge "Add ability for core plugin to implement advanced services"

This commit is contained in:
Jenkins 2013-05-14 08:12:13 +00:00 committed by Gerrit Code Review
commit df6109ae70
4 changed files with 59 additions and 10 deletions

View 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:

View 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]

View 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"])
"DummyServicePlugin"])
cfg.CONF.set_override("core_plugin",
test_config.get('plugin_name_v2',
DB_PLUGIN_KLASS))
self.assertRaises(Exception, QuantumManager.get_instance)
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))
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())

View 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)