]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Separate Configuration from Freescale SDN ML2 mechanism Driver
authorTrinath Somanchi <trinath.somanchi@freescale.com>
Wed, 17 Sep 2014 07:22:14 +0000 (12:52 +0530)
committerTrinath Somanchi <trinath.somanchi@freescale.com>
Wed, 17 Sep 2014 07:26:21 +0000 (12:56 +0530)
- In the current implementation, CRD configuration is existing
  within the code of ML2 mechanism driver.

- When any other plugin/driver (like, Freescale FWaaS Plugin) need
  to use this configuration, it needs to duplicate the complete configuration.

- So the CRD configuration is moved to a separate file for use
  in other plugin/drivers.

- Unit testing of this MD is also updated.

Closes-Bug: #1368033

Change-Id: I488fee47803a494aae9df42f9c59fffa9843e727

neutron/plugins/ml2/drivers/freescale/README.fslsdn [moved from neutron/plugins/ml2/drivers/README.fslsdn with 100% similarity]
neutron/plugins/ml2/drivers/freescale/__init__.py [new file with mode: 0644]
neutron/plugins/ml2/drivers/freescale/config.py [new file with mode: 0644]
neutron/plugins/ml2/drivers/freescale/mechanism_fslsdn.py [moved from neutron/plugins/ml2/drivers/mechanism_fslsdn.py with 78% similarity]
neutron/tests/unit/ml2/drivers/freescale/__init__.py [new file with mode: 0644]
neutron/tests/unit/ml2/drivers/freescale/test_mechanism_fslsdn.py [moved from neutron/tests/unit/ml2/test_mechanism_fslsdn.py with 92% similarity]
setup.cfg

diff --git a/neutron/plugins/ml2/drivers/freescale/__init__.py b/neutron/plugins/ml2/drivers/freescale/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/neutron/plugins/ml2/drivers/freescale/config.py b/neutron/plugins/ml2/drivers/freescale/config.py
new file mode 100644 (file)
index 0000000..7739dc1
--- /dev/null
@@ -0,0 +1,85 @@
+# Copyright (c) 2014 Freescale Semiconductor
+#
+# 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 neutronclient.v2_0 import client
+from oslo.config import cfg
+
+""" Freescale CRD Server Configuration used by ML2 Mechanism Driver.
+
+The following configuration is used by Freescale Drivers/Plugin
+like, FWaaS Plugin, VPNaaS Plugin etc.. which connect to Cloud Resource
+Discovery Service (CRD).
+"""
+
+# CRD service options required for FSL SDN OS Mech Driver
+ml2_fslsdn_opts = [
+    cfg.StrOpt('crd_user_name', default='crd',
+               help=_("CRD service Username.")),
+    cfg.StrOpt('crd_password', default='password',
+               secret=True,
+               help=_("CRD Service Password.")),
+    cfg.StrOpt('crd_tenant_name', default='service',
+               help=_("CRD Tenant Name.")),
+    cfg.StrOpt('crd_auth_url',
+               default='http://127.0.0.1:5000/v2.0/',
+               help=_("CRD Auth URL.")),
+    cfg.StrOpt('crd_url',
+               default='http://127.0.0.1:9797',
+               help=_("URL for connecting to CRD service.")),
+    cfg.IntOpt('crd_url_timeout',
+               default=30,
+               help=_("Timeout value for connecting to "
+                      "CRD service in seconds.")),
+    cfg.StrOpt('crd_region_name',
+               default='RegionOne',
+               help=_("Region name for connecting to "
+                      "CRD Service in admin context.")),
+    cfg.BoolOpt('crd_api_insecure',
+                default=False,
+                help=_("If set, ignore any SSL validation issues.")),
+    cfg.StrOpt('crd_auth_strategy',
+               default='keystone',
+               help=_("Auth strategy for connecting to "
+                      "neutron in admin context.")),
+    cfg.StrOpt('crd_ca_certificates_file',
+               help=_("Location of ca certificates file to use for "
+                      "CRD client requests.")),
+]
+
+# Register the configuration option for crd service
+cfg.CONF.register_opts(ml2_fslsdn_opts, "ml2_fslsdn")
+
+# shortcut
+FSLCONF = cfg.CONF.ml2_fslsdn
+
+SERVICE_TYPE = 'crd'
+
+
+def get_crdclient():
+    """ Using the CRD configuration, get and return CRD Client instance."""
+    crd_client_params = {
+        'username': FSLCONF.crd_user_name,
+        'tenant_name': FSLCONF.crd_tenant_name,
+        'region_name': FSLCONF.crd_region_name,
+        'password': FSLCONF.crd_password,
+        'auth_url': FSLCONF.crd_auth_url,
+        'auth_strategy': FSLCONF.crd_auth_strategy,
+        'endpoint_url': FSLCONF.crd_url,
+        'timeout': FSLCONF.crd_url_timeout,
+        'insecure': FSLCONF.crd_api_insecure,
+        'service_type': SERVICE_TYPE,
+        'ca_cert': FSLCONF.crd_ca_certificates_file,
+    }
+    return client.Client(**crd_client_params)
similarity index 78%
rename from neutron/plugins/ml2/drivers/mechanism_fslsdn.py
rename to neutron/plugins/ml2/drivers/freescale/mechanism_fslsdn.py
index 381ea955114a914259278ed9715dd21d1070b220..282965c8c8ff3c56a0437bd383219b3fa6751491 100755 (executable)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from neutronclient.v2_0 import client
-from oslo.config import cfg
-
 from neutron.common import constants as n_const
 from neutron.common import log
 from neutron.extensions import portbindings
 from neutron.openstack.common import log as logging
 from neutron.plugins.common import constants
 from neutron.plugins.ml2 import driver_api as api
