Skip to content

Commit

Permalink
Set backup status to error on VolumeNotFound
Browse files Browse the repository at this point in the history
When creating a backup and it fails we will try
to update the status on the volume but if it does
not exist we will instead fail on that and the
backup will be stuck in creating status which means
cloud admin need to help resetting the status.

This catches the VolumeNotFound exception and ignores
updating the volume status and thus backup will be
set to error and can be deleted by user instead.

Closes-Bug: #1996049
Change-Id: Iafa92ece7f83323af257c1702df5029469b11739
(cherry picked from commit 813df9b)
  • Loading branch information
tobias-urdin committed Jul 21, 2023
1 parent 0d562ba commit 5f35750
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cinder/backup/manager.py
Expand Up @@ -416,10 +416,15 @@ def create_backup(self, context, backup):
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):
Expand Down
20 changes: 20 additions & 0 deletions cinder/tests/unit/backup/test_backup.py
Expand Up @@ -673,6 +673,26 @@ def my_start_backup(*args, **kwargs):
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):
Expand Down
@@ -0,0 +1,5 @@
---
fixes:
- |
`Bug #1996049 <https://bugs.launchpad.net/cinder/+bug/1996049>`_: Fixed bug
where backup was not set to error on failure when volume did not exist.

0 comments on commit 5f35750

Please sign in to comment.