Add capabilities to storage driver

This patch is work for glance, and the main change on glance_store side
is change Iedf0d4f829e46ca64c3f4fc6a7dfee54d9b0605b .

This change works with glance_store v0.1.11 at least.

Implements: blueprint store-capabilities
Depends-On: I5055b837e94fdee7e01cc94f8bdb89bada34f77b

Change-Id: Ibbc85b6bc2ea98c564d316db2874d7df5aac32a6
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
This commit is contained in:
Zhi Yan Liu 2014-12-15 17:55:30 +08:00
parent ab5dca9098
commit efc333ffbd
4 changed files with 62 additions and 0 deletions

View File

@ -458,6 +458,9 @@ class Controller(controller.BaseController):
raise HTTPServiceUnavailable(explanation=e.msg)
except store.NotFound as e:
raise HTTPNotFound(explanation=e.msg)
except (store.StoreGetNotSupported,
store.StoreRandomGetNotSupported) as e:
raise HTTPBadRequest(explanation=e.msg)
image_size = int(image_size) if image_size else None
return image_data, image_size

View File

@ -220,6 +220,9 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
raise webob.exc.HTTPNotFound(explanation=e.msg)
except glance_store.RemoteServiceUnavailable as e:
raise webob.exc.HTTPServiceUnavailable(explanation=e.msg)
except (glance_store.StoreGetNotSupported,
glance_store.StoreRandomGetNotSupported) as e:
raise webob.exc.HTTPBadRequest(explanation=e.msg)
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=e.msg)
# NOTE(saschpe): "response.app_iter = ..." currently resets Content-MD5

View File

@ -2622,6 +2622,21 @@ class TestGlanceAPI(base.IsolatedUnitTest):
image_controller.show,
request, mocked_get_image)
@mock.patch('glance_store._drivers.filesystem.Store.get')
def test_show_image_store_get_not_support(self, m_get):
m_get.side_effect = store.StoreGetNotSupported()
req = webob.Request.blank("/images/%s" % UUID2)
res = req.get_response(self.api)
self.assertEqual(400, res.status_int)
@mock.patch('glance_store._drivers.filesystem.Store.get')
def test_show_image_store_random_get_not_support(self, m_get):
m_get.side_effect = store.StoreRandomGetNotSupported(chunk_size=0,
offset=0)
req = webob.Request.blank("/images/%s" % UUID2)
res = req.get_response(self.api)
self.assertEqual(400, res.status_int)
def test_delete_image(self):
req = webob.Request.blank("/images/%s" % UUID2)
req.method = 'DELETE'

View File

@ -507,6 +507,47 @@ class TestImageDataSerializer(test_utils.BaseTestCase):
self.serializer.download,
response, image)
def test_download_store_get_not_support(self):
"""Test image download returns HTTPBadRequest.
Make sure that serializer returns 400 bad request error in case of
getting images from this store is not supported at specified location.
"""
with mock.patch.object(glance.api.policy.ImageProxy,
'get_data') as mock_get_data:
mock_get_data.side_effect = glance_store.StoreGetNotSupported()
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.HTTPBadRequest,
self.serializer.download,
response, image)
def test_download_store_random_get_not_support(self):
"""Test image download returns HTTPBadRequest.
Make sure that serializer returns 400 bad request error in case of
getting randomly images from this store is not supported at
specified location.
"""
with mock.patch.object(glance.api.policy.ImageProxy,
'get_data') as m_get_data:
err = glance_store.StoreRandomGetNotSupported(offset=0,
chunk_size=0)
m_get_data.side_effect = err
request = wsgi.Request.blank('/')
response = webob.Response()
response.request = request
image = FakeImage(size=3, data=iter('ZZZ'))
image.get_data = m_get_data
self.assertRaises(webob.exc.HTTPBadRequest,
self.serializer.download,
response, image)
def test_upload(self):
request = webob.Request.blank('/')
request.environ = {}