From ef40eea0f78d5572ba8e9ecbc429d3eb59c5ced5 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Wed, 8 Aug 2018 15:00:48 +0200 Subject: [PATCH] Fix exception message when there are leases with the same name The resource variable, originally containing the resource type, i.e. 'lease', was reassigned with a lease object before being used in the exception message. As a result, the message displayed a dictionary of lease values, instead of "type 'lease'". Change-Id: If4cb03cfb4a895c11e3952f0f1b79e0c7d14de8c Closes-Bug: #1786030 (cherry picked from commit 92e26f3417ea2d50bb8f5652bc3073b917a64dcf) --- blazarclient/utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/blazarclient/utils.py b/blazarclient/utils.py index 0dd94a2..95917fd 100644 --- a/blazarclient/utils.py +++ b/blazarclient/utils.py @@ -102,9 +102,9 @@ def get_item_properties(item, fields, mixed_case_fields=None, formatters=None): return tuple(row) -def find_resource_id_by_name_or_id(client, resource, name_or_id, +def find_resource_id_by_name_or_id(client, resource_type, name_or_id, name_key, id_pattern): - resource_manager = getattr(client, resource) + resource_manager = getattr(client, resource_type) is_id = re.match(id_pattern, name_or_id) if is_id: resources = resource_manager.list() @@ -113,11 +113,12 @@ def find_resource_id_by_name_or_id(client, resource, name_or_id, return name_or_id raise exception.BlazarClientException('No resource found with ID %s' % name_or_id) - return _find_resource_id_by_name(client, resource, name_or_id, name_key) + return _find_resource_id_by_name(client, resource_type, name_or_id, + name_key) -def _find_resource_id_by_name(client, resource, name, name_key): - resource_manager = getattr(client, resource) +def _find_resource_id_by_name(client, resource_type, name, name_key): + resource_manager = getattr(client, resource_type) resources = resource_manager.list() named_resources = [] @@ -130,7 +131,7 @@ def _find_resource_id_by_name(client, resource, name, name_key): raise exception.NoUniqueMatch(message="There are more than one " "appropriate resources for the " "name '%s' and type '%s'" % - (name, resource)) + (name, resource_type)) elif named_resources: return named_resources[0] else: