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 633bec8fd4
)
This commit is contained in:
parent
e58013c2c0
commit
3cdd0aaa67
|
@ -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
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in New Issue