From 390ddb7ea9ca7e736a17f1ff516aee5e11961feb Mon Sep 17 00:00:00 2001 From: felix23ma Date: Sat, 14 Nov 2015 09:35:24 +0800 Subject: [PATCH] Check specific driver enabled in create_backup MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Backend is already known so don’t need to use the default backend name to check if the driver is initialized. Change-Id: I797c75ca0eff574e3eb20dfedc8d5b64ca06a06a Closes-Bug: #1515900 --- cinder/backup/manager.py | 4 +-- cinder/tests/unit/test_backup.py | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index ca238583a..9ddf0a754 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -386,7 +386,7 @@ class BackupManager(manager.SchedulerDependentManager): # before going forward. The exception will be caught, # the volume status will be set back to available and # the backup status to 'error' - utils.require_driver_initialized(self.driver) + utils.require_driver_initialized(self._get_driver(backend)) backup_service = self.service.get_backup_driver(context) self._get_driver(backend).backup_volume(context, backup, @@ -481,7 +481,7 @@ class BackupManager(manager.SchedulerDependentManager): # before going forward. The exception will be caught, # the volume status will be set back to available and # the backup status to 'error' - utils.require_driver_initialized(self.driver) + utils.require_driver_initialized(self._get_driver(backend)) backup_service = self.service.get_backup_driver(context) self._get_driver(backend).restore_backup(context, backup, diff --git a/cinder/tests/unit/test_backup.py b/cinder/tests/unit/test_backup.py index 6de7d0130..56ab5e6aa 100644 --- a/cinder/tests/unit/test_backup.py +++ b/cinder/tests/unit/test_backup.py @@ -531,6 +531,27 @@ class BackupTestCase(BaseBackupTest): self.backup_mgr.create_backup(self.ctxt, backup) self.assertEqual(2, notify.call_count) + def test_require_driver_initialized_in_create_backup(self): + """Test backup creation. + + Test require_driver_initialized with _get_driver + in a normal backup creation. + """ + vol_size = 1 + vol_id = self._create_volume_db_entry(size=vol_size) + backup = self._create_backup_db_entry(volume_id=vol_id) + + self.backup_mgr._get_driver = mock.MagicMock() + self.backup_mgr._get_volume_backend = mock.MagicMock() + self.backup_mgr._get_volume_backend.return_value = 'mybackend' + + self.backup_mgr.create_backup(self.ctxt, backup) + self.assertEqual(2, self.backup_mgr._get_driver.call_count) + self.assertEqual(self.backup_mgr._get_driver.call_args_list[0], + mock.call('mybackend')) + self.assertEqual(self.backup_mgr._get_driver.call_args_list[1], + mock.call('mybackend')) + def test_restore_backup_with_bad_volume_status(self): """Test error handling. @@ -639,6 +660,29 @@ class BackupTestCase(BaseBackupTest): self.backup_mgr.restore_backup(self.ctxt, backup, vol_id) self.assertEqual(2, notify.call_count) + def test_require_driver_initialized_in_restore_backup(self): + """Test backup restoration. + + Test require_driver_initialized with _get_driver + in a normal backup restoration. + """ + vol_size = 1 + vol_id = self._create_volume_db_entry(status='restoring-backup', + size=vol_size) + backup = self._create_backup_db_entry(status='restoring', + volume_id=vol_id) + + self.backup_mgr._get_driver = mock.MagicMock() + self.backup_mgr._get_volume_backend = mock.MagicMock() + self.backup_mgr._get_volume_backend.return_value = 'mybackend' + + self.backup_mgr.restore_backup(self.ctxt, backup, vol_id) + self.assertEqual(2, self.backup_mgr._get_driver.call_count) + self.assertEqual(self.backup_mgr._get_driver.call_args_list[0], + mock.call('mybackend')) + self.assertEqual(self.backup_mgr._get_driver.call_args_list[1], + mock.call('mybackend')) + def test_delete_backup_with_bad_backup_status(self): """Test error handling. -- 2.45.2