Merge "Register provider configuration with ServiceTypeManager"
This commit is contained in:
commit
3693ebbbac
|
@ -56,6 +56,17 @@ def verify_lbaas_mutual_exclusion():
|
|||
raise SystemExit(1)
|
||||
|
||||
|
||||
def add_provider_configuration(type_manager, service_type):
|
||||
try:
|
||||
type_manager.add_provider_configuration(
|
||||
service_type,
|
||||
pconf.ProviderConfiguration('neutron_lbaas'))
|
||||
except AttributeError:
|
||||
# TODO(armax): remove this try catch once the API
|
||||
# add_provider_configuration becomes available
|
||||
LOG.debug('add_provider_configuration API is not available')
|
||||
|
||||
|
||||
class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
|
||||
agent_scheduler.LbaasAgentSchedulerDbMixin):
|
||||
"""Implementation of the Neutron Loadbalancer Service Plugin.
|
||||
|
@ -77,6 +88,8 @@ class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
|
|||
def __init__(self):
|
||||
"""Initialization for the loadbalancer service plugin."""
|
||||
self.service_type_manager = st_db.ServiceTypeManager.get_instance()
|
||||
add_provider_configuration(
|
||||
self.service_type_manager, constants.LOADBALANCER)
|
||||
self._load_drivers()
|
||||
super(LoadBalancerPlugin, self).subscribe()
|
||||
|
||||
|
@ -384,6 +397,8 @@ class LoadBalancerPluginv2(loadbalancerv2.LoadBalancerPluginBaseV2):
|
|||
"""Initialization for the loadbalancer service plugin."""
|
||||
self.db = ldbv2.LoadBalancerPluginDbv2()
|
||||
self.service_type_manager = st_db.ServiceTypeManager.get_instance()
|
||||
add_provider_configuration(
|
||||
self.service_type_manager, constants.LOADBALANCERV2)
|
||||
self._load_drivers()
|
||||
self.db.subscribe()
|
||||
|
||||
|
|
|
@ -14,11 +14,15 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
|
||||
from neutron.db import servicetype_db as st_db
|
||||
from neutron.tests import base as n_base
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
from neutron.tests.unit.extensions import base as ext_base
|
||||
from neutron.tests.unit.extensions import test_quotasv2
|
||||
from neutron.tests.unit import testlib_api
|
||||
from oslo_config import cfg
|
||||
from testtools import matchers
|
||||
|
||||
|
||||
|
@ -29,6 +33,23 @@ class BaseTestCase(n_base.BaseTestCase):
|
|||
class NeutronDbPluginV2TestCase(
|
||||
test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
|
||||
|
||||
def set_override(self, lbaas_provider):
|
||||
# TODO(armax): remove this if branch as soon as the ServiceTypeManager
|
||||
# API for adding provider configurations becomes available
|
||||
if not hasattr(st_db.ServiceTypeManager, 'add_provider_configuration'):
|
||||
cfg.CONF.set_override(
|
||||
'service_provider', lbaas_provider, 'service_providers')
|
||||
else:
|
||||
# override the default service provider
|
||||
self.service_providers = (
|
||||
mock.patch.object(st_db.ServiceTypeManager,
|
||||
'get_service_providers').start())
|
||||
self.service_providers.return_value = (
|
||||
self._to_provider_dicts(lbaas_provider))
|
||||
|
||||
# need to reload provider configuration
|
||||
st_db.ServiceTypeManager._instance = None
|
||||
|
||||
def new_list_request(self, resource, fmt=None, params=None, id=None,
|
||||
subresource=None):
|
||||
return self._req(
|
||||
|
@ -52,6 +73,20 @@ class NeutronDbPluginV2TestCase(
|
|||
context=context, sub_id=sub_id
|
||||
)
|
||||
|
||||
def _to_provider_dicts(self, lbaas_provider):
|
||||
provider_dicts = []
|
||||
for provider in lbaas_provider:
|
||||
bits = provider.split(':')
|
||||
p = {
|
||||
'service_type': bits[0],
|
||||
'name': bits[1],
|
||||
'driver': bits[2]
|
||||
}
|
||||
if len(bits) == 4:
|
||||
p['default'] = True
|
||||
provider_dicts.append(p)
|
||||
return provider_dicts
|
||||
|
||||
def _test_list_with_sort(self, resource,
|
||||
items, sorts, resources=None,
|
||||
query_params='',
|
||||
|
|
|
@ -26,7 +26,6 @@ from neutron import manager
|
|||
from neutron.plugins.common import constants
|
||||
from neutron.services import provider_configuration as pconf
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
from oslo_config import cfg
|
||||
import testtools
|
||||
import webob.exc
|
||||
|
||||
|
@ -311,11 +310,9 @@ class LoadBalancerPluginDbTestCase(LoadBalancerTestMixin,
|
|||
lbaas_provider = (
|
||||
constants.LOADBALANCER +
|
||||
':lbaas:' + NOOP_DRIVER_KLASS + ':default')
|
||||
cfg.CONF.set_override('service_provider',
|
||||
[lbaas_provider],
|
||||
'service_providers')
|
||||
#force service type manager to reload configuration:
|
||||
sdb.ServiceTypeManager._instance = None
|
||||
|
||||
# override the default service provider
|
||||
self.set_override([lbaas_provider])
|
||||
|
||||
# removing service-type because it resides in neutron and tests
|
||||
# dont care
|
||||
|
@ -659,10 +656,9 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
|
|||
':haproxy:neutron_lbaas.services.loadbalancer.'
|
||||
'drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver'
|
||||
':default')
|
||||
cfg.CONF.set_override('service_provider',
|
||||
[prov1, prov2],
|
||||
'service_providers')
|
||||
sdb.ServiceTypeManager._instance = None
|
||||
# override the default service provider
|
||||
self.set_override([prov1, prov2])
|
||||
|
||||
self.plugin = loadbalancer_plugin.LoadBalancerPlugin()
|
||||
with self.subnet() as subnet:
|
||||
ctx = context.get_admin_context()
|
||||
|
@ -1608,12 +1604,11 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
|
|||
qry = ctx.session.query(sdb.ProviderResourceAssociation)
|
||||
self.assertEqual(qry.count(), 2)
|
||||
#removing driver
|
||||
cfg.CONF.set_override('service_provider',
|
||||
[constants.LOADBALANCER +
|
||||
':lbaas1:' + NOOP_DRIVER_KLASS +
|
||||
':default'],
|
||||
'service_providers')
|
||||
sdb.ServiceTypeManager._instance = None
|
||||
self.set_override([
|
||||
constants.LOADBALANCER +
|
||||
':lbaas1:' + NOOP_DRIVER_KLASS +
|
||||
':default'
|
||||
])
|
||||
# calling _remove_orphan... in constructor
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
|
|
|
@ -25,10 +25,8 @@ from neutron.common import constants as n_constants
|
|||
from neutron.common import exceptions as n_exc
|
||||
from neutron import context
|
||||
import neutron.db.l3_db # noqa
|
||||
from neutron.db import servicetype_db as sdb
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import uuidutils
|
||||
import testtools
|
||||
import webob.exc
|
||||
|
@ -308,11 +306,8 @@ class LbaasPluginDbTestCase(LbaasTestMixin, base.NeutronDbPluginV2TestCase):
|
|||
lbaas_provider = (
|
||||
constants.LOADBALANCERV2 +
|
||||
':lbaas:' + NOOP_DRIVER_CLASS + ':default')
|
||||
cfg.CONF.set_override('service_provider',
|
||||
[lbaas_provider],
|
||||
'service_providers')
|
||||
# force service type manager to reload configuration:
|
||||
sdb.ServiceTypeManager._instance = None
|
||||
# override the default service provider
|
||||
self.set_override([lbaas_provider])
|
||||
|
||||
# removing service-type because it resides in neutron and tests
|
||||
# dont care
|
||||
|
|
|
@ -60,19 +60,6 @@ class TestLoadBalancerPluginBase(test_db_loadbalancer
|
|||
.LoadBalancerPluginDbTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLoadBalancerPluginBase, self).setUp(
|
||||
lbaas_provider=LBAAS_PROVIDER)
|
||||
loaded_plugins = manager.NeutronManager().get_service_plugins()
|
||||
self.plugin_instance = loaded_plugins[constants.LOADBALANCER]
|
||||
|
||||
|
||||
class TestNetScalerPluginDriver(TestLoadBalancerPluginBase):
|
||||
|
||||
"""Unit tests for the NetScaler LBaaS driver module."""
|
||||
|
||||
def setUp(self):
|
||||
mock.patch.object(netscaler_driver, 'LOG').start()
|
||||
|
||||
# mock the NSClient class (REST client)
|
||||
client_mock_cls = mock.patch(NCC_CLIENT_CLASS).start()
|
||||
|
||||
|
@ -87,6 +74,19 @@ class TestNetScalerPluginDriver(TestLoadBalancerPluginBase):
|
|||
self.retrieve_resource_mock.side_effect = mock_retrieve_resource_func
|
||||
self.remove_resource_mock = self.client_mock_instance.remove_resource
|
||||
self.remove_resource_mock.side_effect = mock_remove_resource_func
|
||||
super(TestLoadBalancerPluginBase, self).setUp(
|
||||
lbaas_provider=LBAAS_PROVIDER)
|
||||
loaded_plugins = manager.NeutronManager().get_service_plugins()
|
||||
self.plugin_instance = loaded_plugins[constants.LOADBALANCER]
|
||||
|
||||
|
||||
class TestNetScalerPluginDriver(TestLoadBalancerPluginBase):
|
||||
|
||||
"""Unit tests for the NetScaler LBaaS driver module."""
|
||||
|
||||
def setUp(self):
|
||||
mock.patch.object(netscaler_driver, 'LOG').start()
|
||||
|
||||
super(TestNetScalerPluginDriver, self).setUp()
|
||||
self.plugin_instance.drivers[LBAAS_PROVIDER_NAME] = (
|
||||
netscaler_driver.NetScalerPluginDriver(self.plugin_instance))
|
||||
|
|
|
@ -18,7 +18,6 @@ from neutron.api import extensions
|
|||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants
|
||||
from neutron import context
|
||||
from neutron.db import servicetype_db as st_db
|
||||
from neutron.extensions import agent
|
||||
from neutron import manager
|
||||
from neutron.plugins.common import constants as plugin_const
|
||||
|
@ -75,15 +74,9 @@ class LBaaSAgentSchedulerTestCase(test_agent.AgentDBTestMixIn,
|
|||
'lb_plugin_name': test_db_loadbalancer.DB_LB_PLUGIN_KLASS}
|
||||
|
||||
# default provider should support agent scheduling
|
||||
cfg.CONF.set_override(
|
||||
'service_provider',
|
||||
[('LOADBALANCER:lbaas:neutron_lbaas.services.'
|
||||
self.set_override([('LOADBALANCER:lbaas:neutron_lbaas.services.'
|
||||
'loadbalancer.drivers.haproxy.plugin_driver.'
|
||||
'HaproxyOnHostPluginDriver:default')],
|
||||
'service_providers')
|
||||
|
||||
# need to reload provider configuration
|
||||
st_db.ServiceTypeManager._instance = None
|
||||
'HaproxyOnHostPluginDriver:default')])
|
||||
|
||||
super(LBaaSAgentSchedulerTestCase, self).setUp(
|
||||
self.plugin_str, service_plugins=service_plugins)
|
||||
|
|
|
@ -22,7 +22,6 @@ from neutron.api import extensions
|
|||
from neutron.api.v2 import attributes
|
||||
from neutron import context
|
||||
from neutron.db import agents_db
|
||||
from neutron.db import servicetype_db as st_db
|
||||
from neutron.extensions import agent
|
||||
from neutron import manager
|
||||
from neutron.plugins.common import constants as plugin_const
|
||||
|
@ -32,7 +31,6 @@ import neutron.tests.unit.extensions
|
|||
from neutron.tests.unit.extensions import test_agent
|
||||
from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent \
|
||||
import test_agent_scheduler
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
from webob import exc
|
||||
|
||||
|
@ -105,14 +103,9 @@ class LBaaSAgentSchedulerTestCase(test_agent.AgentDBTestMixIn,
|
|||
'lb_plugin_name': test_db_loadbalancerv2.DB_LB_PLUGIN_CLASS}
|
||||
|
||||
# default provider should support agent scheduling
|
||||
cfg.CONF.set_override(
|
||||
'service_provider',
|
||||
self.set_override(
|
||||
[('LOADBALANCERV2:lbaas:neutron_lbaas.drivers.haproxy.'
|
||||
'plugin_driver.HaproxyOnHostPluginDriver:default')],
|
||||
'service_providers')
|
||||
|
||||
# need to reload provider configuration
|
||||
st_db.ServiceTypeManager._instance = None
|
||||
'plugin_driver.HaproxyOnHostPluginDriver:default')])
|
||||
|
||||
super(LBaaSAgentSchedulerTestCase, self).setUp(
|
||||
self.plugin_str, service_plugins=service_plugins)
|
||||
|
|
Loading…
Reference in New Issue