Merge "Rollback volume status if backup service is unavailable"

This commit is contained in:
Zuul 2020-09-24 12:30:56 +00:00 committed by Gerrit Code Review
commit 11feb7c793
3 changed files with 22 additions and 3 deletions

View File

@ -629,13 +629,17 @@ class SchedulerManager(manager.CleanableManager, manager.Manager):
return requested, not_requested
def create_backup(self, context, backup):
volume = self.db.volume_get(context, backup.volume_id)
volume_id = backup.volume_id
volume = self.db.volume_get(context, volume_id)
try:
host = self.driver.get_backup_host(volume)
backup.host = host
backup.save()
self.backup_api.create_backup(context, backup)
except exception.ServiceNotFound:
self.db.volume_update(context, volume_id,
{'status': volume['previous_status'],
'previous_status': volume['status']})
msg = "Service not found for creating backup."
LOG.error(msg)
vol_utils.update_backup_error(backup, msg)

View File

@ -605,9 +605,12 @@ class SchedulerManagerTestCase(test.TestCase):
@mock.patch('cinder.volume.volume_utils.update_backup_error')
@mock.patch('cinder.scheduler.driver.Scheduler.get_backup_host')
@mock.patch('cinder.db.volume_get')
def test_create_backup_no_service(self, mock_volume_get, mock_host,
mock_error):
@mock.patch('cinder.db.volume_update')
def test_create_backup_no_service(self, mock_volume_update,
mock_volume_get, mock_host, mock_error):
volume = fake_volume.fake_db_volume()
volume['status'] = 'backing-up'
volume['previous_status'] = 'available'
mock_volume_get.return_value = volume
mock_host.side_effect = exception.ServiceNotFound(
service_id='cinder-volume')
@ -617,6 +620,11 @@ class SchedulerManagerTestCase(test.TestCase):
mock_host.assert_called_once_with(volume)
mock_volume_get.assert_called_once_with(self.context, backup.volume_id)
mock_volume_update.assert_called_once_with(
self.context,
backup.volume_id,
{'status': 'available',
'previous_status': 'backing-up'})
mock_error.assert_called_once_with(
backup, 'Service not found for creating backup.')

View File

@ -0,0 +1,7 @@
---
fixes:
- |
`Bug #1896087 <https://bugs.launchpad.net/cinder/+bug/1896087>`_:
Volume status will be rolled back to the previous state if backup creation
fails when backup service is not available