]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove the unnecassary volume_api.get(context, volume_id)
authorVincent Hou <sbhou@cn.ibm.com>
Mon, 31 Aug 2015 09:23:48 +0000 (17:23 +0800)
committerVincent Hou <sbhou@cn.ibm.com>
Tue, 1 Sep 2015 13:24:07 +0000 (21:24 +0800)
In the method delete from volume_image_metadata, volume_api.get()
may be called twice. This first time is to get the metadata, and
the second is to get the volume. We can get both of them at the
same time.

Change-Id: I0633c16db21e254ec43bad472748cbc0b7796a24
Closes-Bug: #1489342

cinder/api/contrib/volume_image_metadata.py

index 3b1f77e6ea5f46ec4fbdecfbbba378410fdff54b..7d763f0b4945c910a480a55f0e3b19190cf853a4 100644 (file)
@@ -45,7 +45,7 @@ class VolumeImageMetadataController(wsgi.Controller):
         except exception.VolumeNotFound:
             msg = _('Volume with volume id %s does not exist.') % volume_id
             raise webob.exc.HTTPNotFound(explanation=msg)
-        return meta
+        return (volume, meta)
 
     def _get_all_images_metadata(self, context):
         """Returns the image metadata for all volumes."""
@@ -146,21 +146,18 @@ class VolumeImageMetadataController(wsgi.Controller):
                 raise webob.exc.HTTPBadRequest(explanation=msg)
 
             if key:
-                metadata = self._get_image_metadata(context, id)
+                vol, metadata = self._get_image_metadata(context, id)
                 if key not in metadata:
                     msg = _("Metadata item was not found.")
                     raise webob.exc.HTTPNotFound(explanation=msg)
 
-            try:
-                volume = self.volume_api.get(context, id)
                 self.volume_api.delete_volume_metadata(
-                    context,
-                    volume,
-                    key,
+                    context, vol, key,
                     meta_type=common.METADATA_TYPES.image)
-            except exception.VolumeNotFound:
-                msg = _('Volume does not exist.')
-                raise webob.exc.HTTPNotFound(explanation=msg)
+            else:
+                msg = _("The key cannot be None.")
+                raise webob.exc.HTTPBadRequest(explanation=msg)
+
             return webob.Response(status_int=200)