From 7998dbe33d6671bb4ea0e5506dd24aab8a85d2bf Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Wed, 29 Jan 2014 23:24:50 +0800 Subject: [PATCH] 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 --- glance/api/v2/images.py | 7 ++++++- glance/tests/functional/v2/test_images.py | 2 ++ glance/tests/functional/v2/test_schemas.py | 1 + glance/tests/unit/v2/test_images_resource.py | 13 +++++++++++++ glance/tests/unit/v2/test_schemas_resource.py | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index 479bc86e83..600219c0a4 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -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)'), diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index a347ed6bbb..4c46c64d0b 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -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 = { diff --git a/glance/tests/functional/v2/test_schemas.py b/glance/tests/functional/v2/test_schemas.py index aefa8c5273..00cff511d2 100644 --- a/glance/tests/functional/v2/test_schemas.py +++ b/glance/tests/functional/v2/test_schemas.py @@ -41,6 +41,7 @@ class TestSchemas(functional.FunctionalTest): 'updated_at', 'tags', 'size', + 'owner', 'container_format', 'disk_format', 'self', diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index 6fabbf58e7..04c3d40c77 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -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, diff --git a/glance/tests/unit/v2/test_schemas_resource.py b/glance/tests/unit/v2/test_schemas_resource.py index dfa2d0e7cc..8110f21e6d 100644 --- a/glance/tests/unit/v2/test_schemas_resource.py +++ b/glance/tests/unit/v2/test_schemas_resource.py @@ -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):