Merge "Fix 500 from duplicate stage call"

This commit is contained in:
Zuul 2017-12-11 14:35:51 +00:00 committed by Gerrit Code Review
commit be3f156b6c
2 changed files with 20 additions and 0 deletions

View File

@ -341,6 +341,11 @@ class ImageDataController(object):
raise webob.exc.HTTPServiceUnavailable(explanation=msg,
request=req)
except exception.InvalidImageStatusTransition as e:
msg = encodeutils.exception_to_unicode(e)
LOG.debug(msg)
raise webob.exc.HTTPConflict(explanation=e.msg, request=req)
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("Failed to stage image data due to "

View File

@ -491,6 +491,21 @@ class TestImagesController(base.StoreClearingUnitTest):
self.controller.stage,
request, image_id, 'YYYYYYY', 7)
@mock.patch.object(filesystem.Store, 'add')
def test_image_stage_invalid_image_transition(self, mock_store_add):
image_id = str(uuid.uuid4())
request = unit_test_utils.get_fake_request()
image = FakeImage(image_id=image_id)
self.image_repo.result = image
self.controller.stage(request, image_id, 'YYYY', 4)
self.assertEqual('uploading', image.status)
self.assertEqual(0, image.size)
# try staging again
mock_store_add.side_effect = exception.InvalidImageStatusTransition(
cur_status='uploading', new_status='uploading')
self.assertRaises(webob.exc.HTTPConflict, self.controller.stage,
request, image_id, 'YYYY', 4)
class TestImageDataDeserializer(test_utils.BaseTestCase):