Backward compatibility for advanced services

Patch implements translation from class paths to neutron to class paths
to neutron_<adv_service>. It's achieved by defining entry point in
setup.cfg which is translated by stevedore.

There will be needed patches in advanced services tree calling
get_provider_driver_class() function before importing class.

This patch specifically fixes loading service plugins and
drivers for service plugin. Patches for agents are still needed in
neutron repo and adv services repos.

Alternative and better solution would be implementing new DriverType
to oslo.config, which will have callback to
get_provider_driver_class()-like function.

Co-Authored-By: Ihar Hrachyshka <ihrachys@redhat.com>
Change-Id: I76af175c4387326a4e5ff95c2f15d8b866dedab3
Partial-Bug: 1401895
This commit is contained in:
Jakub Libosvar 2014-12-16 17:33:23 +01:00 committed by armando-migliaccio
parent bcb5675d92
commit 21842feeae
13 changed files with 66 additions and 171 deletions

View File

@ -30,6 +30,8 @@ from stevedore import driver
LOG = logging.getLogger(__name__)
CORE_PLUGINS_NAMESPACE = 'neutron.core_plugins'
class Manager(periodic_task.PeriodicTasks):
@ -111,7 +113,7 @@ class NeutronManager(object):
# for performance metrics.
plugin_provider = cfg.CONF.core_plugin
LOG.info(_LI("Loading core plugin: %s"), plugin_provider)
self.plugin = self._get_plugin_instance('neutron.core_plugins',
self.plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE,
plugin_provider)
msg = validate_post_plugin_load()
if msg:

View File

@ -25,6 +25,7 @@ from neutron.i18n import _LE
from neutron.openstack.common import log as logging
from neutron.plugins.common import constants
from neutron.services.firewall.agents import firewall_agent_api as api
from neutron.services import provider_configuration as provconf
LOG = logging.getLogger(__name__)
@ -55,7 +56,8 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin):
def __init__(self, conf):
LOG.debug("Initializing firewall agent")
self.conf = conf
fwaas_driver_class_path = cfg.CONF.fwaas.driver
fwaas_driver_class_path = provconf.get_provider_driver_class(
cfg.CONF.fwaas.driver)
self.fwaas_enabled = cfg.CONF.fwaas.enabled
# None means l3-agent has no information on the server

View File

@ -1,29 +0,0 @@
# Copyright 2014 A10 Networks, Inc
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.i18n import _LE
from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
try:
from neutron_fwaas.services.firewall import fwaas_plugin
except Exception as e:
LOG.error(_LE("Firewall service plugin requires neutron-fwaas module"))
raise e
class FirewallPlugin(fwaas_plugin.FirewallPlugin):
pass

View File

@ -1,29 +0,0 @@
# Copyright 2014 A10 Networks, Inc
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.i18n import _LE
from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
try:
from neutron_lbaas.services.loadbalancer import plugin
except Exception as e:
LOG.error(_LE("Loadbalancer service plugin requires neutron-lbaas module"))
raise e
class LoadBalancerPlugin(plugin.LoadBalancerPlugin):
pass

View File