+from neutron.plugins.ml2.drivers.freescale import config  # noqa
 
 
 LOG = logging.getLogger(__name__)
 
-# CRD service options required for FSL SDN OS Mech Driver
-ml2_fslsdn_opts = [
-    cfg.StrOpt('crd_user_name', default='crd',
-               help=_("CRD service Username")),
-    cfg.StrOpt('crd_password', default='password',
-               secret='True',
-               help=_("CRD Service Password")),
-    cfg.StrOpt('crd_tenant_name', default='service',
-               help=_("CRD Tenant Name")),
-    cfg.StrOpt('crd_auth_url',
-               default='http://127.0.0.1:5000/v2.0/',
-               help=_("CRD Auth URL")),
-    cfg.StrOpt('crd_url',
-               default='http://127.0.0.1:9797',
-               help=_("URL for connecting to CRD service")),
-    cfg.IntOpt('crd_url_timeout',
-               default=30,
-               help=_("Timeout value for connecting to "
-                      "CRD service in seconds")),
-    cfg.StrOpt('crd_region_name',
-               default='RegionOne',
-               help=_("Region name for connecting to "
-                      "CRD Service in admin context")),
-    cfg.BoolOpt('crd_api_insecure',
-                default=False,
-                help=_("If set, ignore any SSL validation issues")),
-    cfg.StrOpt('crd_auth_strategy',
-               default='keystone',
-               help=_("Auth strategy for connecting to "
-                      "neutron in admin context")),
-    cfg.StrOpt('crd_ca_certificates_file',
-               help=_("Location of ca certificates file to use for "
-                      "CRD client requests.")),
-]
-
-# Register the configuration option for crd service
-# required for FSL SDN OS Mechanism driver
-cfg.CONF.register_opts(ml2_fslsdn_opts, "ml2_fslsdn")
-
-# shortcut
-FSLCONF = cfg.CONF.ml2_fslsdn
-
-SERVICE_TYPE = 'crd'
-
 
 class FslsdnMechanismDriver(api.MechanismDriver):
 
@@ -82,20 +36,7 @@ class FslsdnMechanismDriver(api.MechanismDriver):
         self.vif_type = portbindings.VIF_TYPE_OVS
         self.vif_details = {portbindings.CAP_PORT_FILTER: True}
         LOG.info(_("Initializing CRD client... "))
-        crd_client_params = {
-            'username': FSLCONF.crd_user_name,
-            'tenant_name': FSLCONF.crd_tenant_name,
-            'region_name': FSLCONF.crd_region_name,
-            'password': FSLCONF.crd_password,
-            'auth_url': FSLCONF.crd_auth_url,
-            'auth_strategy': FSLCONF.crd_auth_strategy,
-            'endpoint_url': FSLCONF.crd_url,
-            'timeout': FSLCONF.crd_url_timeout,
-            'insecure': FSLCONF.crd_api_insecure,
-            'service_type': SERVICE_TYPE,
-            'ca_cert': FSLCONF.crd_ca_certificates_file,
-        }
-        self._crdclient = client.Client(**crd_client_params)
+        self._crdclient = config.get_crdclient()
 
     # Network Management
     @staticmethod
