From b93d0b723b63e4aa43ef8a70cc54954a391d5e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulko?= Date: Wed, 9 Nov 2016 11:32:43 +0100 Subject: [PATCH] Make BackupManager not a SchedulerDependentManager BackupManager isn't really reporting anything to scheduler and is inheriting from SchedulerDependentManager only because it uses _add_to_threadpool method. This commit extracts this method into new ThreadPoolManager class and makes BackupManager to inherit it. Change-Id: I79e4c5e05571b6b52fed8885fe280a3d9d8726ea --- cinder/backup/manager.py | 7 +++---- cinder/manager.py | 17 +++++++++++------ cinder/tests/unit/backup/test_backup.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index 6b6eb8026c6..e7be5b8b25d 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -78,14 +78,14 @@ CONF.import_opt('num_volume_device_scan_tries', 'cinder.volume.driver') QUOTAS = quota.QUOTAS -class BackupManager(manager.SchedulerDependentManager): +class BackupManager(manager.ThreadPoolManager): """Manages backup of block storage devices.""" RPC_API_VERSION = backup_rpcapi.BackupAPI.RPC_API_VERSION target = messaging.Target(version=RPC_API_VERSION) - def __init__(self, service_name=None, *args, **kwargs): + def __init__(self, *args, **kwargs): self.service = importutils.import_module(self.driver_name) self.az = CONF.storage_availability_zone self.volume_managers = {} @@ -99,8 +99,7 @@ class BackupManager(manager.SchedulerDependentManager): self._setup_volume_drivers() self.backup_rpcapi = backup_rpcapi.BackupAPI() self.volume_rpcapi = volume_rpcapi.VolumeAPI() - super(BackupManager, self).__init__(service_name='backup', - *args, **kwargs) + super(BackupManager, self).__init__(*args, **kwargs) def _get_volume_backend(self, host=None, allow_null_host=False): if host is None: diff --git a/cinder/manager.py b/cinder/manager.py index 7beb9f873eb..1ada2568b18 100644 --- a/cinder/manager.py +++ b/cinder/manager.py @@ -85,7 +85,7 @@ class Manager(base.Base, PeriodicTasks): target = messaging.Target(version=RPC_API_VERSION) - def __init__(self, host=None, db_driver=None, cluster=None): + def __init__(self, host=None, db_driver=None, cluster=None, **kwargs): if not host: host = CONF.host self.host = host @@ -145,7 +145,16 @@ class Manager(base.Base, PeriodicTasks): rpc.LAST_RPC_VERSIONS = {} -class SchedulerDependentManager(Manager): +class ThreadPoolManager(Manager): + def __init__(self, *args, **kwargs): + self._tp = greenpool.GreenPool() + super(ThreadPoolManager, self).__init__(*args, **kwargs) + + def _add_to_threadpool(self, func, *args, **kwargs): + self._tp.spawn_n(func, *args, **kwargs) + + +class SchedulerDependentManager(ThreadPoolManager): """Periodically send capability updates to the Scheduler services. Services that need to update the Scheduler of their capabilities @@ -160,7 +169,6 @@ class SchedulerDependentManager(Manager): self.last_capabilities = None self.service_name = service_name self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() - self._tp = greenpool.GreenPool() super(SchedulerDependentManager, self).__init__(host, db_driver, cluster=cluster) @@ -194,9 +202,6 @@ class SchedulerDependentManager(Manager): "during a live upgrade. Error: %(e)s") LOG.warning(msg, {'host': self.host, 'e': e}) - def _add_to_threadpool(self, func, *args, **kwargs): - self._tp.spawn_n(func, *args, **kwargs) - def reset(self): super(SchedulerDependentManager, self).reset() self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI() diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index b6e72ae7fe5..49eedf4c787 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -291,7 +291,7 @@ class BackupTestCase(BaseBackupTest): self.assertTrue(self.volume_mocks['detach_volume'].called) @mock.patch('cinder.objects.backup.BackupList.get_all_by_host') - @mock.patch('cinder.manager.SchedulerDependentManager._add_to_threadpool') + @mock.patch('cinder.manager.ThreadPoolManager._add_to_threadpool') def test_init_host_with_service_inithost_offload(self, mock_add_threadpool, mock_get_all_by_host):