summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitagrawal <ankit11.agrawal@nttdata.com>2014-10-10 05:31:46 -0700
committerAbhishek Kekane <abhishek.kekane@nttdata.com>2014-10-22 05:40:20 +0000
commit3cdd0aaa67400fcf6f04323c4697ebed1966c65f (patch)
tree0fc865ebfe13a383071d43b5794b654ac258e774
parente58013c2c0b6f0ffe57c2a70bd0b73f419f20bc9 (diff)
downloadglance-3cdd0aaa67400fcf6f04323c4697ebed1966c65f.tar.gz
Improve error log for expired image location url
If image is not present at the specified location while creating instance from image, then HTTPInternalServerError 500 response along with stack trace is logged on nova compute which does not help user to understand the exact cause of failure. Return HTTPNotFound error to the nova compute in case of image url got expired or image is not present at the given location to give clear indication of the cause of failure to user. Closes-Bug: #1198566 Change-Id: I9acd9112aeae8d3b3c0c3921f306e716e5808c2e (cherry picked from commit 633bec8fd45897735e1fcb9844903fe597903b21)
-rw-r--r--glance/api/v2/image_data.py2
-rw-r--r--glance/tests/unit/v2/test_image_data_resource.py19
2 files changed, 21 insertions, 0 deletions
diff --git a/glance/api/v2/image_data.py b/glance/api/v2/image_data.py
index dc38ffcea..430ffc53e 100644
--- a/glance/api/v2/image_data.py
+++ b/glance/api/v2/image_data.py
@@ -214,6 +214,8 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
# an iterator very strange
response.app_iter = iter(image.get_data(offset=offset,
chunk_size=chunk_size))
+ except glance_store.NotFound as e:
+ raise webob.exc.HTTPNotFound(explanation=e.msg)
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=e.msg)
#NOTE(saschpe): "response.app_iter = ..." currently resets Content-MD5
diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py
index a055ab0f7..cc8148a81 100644
--- a/glance/tests/unit/v2/test_image_data_resource.py
+++ b/glance/tests/unit/v2/test_image_data_resource.py
@@ -471,6 +471,25 @@ class TestImageDataSerializer(test_utils.BaseTestCase):
self.serializer.download,
response, image)
+ def test_download_not_found(self):
+ """Test image download returns HTTPNotFound.
+
+ Make sure that serializer returns 404 not found error in case of
+ image is not available at specified location.
+ """
+ with mock.patch.object(glance.api.policy.ImageProxy,
+ 'get_data') as mock_get_data:
+ mock_get_data.side_effect = glance_store.NotFound()
+
+ request = wsgi.Request.blank('/')
+ response = webob.Response()
+ response.request = request
+ image = FakeImage(size=3, data=iter('ZZZ'))
+ image.get_data = mock_get_data
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.serializer.download,
+ response, image)
+
def test_upload(self):
request = webob.Request.blank('/')
request.environ = {}