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
This commit is contained in:
Ankit Agrawal 2016-02-15 22:59:05 -08:00
parent bdeb22da28
commit b2fc77f731
3 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)