Glance API V2 can't recognize parameter 'id'

Based on current implement, API V2 is using **id** in image schema,
but using **image_id** for most of the internal functions as key
word arguments. So user will got a key error if using:

glance --os-image-api-version 2 image-create --id <id>

This patch will map 'id' to 'image_id' in RequestDeserializer and
add an unit test case fo the change.

Closes-Bug: 1366515

Change-Id: I4c72881a7ada728307e806776426b42cf4cf0993
This commit is contained in:
Fei Long Wang 2014-09-08 00:19:25 +12:00
parent 5a74548f46
commit 45c109556d
2 changed files with 17 additions and 2 deletions

View File

@ -320,7 +320,13 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
tags = properties.pop('tags', None)
for key in self._base_properties:
try:
image[key] = properties.pop(key)
# NOTE(flwang): Instead of changing the _check_unexpected
# of ImageFactory. It would be better to do the mapping
# at here.
if key == 'id':
image['image_id'] = properties.pop(key)
else:
image[key] = properties.pop(key)
except KeyError:
pass
return dict(image=image, extra_properties=properties, tags=tags)

View File

@ -1942,6 +1942,15 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
self.assertRaises(webob.exc.HTTPBadRequest, self.deserializer.create,
request)
def test_create_id_to_image_id(self):
request = unit_test_utils.get_fake_request()
request.body = jsonutils.dumps({'id': UUID4})
output = self.deserializer.create(request)
expected = {'image': {'image_id': UUID4},
'extra_properties': {},
'tags': None}
self.assertEqual(expected, output)
def test_create_no_body(self):
request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPBadRequest, self.deserializer.create,
@ -1963,7 +1972,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
})
output = self.deserializer.create(request)
properties = {
'id': UUID3,
'image_id': UUID3,
'name': 'image-1',
'visibility': 'public',
'container_format': 'ami',