]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix cleanup_temp_volume_snapshots for missing vol
authorTom Barron <tpb@dyncloud.net>
Sat, 25 Jul 2015 21:11:29 +0000 (17:11 -0400)
committerTom Barron <tpb@dyncloud.net>
Mon, 27 Jul 2015 16:06:59 +0000 (16:06 +0000)
The cleanup_temp_volume_snapshots method raises an exception that
causes the backup service to exit if there is a backup without a
corresponding volume.

This commit catches these exceptions so that the backup service is
not prevented from starting in this circumstance.

Change-Id: Ia1aac2fe78048df5fce595d5de181cb4930ea78d
Closes-bug: 1478599

cinder/backup/manager.py
cinder/tests/unit/test_backup.py

index f0a90f7b29141e56bfcd99f99649669b9422e7c7..8b6514da4ec491d6a52b2d5c8c0b389dc7ae68b6 100644 (file)
@@ -265,10 +265,16 @@ class BackupManager(manager.SchedulerDependentManager):
         # create by the backup job are deleted when service is started.
         ctxt = context.get_admin_context()
         for backup in backups:
-            volume = self.db.volume_get(ctxt, backup.volume_id)
-            volume_host = volume_utils.extract_host(volume['host'], 'backend')
-            backend = self._get_volume_backend(host=volume_host)
-            mgr = self._get_manager(backend)
+            try:
+                volume = self.db.volume_get(ctxt, backup.volume_id)
+                volume_host = volume_utils.extract_host(volume['host'],
+                                                        'backend')
+                backend = self._get_volume_backend(host=volume_host)
+                mgr = self._get_manager(backend)
+            except (KeyError, exception.VolumeNotFound):
+                LOG.debug("Could not find a volume to clean up for "
+                          "backup %s.", backup.id)
+                continue
             if backup.temp_volume_id and backup.status == 'error':
                 temp_volume = self.db.volume_get(ctxt,
                                                  backup.temp_volume_id)
index 836d5dd56aa97c6ea956b56f5b95da3fc3179b85..1c48e7bc8fee5457433af2d7d0fb3d122dac0ddd 100644 (file)
@@ -17,6 +17,7 @@ Tests for Backup code.
 
 """
 
+import ddt
 import tempfile
 
 import mock
@@ -170,6 +171,7 @@ class BaseBackupTest(test.TestCase):
         return backup
 
 
+@ddt.ddt
 class BackupTestCase(BaseBackupTest):
     """Test Case for backups."""
 
@@ -227,6 +229,20 @@ class BackupTestCase(BaseBackupTest):
         self.assertTrue(mock_delete_volume.called)
         self.assertTrue(mock_delete_snapshot.called)
 
+    @mock.patch.object(db, 'volume_get')
+    @ddt.data(KeyError, exception.VolumeNotFound)
+    def test_cleanup_temp_volumes_snapshots(self,
+                                            err,
+                                            mock_volume_get):
+        """Ensure we handle missing volume for a backup."""
+        mock_volume_get.side_effect = [err]
+
+        backup1 = self._create_backup_db_entry(status='creating')
+        backups = [backup1]
+
+        self.assertIsNone(self.backup_mgr._cleanup_temp_volumes_snapshots(
+            backups))
+
     def test_create_backup_with_bad_volume_status(self):
         """Test creating a backup from a volume with a bad status."""
         vol_id = self._create_volume_db_entry(status='restoring', size=1)