@ -14,13 +14,16 @@
# under the License.
from oslo.config import cfg
import stevedore
from neutron.common import exceptions as n_exc
from neutron.i18n import _LW
from neutron.openstack.common import log as logging
from neutron.plugins.common import constants
LOG = logging.getLogger(__name__)
SERVICE_PROVIDERS = 'neutron.service_providers'
serviceprovider_opts = [
cfg.MultiStrOpt('service_provider', default=[],
@ -37,6 +40,28 @@ def normalize_provider_name(name):
return name.lower()
def get_provider_driver_class(driver, namespace=SERVICE_PROVIDERS):
"""Return path to provider driver class
In order to keep backward compatibility with configs < Kilo, we need to
translate driver class paths after advanced services split. This is done by
defining old class path as entry point in neutron package.
"""
try:
driver_manager = stevedore.driver.DriverManager(
namespace, driver).driver
except RuntimeError:
return driver
new_driver = "%s.%s" % (driver_manager.__module__,
driver_manager.__name__)
LOG.warning(_LW(
"The configured driver %(driver)s has been moved, automatically "
"using %(new_driver)s instead. Please update your config files, "
"as this automatic fixup will be removed in a future release."),
{'driver': driver, 'new_driver': new_driver})
return new_driver
def parse_service_provider_opt():
"""Parse service definition opts and returns result."""
def validate_name(name):
@ -71,6 +96,7 @@ def parse_service_provider_opt():
'allowed': constants.ALLOWED_SERVICES})
LOG.error(msg)
raise n_exc.Invalid(msg)
driver = get_provider_driver_class(driver)
res.append({'service_type': svc_type,
'name': name,
'driver': driver,

View File

@ -1,29 +0,0 @@
# Copyright 2014 A10 Networks, Inc
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.i18n import _LE
from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
try:
from neutron_vpnaas.services.vpn import plugin
except Exception as e:
LOG.error(_LE("VPN service plugin requires neutron-vpnaas module"))
raise e
class VPNDriverPlugin(plugin.VPNDriverPlugin):
pass

View File

@ -1,26 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.tests import base
class TestPluginShim(base.BaseTestCase):
def test_plugin_shim(self):
try:
from neutron.services.firewall import fwaas_plugin as plugin
plugin.FirewallPlugin()
except ImportError:
pass

View File

@ -1,26 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.tests import base
class TestPluginShim(base.BaseTestCase):
def test_plugin_shim(self):
try:
from neutron.services.loadbalancer import plugin
plugin.LoadBalancerPlugin()
except ImportError:
pass

View File

@ -1,26 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.tests import base
class TestPluginShim(base.BaseTestCase):
def test_plugin_shim(self):
try:
from neutron.services.vpn import plugin
plugin.VPNDriverPlugin()
except ImportError:
pass

View File

@ -15,7 +15,7 @@
from oslo.config import cfg
from neutron.common import exceptions as n_exc
from neutron import manager
from neutron.plugins.common import constants
from neutron.services import provider_configuration as provconf
from neutron.tests import base
@ -197,3 +197,17 @@ class ProviderConfigurationTestCase(base.BaseTestCase):
fields=['name']
)
self.assertEqual(p, [{'name': prov['name']}])
class GetProviderDriverClassTestCase(base.BaseTestCase):
def test_get_provider_driver_class_hit(self):
driver = 'ml2'
expected = 'neutron.plugins.ml2.plugin.Ml2Plugin'
actual = provconf.get_provider_driver_class(
driver,
namespace=manager.CORE_PLUGINS_NAMESPACE)
self.assertEqual(expected, actual)
def test_get_provider_driver_class_miss(self):
retval = provconf.get_provider_driver_class('foo')
self.assertEqual('foo', retval)

View File

@ -144,10 +144,26 @@ neutron.service_plugins =
dummy = neutron.tests.unit.dummy_plugin:DummyServicePlugin
router = neutron.services.l3_router.l3_router_plugin:L3RouterPlugin
bigswitch_l3 = neutron.plugins.bigswitch.l3_router_plugin:L3RestProxy
firewall = neutron.services.firewall.fwaas_plugin:FirewallPlugin
lbaas = neutron.services.loadbalancer.plugin:LoadBalancerPlugin
vpnaas = neutron.services.vpn.plugin:VPNDriverPlugin
firewall = neutron_fwaas.services.firewall.fwaas_plugin:FirewallPlugin
lbaas = neutron_lbaas.services.loadbalancer.plugin:LoadBalancerPlugin
vpnaas = neutron_vpnaas.services.vpn.plugin:VPNDriverPlugin
metering = neutron.services.metering.metering_plugin:MeteringPlugin
neutron.services.firewall.fwaas_plugin.FirewallPlugin = neutron_fwaas.services.firewall.fwaas_plugin:FirewallPlugin
neutron.services.loadbalancer.plugin.LoadBalancerPlugin = neutron_lbaas.services.loadbalancer.plugin:LoadBalancerPlugin
neutron.services.vpn.plugin.VPNDriverPlugin = neutron_vpnaas.services.vpn.plugin:VPNDriverPlugin
neutron.service_providers =
# These are for backwards compat with Juno firewall service provider configuration values
neutron.services.firewall.drivers.linux.iptables_fwaas.IptablesFwaasDriver = neutron_fwaas.services.firewall.drivers.linux.iptables_fwaas:IptablesFwaasDriver
neutron.services.firewall.drivers.varmour.varmour_fwaas.vArmourFwaasDriver = neutron_fwaas.services.firewall.drivers.varmour.varmour_fwaas:vArmourFwaasDriver
# These are for backwards compat with Juno loadbalancer service provider configuration values
neutron.services.loadbalancer.drivers.a10networks.driver_v1.ThunderDriver = neutron_lbaas.services.loadbalancer.drivers.a10networks.driver_v1:ThunderDriver
neutron.services.loadbalancer.drivers.embrane.driver.EmbraneLbaas = neutron_lbaas.services.loadbalancer.drivers.embrane.driver:EmbraneLbaas
neutron.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver = neutron_lbaas.services.loadbalancer.drivers.haproxy.plugin_driver:HaproxyOnHostPluginDriver
neutron.services.loadbalancer.drivers.netscaler.netscaler_driver.NetScalerPluginDriver = neutron_lbaas.services.loadbalancer.drivers.netscaler.netscaler_driver:NetScalerPluginDriver
neutron.services.loadbalancer.drivers.radware.driver.LoadBalancerDriver = neutron_lbaas.services.loadbalancer.drivers.radware.driver:LoadBalancerDriver
# These are for backwards compat with Juno vpnaas service provider configuration values
neutron.services.vpn.service_drivers.cisco_ipsec.CiscoCsrIPsecVPNDriver = neutron_vpnaas.services.vpn.service_drivers.cisco_ipsec:CiscoCsrIPsecVPNDriver
neutron.services.vpn.service_drivers.ipsec.IPsecVPNDriver = neutron_vpnaas.services.vpn.service_drivers.ipsec:IPsecVPNDriver
neutron.ml2.type_drivers =
flat = neutron.plugins.ml2.drivers.type_flat:FlatTypeDriver
local = neutron.plugins.ml2.drivers.type_local:LocalTypeDriver