Merge "Select service_provider on the basis of service_module"

This commit is contained in:
Zuul 2018-11-15 12:47:09 +00:00 committed by Gerrit Code Review
commit 1e0a5b901a
4 changed files with 17 additions and 7 deletions

View File

@ -554,7 +554,7 @@ your code::
service_type_manager = servicetype_db.ServiceTypeManager.get_instance()
service_type_manager.add_provider_configuration(
YOUR_SERVICE_TYPE,
pconf.ProviderConfiguration(YOUR_SERVICE_MODULE))
pconf.ProviderConfiguration(YOUR_SERVICE_MODULE, YOUR_SERVICE_TYPE))
This is typically required when you instantiate your service plugin class.

View File

@ -242,7 +242,8 @@ class _LegacyPlusProviderConfiguration(
# loads up ha, dvr, and single_node service providers automatically.
# If an operator has setup explicit values that conflict with these,
# the operator defined values will take priority.
super(_LegacyPlusProviderConfiguration, self).__init__()
super(_LegacyPlusProviderConfiguration, self).__init__(
svc_type=plugin_constants.L3)
for name, driver in (('dvrha', 'dvrha.DvrHaDriver'),
('dvr', 'dvr.DvrDriver'), ('ha', 'ha.HaDriver'),
('single_node', 'single_node.SingleNodeDriver')):

View File

@ -156,7 +156,7 @@ def get_provider_driver_class(driver, namespace=SERVICE_PROVIDERS):
return new_driver
def parse_service_provider_opt(service_module='neutron'):
def parse_service_provider_opt(service_module='neutron', service_type=None):
"""Parse service definition opts and returns result."""
def validate_name(name):
@ -175,6 +175,8 @@ def parse_service_provider_opt(service_module='neutron'):
split = prov_def.split(':')
try:
svc_type, name, driver = split[:3]
if service_type and service_type != svc_type:
continue
except ValueError:
raise n_exc.Invalid(_("Invalid service provider format"))
validate_name(name)
@ -215,9 +217,9 @@ class ServiceProviderAlreadyAssociated(n_exc.Conflict):
class ProviderConfiguration(object):
def __init__(self, svc_module='neutron'):
def __init__(self, svc_module='neutron', svc_type=None):
self.providers = {}
for prov in parse_service_provider_opt(svc_module):
for prov in parse_service_provider_opt(svc_module, svc_type):
self.add_provider(prov)
def _ensure_driver_unique(self, driver):

View File

@ -54,8 +54,10 @@ class ServiceTypeManagerTestCase(testlib_api.SqlTestCase):
st_db.ServiceTypeManager._instance = None
self.manager = st_db.ServiceTypeManager.get_instance()
for provider in service_providers:
service_type = provider.split(':')[0]
self.manager.add_provider_configuration(
provider.split(':')[0], provconf.ProviderConfiguration())
service_type, provconf.ProviderConfiguration(
svc_type=service_type))
def test_service_provider_driver_not_unique(self):
self._set_override([constants.LOADBALANCER + ':lbaas:driver'])
@ -75,6 +77,9 @@ class ServiceTypeManagerTestCase(testlib_api.SqlTestCase):
constants.FIREWALL +
':fwaas:driver_path2'])
ctx = context.get_admin_context()
res = self.manager.get_service_providers(ctx)
self.assertEqual(2, len(res))
res = self.manager.get_service_providers(
ctx,
filters=dict(service_type=[constants.LOADBALANCER])
@ -235,8 +240,10 @@ class ServiceTypeManagerExtTestCase(ServiceTypeExtensionTestCaseBase):
st_db.ServiceTypeManager._instance = None
self.manager = st_db.ServiceTypeManager.get_instance()
for provider in service_providers:
service_type = provider.split(':')[0]
self.manager.add_provider_configuration(
provider.split(':')[0], provconf.ProviderConfiguration())
service_type, provconf.ProviderConfiguration(
svc_type=service_type))
super(ServiceTypeManagerExtTestCase, self).setUp()
def _list_service_providers(self):