Expose image property 'owner' in v2 API

The 'owner' property on an image is exposed in v1 but does
not appear in the v2 image response. It would be useful to
have this available.

docImpact
Implement blueprint expose-owner-in-v2

Change-Id: I90f68d57e185f4a5ee63cd97bd5597948dde33ea
This commit is contained in:
Fei Long Wang 2014-01-29 23:24:50 +08:00
parent 8782526a91
commit 7998dbe33d
5 changed files with 23 additions and 2 deletions

View File

@ -565,7 +565,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
image_view = dict(image.extra_properties)
attributes = ['name', 'disk_format', 'container_format',
'visibility', 'size', 'status', 'checksum',
'protected', 'min_ram', 'min_disk']
'protected', 'min_ram', 'min_disk', 'owner']
for key in attributes:
image_view[key] = getattr(image, key)
image_view['id'] = image.image_id
@ -665,6 +665,11 @@ def _get_base_properties():
'description': _('md5 hash of image contents. (READ-ONLY)'),
'maxLength': 32,
},
'owner': {
'type': 'string',
'description': _('Owner of the image'),
'maxLength': 255,
},
'size': {
'type': 'integer',
'description': _('Size of image file in bytes (READ-ONLY)'),

View File

@ -90,6 +90,7 @@ class TestImages(functional.FunctionalTest):
u'schema',
u'disk_format',
u'container_format',
u'owner',
])
self.assertEqual(set(image.keys()), checked_keys)
expected_image = {
@ -149,6 +150,7 @@ class TestImages(functional.FunctionalTest):
u'schema',
u'disk_format',
u'container_format',
u'owner',
])
self.assertEqual(set(image.keys()), checked_keys)
expected_image = {

View File

@ -41,6 +41,7 @@ class TestSchemas(functional.FunctionalTest):
'updated_at',
'tags',
'size',
'owner',
'container_format',
'disk_format',
'self',

View File

@ -2551,6 +2551,7 @@ class TestImagesSerializer(test_utils.BaseTestCase):
'self': '/v2/images/%s' % UUID1,
'file': '/v2/images/%s/file' % UUID1,
'schema': '/v2/schemas/image',
'owner': '6838eb7b-6ded-434a-882c-b344c77fe8df',
},
{
'id': UUID2,
@ -2639,6 +2640,7 @@ class TestImagesSerializer(test_utils.BaseTestCase):
'self': '/v2/images/%s' % UUID1,
'file': '/v2/images/%s/file' % UUID1,
'schema': '/v2/schemas/image',
'owner': '6838eb7b-6ded-434a-882c-b344c77fe8df',
}
response = webob.Response()
self.serializer.show(response, self.fixtures[0])
@ -2683,6 +2685,7 @@ class TestImagesSerializer(test_utils.BaseTestCase):
'self': '/v2/images/%s' % UUID1,
'file': '/v2/images/%s/file' % UUID1,
'schema': '/v2/schemas/image',
'owner': '6838eb7b-6ded-434a-882c-b344c77fe8df',
}
response = webob.Response()
self.serializer.create(response, self.fixtures[0])
@ -2710,6 +2713,7 @@ class TestImagesSerializer(test_utils.BaseTestCase):
'self': '/v2/images/%s' % UUID1,
'file': '/v2/images/%s/file' % UUID1,
'schema': '/v2/schemas/image',
'owner': '6838eb7b-6ded-434a-882c-b344c77fe8df',
}
response = webob.Response()
self.serializer.update(response, self.fixtures[0])
@ -2767,6 +2771,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase):
u'schema': u'/v2/schemas/image',
u'lang': u'Fran\u00E7ais',
u'dispos\u00E9': u'f\u00E2ch\u00E9',
u'owner': u'6838eb7b-6ded-434a-882c-b344c77fe8df',
},
],
u'first': u'/v2/images',
@ -2800,6 +2805,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase):
u'schema': u'/v2/schemas/image',
u'lang': u'Fran\u00E7ais',
u'dispos\u00E9': u'f\u00E2ch\u00E9',
u'owner': u'6838eb7b-6ded-434a-882c-b344c77fe8df',
}
response = webob.Response()
self.serializer.show(response, self.fixtures[0])
@ -2829,6 +2835,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase):
u'schema': u'/v2/schemas/image',
u'lang': u'Fran\u00E7ais',
u'dispos\u00E9': u'f\u00E2ch\u00E9',
u'owner': u'6838eb7b-6ded-434a-882c-b344c77fe8df',
}
response = webob.Response()
self.serializer.create(response, self.fixtures[0])
@ -2858,6 +2865,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase):
u'schema': u'/v2/schemas/image',
u'lang': u'Fran\u00E7ais',
u'dispos\u00E9': u'f\u00E2ch\u00E9',
u'owner': u'6838eb7b-6ded-434a-882c-b344c77fe8df',
}
response = webob.Response()
self.serializer.update(response, self.fixtures[0])
@ -2897,6 +2905,7 @@ class TestImagesSerializerWithExtendedSchema(test_utils.BaseTestCase):
'checksum': 'ca425b88f047ce8ec45ee90e813ada91',
'tags': [],
'size': 1024,
'owner': '2c014f32-55eb-467d-8fcb-4bd706012f81',
'color': 'green',
'created_at': ISOTIME,
'updated_at': ISOTIME,
@ -2919,6 +2928,7 @@ class TestImagesSerializerWithExtendedSchema(test_utils.BaseTestCase):
'checksum': 'ca425b88f047ce8ec45ee90e813ada91',
'tags': [],
'size': 1024,
'owner': '2c014f32-55eb-467d-8fcb-4bd706012f81',
'color': 'invalid',
'created_at': ISOTIME,
'updated_at': ISOTIME,
@ -2959,6 +2969,7 @@ class TestImagesSerializerWithAdditionalProperties(test_utils.BaseTestCase):
'self': '/v2/images/%s' % UUID2,
'file': '/v2/images/%s/file' % UUID2,
'schema': '/v2/schemas/image',
'owner': '2c014f32-55eb-467d-8fcb-4bd706012f81',
}
response = webob.Response()
serializer.show(response, self.fixture)
@ -2985,6 +2996,7 @@ class TestImagesSerializerWithAdditionalProperties(test_utils.BaseTestCase):
'self': '/v2/images/%s' % UUID2,
'file': '/v2/images/%s/file' % UUID2,
'schema': '/v2/schemas/image',
'owner': '2c014f32-55eb-467d-8fcb-4bd706012f81',
}
response = webob.Response()
serializer.show(response, self.fixture)
@ -3002,6 +3014,7 @@ class TestImagesSerializerWithAdditionalProperties(test_utils.BaseTestCase):
'checksum': 'ca425b88f047ce8ec45ee90e813ada91',
'tags': [],
'size': 1024,
'owner': '2c014f32-55eb-467d-8fcb-4bd706012f81',
'created_at': ISOTIME,
'updated_at': ISOTIME,
'self': '/v2/images/%s' % UUID2,

View File

@ -32,7 +32,7 @@ class TestSchemasController(test_utils.BaseTestCase):
'disk_format', 'updated_at', 'visibility', 'self',
'file', 'container_format', 'schema', 'id', 'size',
'direct_url', 'min_ram', 'min_disk', 'protected',
'locations'])
'locations', 'owner'])
self.assertEqual(set(output['properties'].keys()), expected)
def test_images(self):