_translate_from_glance() can cause an unnecessary HTTP request

After returning from a get() call to python-glanceclient, cinder runs a
translation function on the returned Image to get the data it wants. Part of
this process is checking for an expected set of attributes, one of which is
the deletion time ('deleted_at'). However, if the image has not been deleted,
deleted_at key will not exist. This forces another call to glance to occur for
the same image. A similar problem exists for the checksum attribute, which does
not exist before an image is active. The fix here is to only consider
deleted_at and checksum if they are expected to be present.

This change was made in nova as change I67b7dd16

Change-Id: Iedc16cb9316f9610fdb8ac03f448bc375a4e6bfa
Closes-Bug: #1275173
(cherry picked from commit da13c6285b)
This commit is contained in:
Chris Buccella 2014-04-03 04:02:45 +00:00 committed by john-griffith
parent 5a1fcc88ce
commit 01e5eac3f2
1 changed files with 14 additions and 3 deletions

View File

@ -413,14 +413,25 @@ def _convert_to_string(metadata):
def _extract_attributes(image):
#NOTE(hdd): If a key is not found, base.Resource.__getattr__() may perform
# a get(), resulting in a useless request back to glance. This list is
# therefore sorted, with dependent attributes as the end
# 'deleted_at' depends on 'deleted'
# 'checksum' depends on 'status' == 'active'
IMAGE_ATTRIBUTES = ['size', 'disk_format', 'owner',
'container_format', 'checksum', 'id',
'container_format', 'status', 'id',
'name', 'created_at', 'updated_at',
'deleted_at', 'deleted', 'status',
'deleted', 'deleted_at', 'checksum',
'min_disk', 'min_ram', 'is_public']
output = {}
for attr in IMAGE_ATTRIBUTES:
output[attr] = getattr(image, attr, None)
if attr == 'deleted_at' and not output['deleted']:
output[attr] = None
elif attr == 'checksum' and output['status'] != 'active':
output[attr] = None
else:
output[attr] = getattr(image, attr)
output['properties'] = getattr(image, 'properties', {})