]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Backward compatibility for advanced services
authorJakub Libosvar <libosvar@redhat.com>
Tue, 16 Dec 2014 16:33:23 +0000 (17:33 +0100)
committerarmando-migliaccio <armamig@gmail.com>
Thu, 18 Dec 2014 17:27:28 +0000 (09:27 -0800)
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

13 files changed:
neutron/manager.py
neutron/services/firewall/agents/l3reference/firewall_l3_agent.py
neutron/services/firewall/fwaas_plugin.py [deleted file]
neutron/services/loadbalancer/plugin.py [deleted file]
neutron/services/provider_configuration.py
neutron/services/vpn/plugin.py [deleted file]
neutron/tests/unit/services/firewall/test_plugin_shim.py [deleted file]
neutron/tests/unit/services/loadbalancer/__init__.py [deleted file]
neutron/tests/unit/services/loadbalancer/test_plugin_shim.py [deleted file]
neutron/tests/unit/services/vpn/__init__.py [deleted file]
neutron/tests/unit/services/vpn/test_plugin_shim.py [deleted file]
neutron/tests/unit/test_provider_configuration.py
setup.cfg

index b3829fa9c03c83b36069e066871225f6142ebc5d..8cd25ad6af18b4c6c67f1785f31f4e3362333a23 100644 (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:
index b4b80c05e3a81e7ef9ca0624b0a07c957ea0ff23..831fca6d31db34a10264f8337d586671dd9c591a 100644 (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
diff --git a/neutron/services/firewall/fwaas_plugin.py b/neutron/services/firewall/fwaas_plugin.py
deleted file mode 100644 (file)
index 3129458..0000000
+++ /dev/null
@@ -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
diff --git a/neutron/services/loadbalancer/plugin.py b/neutron/services/loadbalancer/plugin.py
deleted file mode 100644 (file)
index 831a6ff..0000000
+++ /dev/null
@@ -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
index b9dd8f626e25675eba2240a04c66c272e3702e6f..841954b018eb63f731bfa47cf7861b89b9608e13 100644 (file)
 #    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,
diff --git a/neutron/services/vpn/plugin.py b/neutron/services/vpn/plugin.py
deleted file mode 100644 (file)
index 17f3473..0000000
+++ /dev/null
@@ -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
diff --git a/neutron/tests/unit/services/firewall/test_plugin_shim.py b/neutron/tests/unit/services/firewall/test_plugin_shim.py
deleted file mode 100644 (file)
index 8a1fa1c..0000000
+++ /dev/null
@@ -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
diff --git a/neutron/tests/unit/services/loadbalancer/__init__.py b/neutron/tests/unit/services/loadbalancer/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/neutron/tests/unit/services/loadbalancer/test_plugin_shim.py b/neutron/tests/unit/services/loadbalancer/test_plugin_shim.py
deleted file mode 100644 (file)
index be3d405..0000000
+++ /dev/null
@@ -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
diff --git a/neutron/tests/unit/services/vpn/__init__.py b/neutron/tests/unit/services/vpn/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/neutron/tests/unit/services/vpn/test_plugin_shim.py b/neutron/tests/unit/services/vpn/test_plugin_shim.py
deleted file mode 100644 (file)
index 4fe18be..0000000
+++ /dev/null
@@ -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
index 60eeccca4f516bc1ed86acd67e138673574b4b2d..8a6378a06a3e31099ba9aeb0b5d142d2dc1d2473 100644 (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)
index 2feb253afbacb56d977d527ddde409d0608d46e7..330a136881acaa6f96b4042070a8e0874df92870 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -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