Merge "Switch json to oslo_serialization for token_client"

This commit is contained in:
Jenkins
2015-09-24 17:28:13 +00:00
committed by Gerrit Code Review
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
@@ -442,16 +442,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"""