Enable the option to return the response body
As part of our efforts to enhance automation and CI for Manila, we have begun developing code in the Tobiko tool to support the Manila client. During create/get operations, we have observed that the returned body contains solely the resource id in the format <Share: <id>>. To address this, we are introducing a patch that allows retrieving the full body response, not just the id resource. This cherry-pick includes the change I4c1c1e089a726608124693c13eca73ce12fd5b8e (commit2f6cd660c6) from the stable/2023.2 branch. Since both changes are closely related, and resolve the same issue, we could squash the changes into one submission for ease of back porting. Change-Id: Ia15274e75aa5d3da04d861a64a2f437cd4a9a584 (cherry picked from commit47b0ac7d59) (cherry picked from commit3abf89da1b)
This commit is contained in:
committed by
Goutham Pacha Ravi
parent
71c78051bb
commit
6e494f137b
@@ -63,7 +63,8 @@ class Manager(utils.HookableMixin):
|
||||
def api_version(self):
|
||||
return self.api.api_version
|
||||
|
||||
def _list(self, url, response_key, manager=None, body=None):
|
||||
def _list(self, url, response_key, manager=None, body=None,
|
||||
return_raw=None):
|
||||
"""List the collection.
|
||||
|
||||
:param url: a partial URL, e.g., '/shares'
|
||||
@@ -96,6 +97,8 @@ class Manager(utils.HookableMixin):
|
||||
pass
|
||||
with self.completion_cache('human_id', obj_class, mode="w"):
|
||||
with self.completion_cache('uuid', obj_class, mode="w"):
|
||||
if return_raw:
|
||||
return data
|
||||
resource = [obj_class(manager, res, loaded=True)
|
||||
for res in data if res]
|
||||
if 'count' in body:
|
||||
@@ -167,9 +170,11 @@ class Manager(utils.HookableMixin):
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
|
||||
def _get(self, url, response_key=None):
|
||||
def _get(self, url, response_key, return_raw=False):
|
||||
resp, body = self.api.client.get(url)
|
||||
if response_key:
|
||||
if return_raw:
|
||||
return body[response_key]
|
||||
return self.resource_class(self, body[response_key], loaded=True)
|
||||
else:
|
||||
return self.resource_class(self, body, loaded=True)
|
||||
|
||||
@@ -332,15 +332,15 @@ class SharesTest(utils.TestCase):
|
||||
if version >= api_versions.APIVersion('2.69'):
|
||||
manager.do_list.assert_called_once_with(
|
||||
detailed=False, search_opts=search_opts3,
|
||||
sort_key=None, sort_dir=None)
|
||||
sort_key=None, sort_dir=None, return_raw=False)
|
||||
elif version >= api_versions.APIVersion('2.35'):
|
||||
manager.do_list.assert_called_once_with(
|
||||
detailed=False, search_opts=search_opts2,
|
||||
sort_key=None, sort_dir=None)
|
||||
sort_key=None, sort_dir=None, return_raw=False)
|
||||
else:
|
||||
manager.do_list.assert_called_once_with(
|
||||
detailed=False, search_opts=search_opts1,
|
||||
sort_key=None, sort_dir=None)
|
||||
sort_key=None, sort_dir=None, return_raw=False)
|
||||
|
||||
def test_list_shares_index_with_search_opts(self):
|
||||
search_opts = {
|
||||
|
||||
@@ -127,7 +127,7 @@ class ShareManager(base.ManagerWithFind):
|
||||
def create(self, share_proto, size, snapshot_id=None, name=None,
|
||||
description=None, metadata=None, share_network=None,
|
||||
share_type=None, is_public=False, availability_zone=None,
|
||||
share_group_id=None, scheduler_hints=None):
|
||||
share_group_id=None, scheduler_hints=None, return_raw=False):
|
||||
"""Create a share.
|
||||
|
||||
:param share_proto: text - share protocol for new share available
|
||||
@@ -166,7 +166,8 @@ class ShareManager(base.ManagerWithFind):
|
||||
if share_group_id:
|
||||
body['share_group_id'] = share_group_id
|
||||
|
||||
return self._create('/shares', {'share': body}, 'share')
|
||||
return self._create('/shares', {'share': body}, 'share',
|
||||
return_raw=return_raw)
|
||||
|
||||
@api_versions.wraps("2.29")
|
||||
@api_versions.experimental_api
|
||||
@@ -321,14 +322,15 @@ class ShareManager(base.ManagerWithFind):
|
||||
info = {'snapshot_id': snapshot_id}
|
||||
return self._action('revert', share, info=info)
|
||||
|
||||
def get(self, share):
|
||||
def get(self, share, return_raw=False):
|
||||
"""Get a share.
|
||||
|
||||
:param share: either share object or text with its ID.
|
||||
:rtype: :class:`Share`
|
||||
"""
|
||||
share_id = base.getid(share)
|
||||
return self._get("/shares/%s" % share_id, "share")
|
||||
return self._get("/shares/%s" % share_id, "share",
|
||||
return_raw=return_raw)
|
||||
|
||||
def update(self, share, **kwargs):
|
||||
"""Updates a share.
|
||||
@@ -345,31 +347,34 @@ class ShareManager(base.ManagerWithFind):
|
||||
|
||||
@api_versions.wraps("1.0", "2.34")
|
||||
def list(self, detailed=True, search_opts=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
sort_key=None, sort_dir=None, return_raw=False):
|
||||
"""Get a list of all shares."""
|
||||
search_opts = search_opts or {}
|
||||
search_opts.pop("export_location", None)
|
||||
search_opts.pop("is_soft_deleted", None)
|
||||
return self.do_list(detailed=detailed, search_opts=search_opts,
|
||||
sort_key=sort_key, sort_dir=sort_dir)
|
||||
sort_key=sort_key, sort_dir=sort_dir,
|
||||
return_raw=return_raw)
|
||||
|
||||
@api_versions.wraps("2.35", "2.68") # noqa
|
||||
def list(self, detailed=True, search_opts=None, # noqa
|
||||
sort_key=None, sort_dir=None):
|
||||
sort_key=None, sort_dir=None, return_raw=False):
|
||||
"""Get a list of all shares."""
|
||||
search_opts.pop("is_soft_deleted", None)
|
||||
return self.do_list(detailed=detailed, search_opts=search_opts,
|
||||
sort_key=sort_key, sort_dir=sort_dir)
|
||||
sort_key=sort_key, sort_dir=sort_dir,
|
||||
return_raw=return_raw)
|
||||
|
||||
@api_versions.wraps("2.69") # noqa
|
||||
def list(self, detailed=True, search_opts=None, # noqa
|
||||
sort_key=None, sort_dir=None):
|
||||
sort_key=None, sort_dir=None, return_raw=False):
|
||||
"""Get a list of all shares."""
|
||||
return self.do_list(detailed=detailed, search_opts=search_opts,
|
||||
sort_key=sort_key, sort_dir=sort_dir)
|
||||
sort_key=sort_key, sort_dir=sort_dir,
|
||||
return_raw=return_raw)
|
||||
|
||||
def do_list(self, detailed=True, search_opts=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
sort_key=None, sort_dir=None, return_raw=False):
|
||||
"""Get a list of all shares.
|
||||
|
||||
:param detailed: Whether to return detailed share info or not.
|
||||
@@ -440,7 +445,7 @@ class ShareManager(base.ManagerWithFind):
|
||||
else:
|
||||
path = "/shares%s" % (query_string,)
|
||||
|
||||
return self._list(path, 'shares')
|
||||
return self._list(path, 'shares', return_raw=return_raw)
|
||||
|
||||
def delete(self, share, share_group_id=None):
|
||||
"""Delete a share.
|
||||
|
||||
Reference in New Issue
Block a user