From 8c0f84f8ad9501c79988f7188dc7b7d67e958048 Mon Sep 17 00:00:00 2001 From: Cao Shufeng Date: Wed, 17 Feb 2016 16:31:08 +0800 Subject: Fix omission of request_ids returned to user ManagerWithFind's find() and findall() function is exposed to users as ManagerWithFind is parent class of VolumeManager, SnapshotManager, etc. When the find() and findall() function is called by users, they should also return request_ids to users. Change-Id: I87dca61f96ff9cf4dc9a443a46d7f559e8b3026f Closes-Bug: 1545975 --- cinderclient/base.py | 7 +++++-- cinderclient/tests/unit/test_utils.py | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cinderclient/base.py b/cinderclient/base.py index 36e7df8..db26aae 100644 --- a/cinderclient/base.py +++ b/cinderclient/base.py @@ -348,6 +348,7 @@ class ManagerWithFind(six.with_metaclass(abc.ABCMeta, Manager)): elif num_matches > 1: raise exceptions.NoUniqueMatch else: + matches[0].append_request_ids(matches.request_ids) return matches[0] def findall(self, **kwargs): @@ -370,13 +371,15 @@ class ManagerWithFind(six.with_metaclass(abc.ABCMeta, Manager)): elif 'display_name' in kwargs: search_opts['display_name'] = kwargs['display_name'] - found = [] + found = common_base.ListWithMeta([], None) searches = kwargs.items() + listing = self.list(search_opts=search_opts) + found.append_request_ids(listing.request_ids) # Not all resources attributes support filters on server side # (e.g. 'human_id' doesn't), so when doing findall some client # side filtering is still needed. - for obj in self.list(search_opts=search_opts): + for obj in listing: try: if all(getattr(obj, attr) == value for (attr, value) in searches): diff --git a/cinderclient/tests/unit/test_utils.py b/cinderclient/tests/unit/test_utils.py index 2d2ebd1..347a2d0 100644 --- a/cinderclient/tests/unit/test_utils.py +++ b/cinderclient/tests/unit/test_utils.py @@ -20,7 +20,9 @@ from six import moves from cinderclient import exceptions from cinderclient import utils from cinderclient import base +from cinderclient.openstack.common.apiclient import base as common_base from cinderclient.tests.unit import utils as test_utils +from cinderclient.tests.unit.v2 import fakes UUID = '8e8ec658-c7b0-4243-bdf8-6f7f2952c0d0' @@ -35,6 +37,9 @@ class FakeResource(object): except KeyError: pass + def append_request_ids(self, resp): + pass + class FakeManager(base.ManagerWithFind): @@ -53,7 +58,7 @@ class FakeManager(base.ManagerWithFind): raise exceptions.NotFound(resource_id) def list(self, search_opts): - return self.resources + return common_base.ListWithMeta(self.resources, fakes.REQUEST_ID) class FakeDisplayResource(object): @@ -66,6 +71,9 @@ class FakeDisplayResource(object): except KeyError: pass + def append_request_ids(self, resp): + pass + class FakeDisplayManager(FakeManager): -- cgit v1.2.1