From 8fcefef5c6db3bb7f182df62de9c5bf986f97303 Mon Sep 17 00:00:00 2001 From: Chris Buccella Date: Sat, 1 Feb 2014 07:05:11 +0000 Subject: [PATCH] _translate_from_glance() can cause an unnecessary HTTP request After returning from a get() call to python-glanceclient, nova 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. Change-Id: I67b7dd16a94fe60d873c012f6bd246ab24500d5a Closes-Bug: #1275173 --- nova/image/glance.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nova/image/glance.py b/nova/image/glance.py index 37618792078a..d7ad20aa68ed 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -508,14 +508,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', {})