From 4734d2ab278750bda69f0b45d8d88c856ea5a3be Mon Sep 17 00:00:00 2001 From: Anusha Ramineni Date: Mon, 12 Feb 2018 18:07:58 +0530 Subject: [PATCH] Add disable_drivers config option This commit adds the new option 'disabled_drivers' config option to support disabling of specific drivers if not needed. Usage: disabled_drivers = plexxi, murano Partially-Implements blueprint enable-drivers-by-default Change-Id: I008d095d70cd0718f614332bc92b57178e1d3aaa --- congress/common/config.py | 4 ++++ congress/dse2/dse_node.py | 3 ++- congress/exception.py | 3 ++- congress/tests/api/test_driver_model.py | 23 +++++++++++------------ congress/tests/dse2/test_datasource.py | 11 ++++------- devstack/plugin.sh | 21 --------------------- 6 files changed, 23 insertions(+), 42 deletions(-) diff --git a/congress/common/config.py b/congress/common/config.py index 5bf62fceb..8b84b41f1 100644 --- a/congress/common/config.py +++ b/congress/common/config.py @@ -55,6 +55,10 @@ core_opts = [ deprecated_for_removal=True, deprecated_reason='automatically loads all configured drivers', help=_('List of driver class paths to import.')), + cfg.ListOpt('disabled_drivers', + default=[], + help=_('List of driver names to be disabled. For example, ' + 'disabled_drivers=nova, plexxi')), cfg.IntOpt('datasource_sync_period', default=60, help='The number of seconds to wait between synchronizing ' 'datasource config from the database'), diff --git a/congress/dse2/dse_node.py b/congress/dse2/dse_node.py index e10c7ac67..588423255 100644 --- a/congress/dse2/dse_node.py +++ b/congress/dse2/dse_node.py @@ -514,7 +514,8 @@ class DseNode(object): invoke_on_load=False) for driver in mgr: - result[driver.name] = driver + if driver.name not in cfg.CONF.disabled_drivers: + result[driver.name] = driver cls.loaded_drivers = result diff --git a/congress/exception.py b/congress/exception.py index 3311293d1..1278da752 100644 --- a/congress/exception.py +++ b/congress/exception.py @@ -235,7 +235,8 @@ class DatasourceNotFound(NotFound): class DriverNotFound(NotFound): - msg_fmt = _("Driver not found %(id)s") + msg_fmt = _("Driver not found %(id)s. Either not supported or disabled by " + "deployer in Congress config") class DatasourceCreationError(BadConfig): diff --git a/congress/tests/api/test_driver_model.py b/congress/tests/api/test_driver_model.py index d9501d8a1..97a4e0bf9 100644 --- a/congress/tests/api/test_driver_model.py +++ b/congress/tests/api/test_driver_model.py @@ -17,6 +17,8 @@ from __future__ import print_function from __future__ import division from __future__ import absolute_import +from oslo_config import cfg + from congress.api import webservice from congress.tests.api import base as api_base from congress.tests import base @@ -28,20 +30,8 @@ class TestDriverModel(base.SqlTestCase): super(TestDriverModel, self).setUp() services = api_base.setup_config() self.node = services['node'] - self.ds_manager = services['ds_manager'] - - self.ds_manager.add_datasource(self._get_datasource_request()) self.driver_model = services['api']['api-system'] - def _get_datasource_request(self): - req = {'driver': 'fake_datasource', - 'name': 'fake_datasource'} - req['config'] = {'auth_url': 'foo', - 'username': 'foo', - 'password': 'password', - 'tenant_name': 'foo'} - return req - def tearDown(self): super(TestDriverModel, self).tearDown() @@ -53,6 +43,15 @@ class TestDriverModel(base.SqlTestCase): actual_ret = sorted(ret, key=lambda d: d['id']) self.assertEqual(expected_ret, actual_ret) + def test_drivers_list_with_disabled_drivers(self): + cfg.CONF.set_override('disabled_drivers', 'plexxi') + services = api_base.setup_config(node_id='test-node-1') + driver_api = services['api']['api-system'] + drivers = [d['id'] for d in helper.supported_drivers()] + drivers.remove('plexxi') + ret = [d['id'] for d in driver_api.get_items({}, {})['results']] + self.assertEqual(sorted(drivers), sorted(ret)) + def test_driver_details(self): context = { "driver_id": "fake_datasource" diff --git a/congress/tests/dse2/test_datasource.py b/congress/tests/dse2/test_datasource.py index 654ac82eb..f9146deb8 100644 --- a/congress/tests/dse2/test_datasource.py +++ b/congress/tests/dse2/test_datasource.py @@ -186,10 +186,7 @@ class TestDataSource(base.SqlTestCase): self.assertRaises(congressException.DatasourceNotFound, self.ds_manager.delete_datasource, req) - # TODO(dse2): Doesn't seem like we need this (or it will be moved to API). - # def test_get_driver_schema(self): - # schema = self.datasource_mgr.get_driver_schema( - # 'fake_datasource') - # self.assertEqual( - # schema, - # fake_datasource.FakeDataSource.get_schema()) + def test_get_driver_schema(self): + schema = self.dseNode.get_driver_schema('fake_datasource') + self.assertEqual(schema, + fake_datasource.FakeDataSource.get_schema()) diff --git a/devstack/plugin.sh b/devstack/plugin.sh index a67eb589e..226ca9b73 100755 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -60,27 +60,6 @@ function configure_congress { iniset $CONGRESS_CONF DEFAULT datasource_sync_period 30 iniset $CONGRESS_CONF DEFAULT replicated_policy_engine "$CONGRESS_REPLICATED" iniset $CONGRESS_CONF DEFAULT transport_url rabbit://$RABBIT_USERID:$RABBIT_PASSWORD@$RABBIT_HOST:5672 - - CONGRESS_DRIVERS="congress.datasources.neutronv2_driver.NeutronV2Driver," - CONGRESS_DRIVERS+="congress.datasources.neutronv2_qos_driver.NeutronV2QosDriver," - CONGRESS_DRIVERS+="congress.datasources.glancev2_driver.GlanceV2Driver," - CONGRESS_DRIVERS+="congress.datasources.nova_driver.NovaDriver," - CONGRESS_DRIVERS+="congress.datasources.keystonev3_driver.KeystoneV3Driver," - CONGRESS_DRIVERS+="congress.datasources.cinder_driver.CinderDriver," - CONGRESS_DRIVERS+="congress.datasources.swift_driver.SwiftDriver," - CONGRESS_DRIVERS+="congress.datasources.plexxi_driver.PlexxiDriver," - CONGRESS_DRIVERS+="congress.datasources.vCenter_driver.VCenterDriver," - CONGRESS_DRIVERS+="congress.datasources.murano_driver.MuranoDriver," - CONGRESS_DRIVERS+="congress.datasources.ironic_driver.IronicDriver," - CONGRESS_DRIVERS+="congress.datasources.heatv1_driver.HeatV1Driver," - CONGRESS_DRIVERS+="congress.datasources.doctor_driver.DoctorDriver," - CONGRESS_DRIVERS+="congress.datasources.aodh_driver.AodhDriver," - CONGRESS_DRIVERS+="congress.datasources.cfgvalidator_driver.ValidatorDriver," - CONGRESS_DRIVERS+="congress.datasources.mistral_driver.MistralDriver," - CONGRESS_DRIVERS+="congress.tests.fake_datasource.FakeDataSource" - - iniset $CONGRESS_CONF DEFAULT drivers $CONGRESS_DRIVERS - iniset $CONGRESS_CONF database connection `database_connection_url $CONGRESS_DB_NAME` _congress_setup_keystone $CONGRESS_CONF keystone_authtoken