Switch json to oslo_serialization for token_client

During the service client development, we have switched json import
to oslo_serialization on Tempest side.
token_client modules were migrated before that, and they still import
json module.
This patch switches to oslo_serialization for token_client modules.
In addition, an internal method _json_loads() of RestClient is not
used with the above change. So this patch removes _json_loads().

Change-Id: I4c731b2ce35c4fb85904cab89dbe943ae95b3b52
This commit is contained in:
Ken'ichi Ohmichi
2015-09-02 03:13:26 +00:00
committed by Ken'ichi Ohmichi
parent 2ed10d2173
commit 37a767c30c
3 changed files with 8 additions and 17 deletions

View File

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

View File

@@ -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."""

View File

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