Set backup status to error on VolumeNotFound
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 813df9b99f)
This commit is contained in:
@@ -416,10 +416,15 @@ class BackupManager(manager.SchedulerDependentManager):
|
||||
snapshot.status = fields.SnapshotStatus.AVAILABLE
|
||||
snapshot.save()
|
||||
else:
|
||||
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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user