From 8353d6e204ea0b3162bc484ad87cce4c80e14c6c Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 13 Jul 2021 12:04:56 +0100 Subject: [PATCH] db: Remove 'db_driver' option This is a silly config option. We only have one database driver in-tree and no plans to add more (SQLAlchemy is best in class). There's also no way we'd be able to support out-of-tree drivers. Remove it entirely. Change-Id: Ica3b2e8fcb079beca652e81d2230bcca82fb49d7 Signed-off-by: Stephen Finucane --- cinder/backup/api.py | 3 ++- cinder/backup/driver.py | 10 ++++--- cinder/db/base.py | 26 +++--------------- cinder/group/api.py | 4 +-- cinder/manager.py | 27 +++++++++++-------- cinder/opts.py | 2 -- cinder/tests/unit/test_image_utils.py | 5 ++-- cinder/tests/unit/test_service.py | 7 ++--- .../volume/drivers/ibm/test_storwize_svc.py | 15 ++++------- .../drivers/inspur/instorage/test_common.py | 11 +++----- .../inspur/instorage/test_fc_driver.py | 5 ++-- .../inspur/instorage/test_iscsi_driver.py | 5 ++-- .../inspur/instorage/test_replication.py | 6 ++--- .../unit/volume/drivers/toyou/test_acs5000.py | 8 +++--- cinder/tests/unit/volume/test_image.py | 2 +- cinder/transfer/api.py | 4 +-- cinder/volume/api.py | 4 +-- .../drop-db_driver-opt-b644963bf3b6aced.yaml | 7 +++++ 18 files changed, 64 insertions(+), 87 deletions(-) create mode 100644 releasenotes/notes/drop-db_driver-opt-b644963bf3b6aced.yaml diff --git a/cinder/backup/api.py b/cinder/backup/api.py index 7e03348af97..ca9a3270b31 100644 --- a/cinder/backup/api.py +++ b/cinder/backup/api.py @@ -59,11 +59,12 @@ IMPORT_VOLUME_ID = '00000000-0000-0000-0000-000000000000' class API(base.Base): """API for interacting with the volume backup manager.""" + # TODO(stephenfin): The 'db' kwarg is unused; remove it def __init__(self, db=None): self.backup_rpcapi = backup_rpcapi.BackupAPI() self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() self.volume_api = cinder.volume.API() - super(API, self).__init__(db) + super(API, self).__init__() def get(self, context, backup_id): backup = objects.Backup.get_by_id(context, backup_id) diff --git a/cinder/backup/driver.py b/cinder/backup/driver.py index 621695cecd3..6c1f8a020f6 100644 --- a/cinder/backup/driver.py +++ b/cinder/backup/driver.py @@ -52,8 +52,9 @@ class BackupMetadataAPI(base.Base): TYPE_TAG_VOL_META = 'volume-metadata' TYPE_TAG_VOL_GLANCE_META = 'volume-glance-metadata' - def __init__(self, context, db=None): - super(BackupMetadataAPI, self).__init__(db) + # TODO(stephenfin): The 'db' kwarg is unused; remove it + def __init__(self, context): + super().__init__() self.context = context self._key_mgr = None @@ -347,10 +348,11 @@ class BackupMetadataAPI(base.Base): class BackupDriver(base.Base, metaclass=abc.ABCMeta): + # TODO(stephenfin): The 'db' kwarg is unused; remove it def __init__(self, context, db=None): - super(BackupDriver, self).__init__(db) + super().__init__() self.context = context - self.backup_meta_api = BackupMetadataAPI(context, db) + self.backup_meta_api = BackupMetadataAPI(context) # This flag indicates if backup driver supports force # deletion. So it should be set to True if the driver that inherits # from BackupDriver supports the force deletion function. diff --git a/cinder/db/base.py b/cinder/db/base.py index 28afabc0ad7..9ee9bde408c 100644 --- a/cinder/db/base.py +++ b/cinder/db/base.py @@ -16,32 +16,14 @@ """Base class for classes that need modular database access.""" - -from oslo_config import cfg -from oslo_utils import importutils - - -db_driver_opt = cfg.StrOpt('db_driver', - default='cinder.db', - help='Driver to use for database access') - -CONF = cfg.CONF -CONF.register_opt(db_driver_opt) +import cinder.db class Base(object): """DB driver is injected in the init method.""" - def __init__(self, db_driver=None): - # NOTE(mriedem): Without this call, multiple inheritance involving - # the db Base class does not work correctly. - super(Base, self).__init__() - if not db_driver: - db_driver = CONF.db_driver + def __init__(self): + super().__init__() - # pylint: disable=C0103 - if isinstance(db_driver, str): - self.db = importutils.import_module(db_driver) - else: - self.db = db_driver + self.db = cinder.db self.db.dispose_engine() diff --git a/cinder/group/api.py b/cinder/group/api.py index 29c138e2f34..f23b52f693d 100644 --- a/cinder/group/api.py +++ b/cinder/group/api.py @@ -60,12 +60,12 @@ VALID_ADD_VOL_TO_GROUP_STATUS = ( class API(base.Base): """API for interacting with the volume manager for groups.""" - def __init__(self, db_driver=None): + def __init__(self): self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() self.volume_rpcapi = volume_rpcapi.VolumeAPI() self.volume_api = volume_api.API() - super(API, self).__init__(db_driver) + super().__init__() def _extract_availability_zone(self, availability_zone): raw_zones = self.volume_api.list_availability_zones(enable_cache=True) diff --git a/cinder/manager.py b/cinder/manager.py index 15c4c17276c..3789cf53a1b 100644 --- a/cinder/manager.py +++ b/cinder/manager.py @@ -84,18 +84,19 @@ class Manager(base.Base, PeriodicTasks): target = messaging.Target(version=RPC_API_VERSION) - def __init__(self, - host: oslo_config.types.HostAddress = None, - db_driver=None, - cluster=None, - **_kwargs): + def __init__( + self, + host: oslo_config.types.HostAddress = None, + cluster=None, + **_kwargs, + ): if not host: host = CONF.host self.host: oslo_config.types.HostAddress = host self.cluster = cluster self.additional_endpoints: list = [] self.availability_zone = CONF.storage_availability_zone - super(Manager, self).__init__(db_driver) # type: ignore + super().__init__() # type: ignore def _set_tpool_size(self, nthreads: int) -> None: # NOTE(geguileo): Until PR #472 is merged we have to be very careful @@ -178,14 +179,18 @@ class SchedulerDependentManager(ThreadPoolManager): """ - def __init__(self, host=None, db_driver=None, service_name='undefined', - cluster=None, *args, **kwargs): + def __init__( + self, + host=None, + service_name='undefined', + cluster=None, + *args, + **kwargs, + ): self.last_capabilities = None self.service_name = service_name self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() - super(SchedulerDependentManager, self).__init__(host, db_driver, - cluster=cluster, - *args, **kwargs) + super().__init__(host, cluster=cluster, *args, **kwargs) def update_service_capabilities(self, capabilities): """Remember these capabilities to send on next periodic update.""" diff --git a/cinder/opts.py b/cinder/opts.py index f0274559fd4..f77add8ce51 100644 --- a/cinder/opts.py +++ b/cinder/opts.py @@ -49,7 +49,6 @@ from cinder.compute import nova as cinder_compute_nova from cinder import context as cinder_context from cinder import coordination as cinder_coordination from cinder.db import api as cinder_db_api -from cinder.db import base as cinder_db_base from cinder.image import glance as cinder_image_glance from cinder.image import image_utils as cinder_image_imageutils from cinder.keymgr import conf_key_mgr as cinder_keymgr_confkeymgr @@ -242,7 +241,6 @@ def list_opts(): cinder_context.context_opts, cinder_db_api.db_opts, cinder_db_api.backup_opts, - [cinder_db_base.db_driver_opt], cinder_image_glance.image_opts, cinder_image_glance.glance_core_properties_opts, cinder_image_imageutils.image_opts, diff --git a/cinder/tests/unit/test_image_utils.py b/cinder/tests/unit/test_image_utils.py index 13c7648575a..5bbe895be25 100644 --- a/cinder/tests/unit/test_image_utils.py +++ b/cinder/tests/unit/test_image_utils.py @@ -1090,7 +1090,7 @@ class TestFetchToRaw(test.TestCase): class FakeImageService(object): - def __init__(self, db_driver=None, image_service=None, disk_format='raw'): + def __init__(self, image_service=None, disk_format='raw'): self.temp_images = None self.disk_format = disk_format @@ -1818,8 +1818,7 @@ class TestFetchToVolumeFormat(test.TestCase): pass class FakeImageService(object): - def __init__(self, db_driver=None, - image_service=None, disk_format='raw'): + def __init__(self, image_service=None, disk_format='raw'): self.temp_images = None self.disk_format = disk_format diff --git a/cinder/tests/unit/test_service.py b/cinder/tests/unit/test_service.py index fb131d1522c..1baef758aff 100644 --- a/cinder/tests/unit/test_service.py +++ b/cinder/tests/unit/test_service.py @@ -52,11 +52,8 @@ CONF.register_opts(test_service_opts) class FakeManager(manager.Manager): """Fake manager for tests.""" - def __init__(self, host=None, - db_driver=None, service_name=None, cluster=None): - super(FakeManager, self).__init__(host=host, - db_driver=db_driver, - cluster=cluster) + def __init__(self, host=None, service_name=None, cluster=None): + super().__init__(host=host, cluster=cluster) def test_method(self): return 'manager' diff --git a/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py b/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py index a51b4b20bcb..53f64af8911 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py @@ -26,12 +26,12 @@ import ddt from oslo_concurrency import processutils from oslo_config import cfg from oslo_service import loopingcall -from oslo_utils import importutils from oslo_utils import units import paramiko import six from cinder import context +import cinder.db from cinder import exception from cinder.i18n import _ from cinder import objects @@ -3119,8 +3119,7 @@ class StorwizeSVCISCSIDriverTestCase(test.TestCase): self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = CONF.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.iscsi_driver.db = self.db self.iscsi_driver.do_setup(None) self.iscsi_driver.check_for_setup_error() @@ -3758,8 +3757,7 @@ class StorwizeSVCFcDriverTestCase(test.TestCase): self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = self.fc_driver.configuration.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.fc_driver.db = self.db self.fc_driver.do_setup(None) self.fc_driver.check_for_setup_error() @@ -4593,8 +4591,7 @@ class StorwizeSVCCommonDriverTestCase(test.TestCase): else: self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = CONF.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.driver.db = self.db self.driver.do_setup(None) self.driver.check_for_setup_error() @@ -9873,10 +9870,8 @@ class StorwizeSVCReplicationTestCase(test.TestCase): self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = self.driver.configuration.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.driver.db = self.db - self.driver.do_setup(None) self.driver.check_for_setup_error() self._create_test_volume_types() diff --git a/cinder/tests/unit/volume/drivers/inspur/instorage/test_common.py b/cinder/tests/unit/volume/drivers/inspur/instorage/test_common.py index da50f856f9b..af91d2f0ce1 100644 --- a/cinder/tests/unit/volume/drivers/inspur/instorage/test_common.py +++ b/cinder/tests/unit/volume/drivers/inspur/instorage/test_common.py @@ -21,11 +21,11 @@ import ddt from eventlet import greenthread from oslo_concurrency import processutils from oslo_config import cfg -from oslo_utils import importutils from oslo_utils import units import paramiko from cinder import context +from cinder import db from cinder import exception from cinder import objects from cinder.objects import fields @@ -77,9 +77,7 @@ class InStorageMCSCommonDriverTestCase(test.TestCase): self.ctxt = context.get_admin_context() self.ctxt = context.get_admin_context() - db_driver = CONF.db_driver - self.db = importutils.import_module(db_driver) - self.driver.db = self.db + self.driver.db = db self.driver.do_setup(None) self.driver.check_for_setup_error() self.driver._assistant.check_lcmapping_interval = 0 @@ -319,7 +317,7 @@ class InStorageMCSCommonDriverTestCase(test.TestCase): def _delete_volume(self, volume): self.driver.delete_volume(volume) - self.db.volume_destroy(self.ctxt, volume['id']) + db.volume_destroy(self.ctxt, volume['id']) def _create_group_in_db(self, **kwargs): group = testutils.create_group(self.ctxt, **kwargs) @@ -340,8 +338,7 @@ class InStorageMCSCommonDriverTestCase(test.TestCase): **kwargs) snapshots = [] grp_id = group_snapshot['group_id'] - volumes = self.db.volume_get_all_by_group(self.ctxt.elevated(), - grp_id) + volumes = db.volume_get_all_by_group(self.ctxt.elevated(), grp_id) if not volumes: msg = "Group is empty. No group snapshot will be created." diff --git a/cinder/tests/unit/volume/drivers/inspur/instorage/test_fc_driver.py b/cinder/tests/unit/volume/drivers/inspur/instorage/test_fc_driver.py index 0d901e52f33..4f472cccf94 100644 --- a/cinder/tests/unit/volume/drivers/inspur/instorage/test_fc_driver.py +++ b/cinder/tests/unit/volume/drivers/inspur/instorage/test_fc_driver.py @@ -18,9 +18,9 @@ from unittest import mock from eventlet import greenthread -from oslo_utils import importutils from cinder import context +import cinder.db from cinder import exception from cinder.tests.unit import test from cinder.tests.unit import utils as testutils @@ -58,8 +58,7 @@ class InStorageMCSFcDriverTestCase(test.TestCase): self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = self.fc_driver.configuration.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.fc_driver.db = self.db self.fc_driver.do_setup(None) self.fc_driver.check_for_setup_error() diff --git a/cinder/tests/unit/volume/drivers/inspur/instorage/test_iscsi_driver.py b/cinder/tests/unit/volume/drivers/inspur/instorage/test_iscsi_driver.py index 66f517ac6f7..42bcda1cfb6 100644 --- a/cinder/tests/unit/volume/drivers/inspur/instorage/test_iscsi_driver.py +++ b/cinder/tests/unit/volume/drivers/inspur/instorage/test_iscsi_driver.py @@ -18,10 +18,10 @@ from unittest import mock from eventlet import greenthread -from oslo_utils import importutils import six from cinder import context +import cinder.db from cinder import exception from cinder.tests.unit import test from cinder.tests.unit import utils as testutils @@ -57,8 +57,7 @@ class InStorageMCSISCSIDriverTestCase(test.TestCase): self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = self.iscsi_driver.configuration.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.iscsi_driver.db = self.db self.iscsi_driver.do_setup(None) self.iscsi_driver.check_for_setup_error() diff --git a/cinder/tests/unit/volume/drivers/inspur/instorage/test_replication.py b/cinder/tests/unit/volume/drivers/inspur/instorage/test_replication.py index 1c6addce046..091426a7ad8 100644 --- a/cinder/tests/unit/volume/drivers/inspur/instorage/test_replication.py +++ b/cinder/tests/unit/volume/drivers/inspur/instorage/test_replication.py @@ -19,10 +19,10 @@ import json from unittest import mock from eventlet import greenthread -from oslo_utils import importutils from oslo_utils import units from cinder import context +import cinder.db from cinder import exception from cinder.objects import fields from cinder.tests.unit import fake_constants as fake @@ -86,9 +86,7 @@ class InStorageMCSReplicationTestCase(test.TestCase): self._reset_flags() self.ctxt = context.get_admin_context() - db_driver = self.driver.configuration.db_driver - self.db = importutils.import_module(db_driver) - self.driver.db = self.db + self.driver.db = cinder.db self.driver.do_setup(None) self.driver.check_for_setup_error() diff --git a/cinder/tests/unit/volume/drivers/toyou/test_acs5000.py b/cinder/tests/unit/volume/drivers/toyou/test_acs5000.py index 33da8bfdcc2..e2efb3d64ce 100644 --- a/cinder/tests/unit/volume/drivers/toyou/test_acs5000.py +++ b/cinder/tests/unit/volume/drivers/toyou/test_acs5000.py @@ -27,11 +27,11 @@ from eventlet import greenthread from oslo_concurrency import processutils from oslo_config import cfg from oslo_utils import excutils -from oslo_utils import importutils from oslo_utils import units import paramiko from cinder import context +import cinder.db from cinder import exception from cinder import ssh_utils from cinder.tests.unit import test @@ -675,8 +675,7 @@ class Acs5000ISCSIDriverTestCase(test.TestCase): self.iscsi_driver.set_fake_storage(self.sim) self.ctxt = context.get_admin_context() - db_driver = CONF.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self.iscsi_driver.db = self.db self.iscsi_driver.get_driver_options() self.iscsi_driver.do_setup(None) @@ -835,8 +834,7 @@ class Acs5000CommonDriverTestCase(test.TestCase): self._driver.set_fake_storage(self.sim) self.ctxt = context.get_admin_context() - db_driver = CONF.db_driver - self.db = importutils.import_module(db_driver) + self.db = cinder.db self._driver.db = self.db self._driver.do_setup(None) self._driver.check_for_setup_error() diff --git a/cinder/tests/unit/volume/test_image.py b/cinder/tests/unit/volume/test_image.py index 8c8b3796047..4d33b096315 100644 --- a/cinder/tests/unit/volume/test_image.py +++ b/cinder/tests/unit/volume/test_image.py @@ -43,7 +43,7 @@ NON_EXISTENT_IMAGE_ID = '003f540f-ec6b-4293-a3f9-7c68646b0f5c' class FakeImageService(object): - def __init__(self, db_driver=None, image_service=None): + def __init__(self, image_service=None): pass def show(self, context, image_id): diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index 1df17f8c07b..116bed9a685 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -56,9 +56,9 @@ QUOTAS = quota.QUOTAS class API(base.Base): """API for interacting volume transfers.""" - def __init__(self, db_driver=None): + def __init__(self): self.volume_api = volume_api.API() - super(API, self).__init__(db_driver) + super().__init__() def get(self, context, transfer_id): context.authorize(policy.GET_POLICY) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index ae2142756d3..12ef4974bcc 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -102,7 +102,7 @@ class API(base.Base): AVAILABLE_MIGRATION_STATUS = (None, 'deleting', 'error', 'success') - def __init__(self, db_driver=None, image_service=None): + def __init__(self, image_service=None): self.image_service = (image_service or glance.get_default_image_service()) self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() @@ -111,7 +111,7 @@ class API(base.Base): self.availability_zones_last_fetched = None self.key_manager = key_manager.API(CONF) self.message = message_api.API() - super(API, self).__init__(db_driver) + super().__init__() def list_availability_zones(self, enable_cache=False, refresh_cache=False): """Describe the known availability zones diff --git a/releasenotes/notes/drop-db_driver-opt-b644963bf3b6aced.yaml b/releasenotes/notes/drop-db_driver-opt-b644963bf3b6aced.yaml new file mode 100644 index 00000000000..9b72aff98ef --- /dev/null +++ b/releasenotes/notes/drop-db_driver-opt-b644963bf3b6aced.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + The ``[DEFAULT] db_driver`` config option has been removed. This was + intended to allow configuration of the database driver, however, there + is only one database driver present in-tree and out-of-tree database + drivers are not supported.