Separate Configuration from Freescale SDN ML2 mechanism Driver

- 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
This commit is contained in:
Trinath Somanchi 2014-09-17 12:52:14 +05:30
parent c214e6bce5
commit 485c174fc7
7 changed files with 92 additions and 82 deletions

View File

@ -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)

View File

@ -13,63 +13,17 @@
# 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

View 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()

View File

@ -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 =