]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Check specific driver enabled in create_backup
authorfelix23ma <felix23ma@gmail.com>
Sat, 14 Nov 2015 01:35:24 +0000 (09:35 +0800)
committerfelix23ma <felix23ma@gmail.com>
Tue, 17 Nov 2015 01:43:38 +0000 (09:43 +0800)
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
cinder/tests/unit/test_backup.py

index ca238583a6f98b938c96a0e3aaf954166c0b78a4..9ddf0a7542c13f7f7c0b7e954e2292c581f93975 100644 (file)
@@ -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,
index 6de7d0130bff6f36a46e66ce1ac9620b0f8a11ad..56ab5e6aa69b944be59f8f38e7f7fe56718358a1 100644 (file)
@@ -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.