Merge "Avoid warning log when image not exist"

This commit is contained in:
Zuul 2018-05-11 02:18:14 +00:00 committed by Gerrit Code Review
commit c52b645b64
2 changed files with 15 additions and 1 deletions

View File

@ -3362,6 +3362,8 @@ class ComputeManager(manager.Manager):
image = self.image_api.get(context, image_id)
if image['status'] != 'active':
self.image_api.delete(context, image_id)
except exception.ImageNotFound:
LOG.debug('Image not found during clean up %s', image_id)
except Exception:
LOG.warning("Error while trying to clean up image %s",
image_id, instance=instance)

View File

@ -3511,10 +3511,13 @@ class ComputeTestCase(BaseTestCase,
def test_snapshot_fails_cleanup_ignores_exception(self):
self._test_snapshot_fails(True, 'snapshot')
def _test_snapshot_deletes_image_on_failure(self, status, exc):
def _test_snapshot_deletes_image_on_failure(self, status, exc,
image_not_exist=False):
self.fake_image_delete_called = False
def fake_show(self_, context, image_id, **kwargs):
if image_not_exist:
raise exception.ImageNotFound(image_id=uuids.snapshot)
self.assertEqual(uuids.snapshot, image_id)
image = {'id': image_id,
'status': status}
@ -3569,6 +3572,15 @@ class ComputeTestCase(BaseTestCase,
'active', instance_not_found)
self.assertFalse(self.fake_image_delete_called)
@mock.patch.object(compute_manager.LOG, 'warning')
def test_snapshot_fails_with_instance_not_found_and_image_not_found(self,
mock_warning):
instance_not_found = exception.InstanceNotFound(instance_id='uuid')
self._test_snapshot_deletes_image_on_failure(
'active', instance_not_found, image_not_exist=True)
self.assertFalse(self.fake_image_delete_called)
mock_warning.assert_not_called()
def test_snapshot_handles_cases_when_instance_is_deleted(self):
inst_obj = self._get_snapshotting_instance()
inst_obj.task_state = task_states.DELETING