Use _parse_resp method from tempest

As a continuation of the patch [1]. The required change
was merged in tempest. So we can make the cleanup in
manila_tempest_plugin.

[1] https://review.opendev.org/c/openstack/manila-tempest-plugin/+/836877

Change-Id: I093be875910ef18deebe3e56b83c6992d1a307e5
This commit is contained in:
lkuchlan
2022-06-29 07:39:53 +03:00
committed by Goutham Pacha Ravi
parent b42c4f84de
commit d62b5dcf51
2 changed files with 4 additions and 45 deletions

View File

@@ -23,7 +23,6 @@ from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions
from manila_tempest_tests import share_exceptions
from manila_tempest_tests import utils
CONF = config.CONF
@@ -43,8 +42,9 @@ class SharesClient(rest_client.RestClient):
self.share_network_id = CONF.share.share_network_id
self.share_size = CONF.share.share_size
def _parse_resp(self, body, verify_top_key=None):
return utils._parse_resp(body, verify_top_key=verify_top_key)
def _parse_resp(self, body, top_key_to_verify=None):
return super(SharesClient, self)._parse_resp(
body, top_key_to_verify=top_key_to_verify)
def create_share(self, share_protocol=None, size=None,
name=None, snapshot_id=None, description=None,
@@ -450,7 +450,7 @@ class SharesClient(rest_client.RestClient):
def get_metadata_item(self, share_id, key):
resp, body = self.get("shares/%s/metadata/%s" % (share_id, key))
self.expected_success(200, resp.status)
return self._parse_resp(body, verify_top_key='meta')
return self._parse_resp(body, top_key_to_verify='meta')
###############

View File

@@ -14,7 +14,6 @@
# under the License.
from collections import OrderedDict
import json
import random
import re
@@ -226,43 +225,3 @@ def get_extra_headers(request_version, graduation_version):
headers = EXPERIMENTAL
extra_headers = True
return headers, extra_headers
def _parse_resp(body, verify_top_key=None):
try:
body = json.loads(body)
except ValueError:
return body
# We assume, that if the first value of the deserialized body's
# item set is a dict or a list, that we just return the first value
# of deserialized body.
# Essentially "cutting out" the first placeholder element in a body
# that looks like this:
#
# {
# "users": [
# ...
# ]
# }
try:
# Ensure there are not more than one top-level keys
# NOTE(freerunner): Ensure, that JSON is not nullable to
# to prevent StopIteration Exception
if not hasattr(body, "keys") or len(body.keys()) != 1:
return body
# Just return the "wrapped" element
first_key, first_item = tuple(body.items())[0]
if isinstance(first_item, (dict, list)):
if verify_top_key is not None:
assert_msg = (
"The expected top level key is '%(top_key)s' but we "
"found '%(actual_key)s'." % {
'top_key': verify_top_key,
'actual_key': first_key
})
assert verify_top_key == first_key, assert_msg
return first_item
except (ValueError, IndexError):
pass
return body