From b2fc77f731c9cdb02efaa942f140ee7fd134ffac Mon Sep 17 00:00:00 2001 From: Ankit Agrawal Date: Mon, 15 Feb 2016 22:59:05 -0800 Subject: [PATCH] Provide consistency for Wrapper classes Updated TupleWithMeta class to make it consistent with other Meta classes in order to avoid confusion. Also made provision to call TupleWithMeta with a tuple containing one or more elements. For more details on how request_id will be returned to the caller, please refer to the approved blueprint [1] discussed with the cross-project team. [1] http://specs.openstack.org/openstack/openstack-specs/specs/return-request-id.html Change-Id: I5a79a4ed8cb4dc83ea3b64499df191750462100d Partial-Implements: blueprint return-request-id-to-caller --- cinderclient/base.py | 2 +- cinderclient/openstack/common/apiclient/base.py | 6 +++--- cinderclient/tests/unit/test_base.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cinderclient/base.py b/cinderclient/base.py index 36e7df89e..78c6fd2ef 100644 --- a/cinderclient/base.py +++ b/cinderclient/base.py @@ -307,7 +307,7 @@ class Manager(common_base.HookableMixin): def _delete(self, url): resp, body = self.api.client.delete(url) - return common_base.TupleWithMeta(resp, body) + return common_base.TupleWithMeta((resp, body), resp) def _update(self, url, body, response_key=None, **kwargs): self.run_hooks('modify_body_for_update', body, **kwargs) diff --git a/cinderclient/openstack/common/apiclient/base.py b/cinderclient/openstack/common/apiclient/base.py index abfcdfe7a..3645f6874 100644 --- a/cinderclient/openstack/common/apiclient/base.py +++ b/cinderclient/openstack/common/apiclient/base.py @@ -551,9 +551,9 @@ class DictWithMeta(dict, RequestIdMixin): class TupleWithMeta(tuple, RequestIdMixin): - def __new__(cls, resp, values): - return super(TupleWithMeta, cls).__new__(cls, (resp, values)) + def __new__(cls, values, resp): + return super(TupleWithMeta, cls).__new__(cls, values) - def __init__(self, resp, values): + def __init__(self, values, resp): self.setup() self.append_request_ids(resp) diff --git a/cinderclient/tests/unit/test_base.py b/cinderclient/tests/unit/test_base.py index 7d329dedc..67265a78e 100644 --- a/cinderclient/tests/unit/test_base.py +++ b/cinderclient/tests/unit/test_base.py @@ -106,8 +106,8 @@ class DictWithMetaTest(utils.TestCase): class TupleWithMetaTest(utils.TestCase): def test_tuple_with_meta(self): resp = create_response_obj_with_header() - obj = common_base.TupleWithMeta(resp, None) - self.assertIsInstance(obj, tuple) + obj = common_base.TupleWithMeta((), resp) + self.assertEqual((), obj) # Check request_ids attribute is added to obj self.assertTrue(hasattr(obj, 'request_ids')) self.assertEqual([REQUEST_ID], obj.request_ids)