From da13c6285bb0aee55cfbc93f55ce2e2b7d6a28f2 Mon Sep 17 00:00:00 2001 From: Chris Buccella Date: Thu, 3 Apr 2014 04:02:45 +0000 Subject: [PATCH] _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 --- cinder/image/glance.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cinder/image/glance.py b/cinder/image/glance.py index b1b8022e7..0c15ba0aa 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -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', {}) -- 2.45.2