]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Show image metadata
authorDave Chen <wei.d.chen@intel.com>
Mon, 3 Aug 2015 09:01:22 +0000 (17:01 +0800)
committerDave Chen <wei.d.chen@intel.com>
Mon, 28 Sep 2015 05:28:54 +0000 (13:28 +0800)
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

cinder/api/contrib/volume_image_metadata.py
cinder/tests/unit/api/contrib/test_volume_image_metadata.py

index 7d763f0b4945c910a480a55f0e3b19190cf853a4..80c19472f11ed7f22fd4bdb12dc240b85d796a09 100644 (file)
@@ -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."""
index dd9ed0108387df317997e556d0478afe48b02b49..2b91ed5f453978920bb8bddf2f8b85e28ffca028 100644 (file)
@@ -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"