diff --git a/neutron/tests/unit/ml2/drivers/freescale/__init__.py b/neutron/tests/unit/ml2/drivers/freescale/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
similarity index 92%
rename from neutron/tests/unit/ml2/test_mechanism_fslsdn.py
rename to neutron/tests/unit/ml2/drivers/freescale/test_mechanism_fslsdn.py
index 244f7e0299c87e7b79068bd8dc4e3c4048dc72da..c5c10737509f666da19d59a7983f696e4e8b5c5c 100644 (file)
@@ -17,7 +17,7 @@ import mock
 from oslo.config import cfg
 
 from neutron.extensions import portbindings
-from neutron.plugins.ml2.drivers import mechanism_fslsdn
+from neutron.plugins.ml2.drivers.freescale import mechanism_fslsdn
 from neutron.tests import base
 from neutron.tests.unit import test_db_plugin
 
@@ -25,32 +25,16 @@ from neutron.tests.unit import test_db_plugin
 """Unit testing for Freescale SDN mechanism driver."""
 
 
-def setup_driver_config():
-    """Mechanism Driver specific configuration."""
-
-    # Configure mechanism driver as 'fslsdn'
-    cfg.CONF.set_override('mechanism_drivers', ['fslsdn'], 'ml2')
-    # Configure FSL SDN Mechanism driver specific options
-    cfg.CONF.set_override('crd_user_name', 'crd', 'ml2_fslsdn')
-    cfg.CONF.set_override('crd_password', 'CRD_PASS', 'ml2_fslsdn')
-    cfg.CONF.set_override('crd_tenant_name', 'service', 'ml2_fslsdn')
-    cfg.CONF.set_override('crd_auth_url',
-                          'http://127.0.0.1:5000/v2.0', 'ml2_fslsdn')
-    cfg.CONF.set_override('crd_url',
-                          'http://127.0.0.1:9797', 'ml2_fslsdn')
-    cfg.CONF.set_override('crd_auth_strategy', 'keystone', 'ml2_fslsdn')
-
-
 class TestFslSdnMechDriverV2(test_db_plugin.NeutronDbPluginV2TestCase):
 
     """Testing mechanism driver with ML2 plugin."""
 
     def setUp(self):
-        setup_driver_config()
+        cfg.CONF.set_override('mechanism_drivers', ['fslsdn'], 'ml2')
 
         def mocked_fslsdn_init(self):
             # Mock CRD client, since it requires CRD service running.
-            self._crdclieint = mock.Mock()
+            self._crdclient = mock.Mock()
 
         with mock.patch.object(mechanism_fslsdn.FslsdnMechanismDriver,
                                'initialize', new=mocked_fslsdn_init):
@@ -79,7 +63,7 @@ class TestFslSdnMechanismDriver(base.BaseTestCase):
 
     def setUp(self):
         super(TestFslSdnMechanismDriver, self).setUp()
-        setup_driver_config()
+        cfg.CONF.set_override('mechanism_drivers', ['fslsdn'], 'ml2')
         self.driver = mechanism_fslsdn.FslsdnMechanismDriver()
         self.driver.initialize()
         self.client = self.driver._crdclient = mock.Mock()
index ff037f75a0f3f95bcf44f152f50686e6cf6486a4..4f0697c80e79b289831042434ed45addfd6f4a95 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -176,7 +176,7 @@ neutron.ml2.mechanism_drivers =
     ofagent = neutron.plugins.ml2.drivers.mech_ofagent:OfagentMechanismDriver
     mlnx = neutron.plugins.ml2.drivers.mlnx.mech_mlnx:MlnxMechanismDriver
     brocade = neutron.plugins.ml2.drivers.brocade.mechanism_brocade:BrocadeMechanism
-    fslsdn = neutron.plugins.ml2.drivers.mechanism_fslsdn:FslsdnMechanismDriver
+    fslsdn = neutron.plugins.ml2.drivers.freescale.mechanism_fslsdn:FslsdnMechanismDriver
     sriovnicswitch = neutron.plugins.ml2.drivers.mech_sriov.mech_driver:SriovNicSwitchMechanismDriver
     nuage = neutron.plugins.ml2.drivers.mech_nuage.driver:NuageMechanismDriver
 neutron.ml2.extension_drivers =