From: Dave Chen Date: Mon, 3 Aug 2015 09:01:22 +0000 (+0800) Subject: Show image metadata X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4add2a0a561d40f5957aefd6b5efc26fcb09c995;p=openstack-build%2Fcinder-build.git Show image metadata This patch implements the API to show the glance image metadata for a specific volume. DocImpact: May need to document this API. APIImpact: Provided the API to show image metadata. Partially implements: bp support-modify-volume-image-metadata Change-Id: I2bcc9d3d44a784abaa0138397f553a825c92573a --- diff --git a/cinder/api/contrib/volume_image_metadata.py b/cinder/api/contrib/volume_image_metadata.py index 7d763f0b4..80c19472f 100644 --- a/cinder/api/contrib/volume_image_metadata.py +++ b/cinder/api/contrib/volume_image_metadata.py @@ -134,6 +134,12 @@ class VolumeImageMetadataController(wsgi.Controller): except exception.InvalidVolumeMetadataSize as error: raise webob.exc.HTTPRequestEntityTooLarge(explanation=error.msg) + @wsgi.action("os-show_image_metadata") + @wsgi.serializers(xml=common.MetadataTemplate) + def index(self, req, id, body): + context = req.environ['cinder.context'] + return {'metadata': self._get_image_metadata(context, id)[1]} + @wsgi.action("os-unset_image_metadata") def delete(self, req, id, body): """Deletes an existing image metadata.""" diff --git a/cinder/tests/unit/api/contrib/test_volume_image_metadata.py b/cinder/tests/unit/api/contrib/test_volume_image_metadata.py index dd9ed0108..2b91ed5f4 100644 --- a/cinder/tests/unit/api/contrib/test_volume_image_metadata.py +++ b/cinder/tests/unit/api/contrib/test_volume_image_metadata.py @@ -268,6 +268,18 @@ class VolumeImageMetadataTest(test.TestCase): self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, req, 1, body) + def test_show_image_metadata(self): + body = {"os-show_image_metadata": None} + req = webob.Request.blank('/v2/fake/volumes/1/action') + req.method = 'POST' + req.body = jsonutils.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(200, res.status_int) + self.assertEqual(fake_image_metadata, + json.loads(res.body)["metadata"]) + class ImageMetadataXMLDeserializer(common.MetadataXMLDeserializer): metadata_node_name = "volume_image_metadata"