diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index 741f0f450d..fa462d038f 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -107,6 +107,8 @@ class ImagesController(object): except exception.Forbidden as e: LOG.debug("User not permitted to create image import task.") raise webob.exc.HTTPForbidden(explanation=e.msg) + except exception.Conflict as e: + raise webob.exc.HTTPConflict(explanation=e.msg) return image_id diff --git a/glance/async/flows/api_image_import.py b/glance/async/flows/api_image_import.py index 91b753f914..44b12d56d4 100644 --- a/glance/async/flows/api_image_import.py +++ b/glance/async/flows/api_image_import.py @@ -194,7 +194,7 @@ class _ImportToStore(task.Task): # implementation image = self.image_repo.get(self.image_id) image.status = 'importing' - self.image_repo.save(image) + self.image_repo.save(image, from_state='uploading') # NOTE(flaper87): Let's dance... and fall # diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index 60fdfd2218..bb53bc8ab9 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -14,6 +14,7 @@ # under the License. import datetime +import eventlet import uuid import glance_store as store @@ -599,6 +600,18 @@ class TestImagesController(base.IsolatedUnitTest): self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, request, UUID4) + def test_image_import_raises_conflict(self): + request = unit_test_utils.get_fake_request() + # NOTE(abhishekk): Due to + # https://bugs.launchpad.net/glance/+bug/1712463 taskflow is not + # executing. Once it is fixed instead of mocking spawn_n method + # we should mock execute method of _ImportToStore task. + with mock.patch.object(eventlet.GreenPool, 'spawn_n', + side_effect=exception.Conflict): + self.assertRaises(webob.exc.HTTPConflict, + self.controller.import_image, request, UUID4, + {}) + def test_create(self): request = unit_test_utils.get_fake_request() image = {'name': 'image-1'}