Merge "Dont query image metadata for empty volume list"

This commit is contained in:
Jenkins 2016-03-25 17:31:43 +00:00 committed by Gerrit Code Review
commit 6a6e5a15dc
2 changed files with 19 additions and 13 deletions

View File

@ -13,7 +13,6 @@
# under the License.
"""The Volume Image Metadata API extension."""
import six
import webob
from oslo_log import log as logging
@ -47,16 +46,6 @@ class VolumeImageMetadataController(wsgi.Controller):
raise webob.exc.HTTPNotFound(explanation=msg)
return (volume, meta)
def _get_all_images_metadata(self, context):
"""Returns the image metadata for all volumes."""
try:
all_metadata = self.volume_api.get_volumes_image_metadata(context)
except Exception as e:
LOG.debug('Problem retrieving volume image metadata. '
'It will be skipped. Error: %s', six.text_type(e))
all_metadata = {}
return all_metadata
def _add_image_metadata(self, context, resp_volume_list, image_metas=None):
"""Appends the image metadata to each of the given volume.
@ -95,8 +84,9 @@ class VolumeImageMetadataController(wsgi.Controller):
if authorize(context):
resp_obj.attach(xml=VolumesImageMetadataTemplate())
# Just get the image metadata of those volumes in response.
self._add_image_metadata(context,
list(resp_obj.obj.get('volumes', [])))
volumes = list(resp_obj.obj.get('volumes', []))
if volumes:
self._add_image_metadata(context, volumes)
@wsgi.action("os-set_image_metadata")
@wsgi.serializers(xml=common.MetadataTemplate)

View File

@ -61,6 +61,10 @@ def fake_volume_get_all(*args, **kwargs):
return objects.VolumeList(objects=[fake_volume_api_get()])
def fake_volume_get_all_empty(*args, **kwargs):
return objects.VolumeList(objects=[])
fake_image_metadata = {
'image_id': 'someid',
'image_name': 'fake',
@ -150,6 +154,18 @@ class VolumeImageMetadataTest(test.TestCase):
self.assertEqual(fake_image_metadata,
self._get_image_metadata_list(res.body)[0])
def test_list_detail_empty_volumes(self):
def fake_dont_call_this(*args, **kwargs):
fake_dont_call_this.called = True
fake_dont_call_this.called = False
self.stubs.Set(volume.api.API, 'get_list_volumes_image_metadata',
fake_dont_call_this)
self.stubs.Set(volume.api.API, 'get_all', fake_volume_get_all_empty)
res = self._make_request('/v2/fake/volumes/detail')
self.assertEqual(200, res.status_int)
self.assertFalse(fake_dont_call_this.called)
def test_list_detail_volumes_with_limit(self):
ctxt = context.get_admin_context()
db.volume_create(ctxt, {'id': 'fake', 'status': 'available',