diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py index 8aa1325..20d5744 100644 --- a/tempest_lib/common/rest_client.py +++ b/tempest_lib/common/rest_client.py @@ -15,13 +15,13 @@ # under the License. import collections -import json import logging as real_logging import re import time import jsonschema from oslo_log import log as logging +from oslo_serialization import jsonutils as json import six from tempest_lib.common import http @@ -439,16 +439,9 @@ class RestClient(object): self._log_request_full(method, req_url, resp, secs, req_headers, req_body, resp_body, caller_name, extra) - def _json_loads(self, resp_body): - if isinstance(resp_body, bytes): - resp_body = json.loads(resp_body.decode('utf8')) - else: - resp_body = json.loads(resp_body) - return resp_body - def _parse_resp(self, body): try: - body = self._json_loads(body) + body = json.loads(body) except ValueError: return body diff --git a/tempest_lib/services/identity/v2/token_client.py b/tempest_lib/services/identity/v2/token_client.py index 1e5b58e..d7575d4 100644 --- a/tempest_lib/services/identity/v2/token_client.py +++ b/tempest_lib/services/identity/v2/token_client.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from oslo_log import log as logging +from oslo_serialization import jsonutils as json from tempest_lib.common import rest_client from tempest_lib import exceptions @@ -88,13 +87,13 @@ class TokenClient(rest_client.RestClient): self._log_request(method, url, resp) if resp.status in [401, 403]: - resp_body = self._json_loads(resp_body) + resp_body = json.loads(resp_body) raise exceptions.Unauthorized(resp_body['error']['message']) elif resp.status not in [200, 201]: raise exceptions.IdentityError( 'Unexpected status code {0}'.format(resp.status)) - return resp, self._json_loads(resp_body) + return resp, json.loads(resp_body) def get_token(self, user, password, tenant, auth_data=False): """Returns (token id, token data) for supplied credentials.""" diff --git a/tempest_lib/services/identity/v3/token_client.py b/tempest_lib/services/identity/v3/token_client.py index 50dc21d..7798f20 100644 --- a/tempest_lib/services/identity/v3/token_client.py +++ b/tempest_lib/services/identity/v3/token_client.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from oslo_log import log as logging +from oslo_serialization import jsonutils as json from tempest_lib.common import rest_client from tempest_lib import exceptions @@ -138,13 +137,13 @@ class V3TokenClient(rest_client.RestClient): self._log_request(method, url, resp) if resp.status in [401, 403]: - resp_body = self._json_loads(resp_body) + resp_body = json.loads(resp_body) raise exceptions.Unauthorized(resp_body['error']['message']) elif resp.status not in [200, 201, 204]: raise exceptions.IdentityError( 'Unexpected status code {0}'.format(resp.status)) - return resp, self._json_loads(resp_body) + return resp, json.loads(resp_body) def get_token(self, **kwargs): """Returns (token id, token data) for supplied credentials"""