diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index 92d482434f3..ec17e4bdcc7 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -416,10 +416,15 @@ class BackupManager(manager.SchedulerDependentManager): snapshot.status = fields.SnapshotStatus.AVAILABLE snapshot.save() else: - self.db.volume_update( - context, volume_id, - {'status': previous_status, - 'previous_status': 'error_backing-up'}) + try: + self.db.volume_update( + context, volume_id, + {'status': previous_status, + 'previous_status': 'error_backing-up'}) + except exception.VolumeNotFound: + # If the volume was deleted we cannot update its + # status but we still want to set the backup to error. + pass volume_utils.update_backup_error(backup, str(err)) def _start_backup(self, context, backup, volume): diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index eca450637fb..d63271e73f0 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -673,6 +673,26 @@ class BackupTestCase(BaseBackupTest): backup.refresh() self.assertEqual(fields.BackupStatus.DELETED, backup.status) + @mock.patch('cinder.backup.manager.BackupManager._start_backup', + side_effect=FakeBackupException(str(uuid.uuid4()))) + @mock.patch.object(db, 'volume_update') + def test_create_backup_aborted_volume_not_found(self, vol_up_mock, + start_backup_mock): + """Test error handling when backup fails and volume does not exist.""" + vol_id = self._create_volume_db_entry(size=1) + backup = self._create_backup_db_entry(volume_id=vol_id) + + vol_up_mock.side_effect = exception.VolumeNotFound(volume_id=vol_id) + + self.assertRaises(FakeBackupException, + self.backup_mgr.create_backup, + self.ctxt, + backup) + backup.refresh() + self.assertEqual(fields.BackupStatus.ERROR, backup.status) + self.assertTrue(start_backup_mock.called) + self.assertTrue(vol_up_mock.called) + @mock.patch('cinder.backup.manager.BackupManager._start_backup', side_effect=FakeBackupException(str(uuid.uuid4()))) def test_create_backup_with_snapshot_error(self, mock_start_backup): diff --git a/releasenotes/notes/backup-volumenotfound-set-to-error-fa47b3631093a702.yaml b/releasenotes/notes/backup-volumenotfound-set-to-error-fa47b3631093a702.yaml new file mode 100644 index 00000000000..6a84d372930 --- /dev/null +++ b/releasenotes/notes/backup-volumenotfound-set-to-error-fa47b3631093a702.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + `Bug #1996049 `_: Fixed bug + where backup was not set to error on failure when volume did not exist.