Merge "Add ability for core plugin to implement advanced services"
This commit is contained in:
commit
df6109ae70
@ -102,7 +102,29 @@ class QuantumManager(object):
|
|||||||
self.service_plugins = {constants.CORE: self.plugin}
|
self.service_plugins = {constants.CORE: self.plugin}
|
||||||
self._load_service_plugins()
|
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):
|
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
|
plugin_providers = cfg.CONF.service_plugins
|
||||||
LOG.debug(_("Loading service plugins: %s"), plugin_providers)
|
LOG.debug(_("Loading service plugins: %s"), plugin_providers)
|
||||||
for provider in plugin_providers:
|
for provider in plugin_providers:
|
||||||
|
@ -20,6 +20,12 @@ CORE = "CORE"
|
|||||||
DUMMY = "DUMMY"
|
DUMMY = "DUMMY"
|
||||||
LOADBALANCER = "LOADBALANCER"
|
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
|
# TODO(salvatore-orlando): Move these (or derive them) from conf file
|
||||||
ALLOWED_SERVICES = [CORE, DUMMY, LOADBALANCER]
|
ALLOWED_SERVICES = [CORE, DUMMY, LOADBALANCER]
|
||||||
|
|
||||||
|
@ -41,6 +41,10 @@ def etcdir(*p):
|
|||||||
return os.path.join(ETCDIR, *p)
|
return os.path.join(ETCDIR, *p)
|
||||||
|
|
||||||
|
|
||||||
|
class MultiServiceCorePlugin(object):
|
||||||
|
supported_extension_aliases = ['lbaas', 'dummy']
|
||||||
|
|
||||||
|
|
||||||
class QuantumManagerTestCase(base.BaseTestCase):
|
class QuantumManagerTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -48,6 +52,7 @@ class QuantumManagerTestCase(base.BaseTestCase):
|
|||||||
args = ['--config-file', etcdir('quantum.conf.test')]
|
args = ['--config-file', etcdir('quantum.conf.test')]
|
||||||
# If test_config specifies some config-file, use it, as well
|
# If test_config specifies some config-file, use it, as well
|
||||||
config.parse(args=args)
|
config.parse(args=args)
|
||||||
|
QuantumManager._instance = None
|
||||||
self.addCleanup(cfg.CONF.reset)
|
self.addCleanup(cfg.CONF.reset)
|
||||||
self.useFixture(
|
self.useFixture(
|
||||||
fixtures.MonkeyPatch('quantum.manager.QuantumManager._instance'))
|
fixtures.MonkeyPatch('quantum.manager.QuantumManager._instance'))
|
||||||
@ -70,14 +75,30 @@ class QuantumManagerTestCase(base.BaseTestCase):
|
|||||||
def test_multiple_plugins_specified_for_service_type(self):
|
def test_multiple_plugins_specified_for_service_type(self):
|
||||||
cfg.CONF.set_override("service_plugins",
|
cfg.CONF.set_override("service_plugins",
|
||||||
["quantum.tests.unit.dummy_plugin."
|
["quantum.tests.unit.dummy_plugin."
|
||||||
"QuantumDummyPlugin",
|
"DummyServicePlugin",
|
||||||
"quantum.tests.unit.dummy_plugin."
|
"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:
|
def test_service_plugin_conflicts_with_core_plugin(self):
|
||||||
QuantumManager.get_instance().get_service_plugins()
|
cfg.CONF.set_override("service_plugins",
|
||||||
self.assertTrue(False,
|
["quantum.tests.unit.dummy_plugin."
|
||||||
"Shouldn't load multiple plugins "
|
"DummyServicePlugin"])
|
||||||
"for the same type")
|
cfg.CONF.set_override("core_plugin",
|
||||||
except Exception as e:
|
"quantum.tests.unit.test_quantum_manager."
|
||||||
LOG.debug(str(e))
|
"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())
|
||||||
|
@ -168,7 +168,7 @@ class RouterServiceInsertionTestCase(base.BaseTestCase):
|
|||||||
|
|
||||||
#just stubbing core plugin with LoadBalancer plugin
|
#just stubbing core plugin with LoadBalancer plugin
|
||||||
cfg.CONF.set_override('core_plugin', 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')
|
cfg.CONF.set_override('quota_router', -1, group='QUOTAS')
|
||||||
self.addCleanup(cfg.CONF.reset)
|
self.addCleanup(cfg.CONF.reset)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user