Merge "Avoid raise InstanceNotRunning exception"

This commit is contained in:
Zuul 2019-11-22 21:48:40 +00:00 committed by Gerrit Code Review
commit d4c11ae67d
2 changed files with 46 additions and 4 deletions

View File

@ -3876,6 +3876,7 @@ class ComputeManager(manager.Manager):
self.host, phase=fields.NotificationPhase.END,
snapshot_image_id=image_id)
except (exception.InstanceNotFound,
exception.InstanceNotRunning,
exception.UnexpectedDeletingTaskStateError):
# the instance got deleted during the snapshot
# Quickly bail out of here
@ -3902,15 +3903,25 @@ class ComputeManager(manager.Manager):
@wrap_exception()
def volume_snapshot_create(self, context, instance, volume_id,
create_info):
self.driver.volume_snapshot_create(context, instance, volume_id,
create_info)
try:
self.driver.volume_snapshot_create(context, instance, volume_id,
create_info)
except exception.InstanceNotRunning:
# Libvirt driver can raise this exception
LOG.debug('Instance disappeared during volume snapshot create',
instance=instance)
@messaging.expected_exceptions(NotImplementedError)
@wrap_exception()
def volume_snapshot_delete(self, context, instance, volume_id,
snapshot_id, delete_info):
self.driver.volume_snapshot_delete(context, instance, volume_id,
snapshot_id, delete_info)
try:
self.driver.volume_snapshot_delete(context, instance, volume_id,
snapshot_id, delete_info)
except exception.InstanceNotRunning:
# Libvirt driver can raise this exception
LOG.debug('Instance disappeared during volume snapshot delete',
instance=instance)
@wrap_instance_fault
def _rotate_backups(self, context, instance, backup_type, rotation):

View File

@ -1355,6 +1355,17 @@ class ComputeVolumeTestCase(BaseTestCase):
self.compute.volume_snapshot_create, self.context,
self.instance_object, 'fake_id', {})
@mock.patch.object(compute_manager.LOG, 'debug')
def test_volume_snapshot_create_instance_not_running(self, mock_debug):
with mock.patch.object(self.compute.driver,
'volume_snapshot_create') as mock_create:
exc = exception.InstanceNotRunning(instance_id=uuids.instance)
mock_create.side_effect = exc
self.compute.volume_snapshot_create(self.context,
self.instance_object, uuids.volume, {})
mock_debug.assert_called_once_with('Instance disappeared during '
'volume snapshot create', instance=self.instance_object)
def test_volume_snapshot_delete(self):
self.assertRaises(messaging.ExpectedException,
self.compute.volume_snapshot_delete, self.context,
@ -1366,6 +1377,17 @@ class ComputeVolumeTestCase(BaseTestCase):
self.compute.volume_snapshot_delete, self.context,
self.instance_object, uuids.volume, uuids.snapshot, {})
@mock.patch.object(compute_manager.LOG, 'debug')
def test_volume_snapshot_delete_instance_not_running(self, mock_debug):
with mock.patch.object(self.compute.driver,
'volume_snapshot_delete') as mock_delete:
exc = exception.InstanceNotRunning(instance_id=uuids.instance)
mock_delete.side_effect = exc
self.compute.volume_snapshot_delete(self.context,
self.instance_object, uuids.volume, uuids.snapshot, {})
mock_debug.assert_called_once_with('Instance disappeared during '
'volume snapshot delete', instance=self.instance_object)
@mock.patch.object(cinder.API, 'create',
side_effect=exception.OverQuota(overs='something'))
def test_prep_block_device_over_quota_failure(self, mock_create):
@ -3519,6 +3541,15 @@ class ComputeTestCase(BaseTestCase,
self.assertFalse(self.fake_image_delete_called)
mock_warning.assert_not_called()
def test_snapshot_fails_with_instance_not_running(self):
instance_not_running = exception.InstanceNotRunning(instance_id='uuid')
self._test_snapshot_deletes_image_on_failure(
'error', instance_not_running)
self.assertTrue(self.fake_image_delete_called)
self._test_snapshot_deletes_image_on_failure(
'active', instance_not_running)
self.assertFalse(self.fake_image_delete_called)
def test_snapshot_handles_cases_when_instance_is_deleted(self):
inst_obj = self._get_snapshotting_instance()
inst_obj.task_state = task_states.DELETING