Update json module to jsonutils

oslo project provide jsonutils, and neutronclient use it in many place[1],
this PS to update the remained json module to oslo jsonutils for
consistency.

[1]: https://github.com/openstack/python-neutronclient/search?utf8=%E2%9C%93&q=jsonutils&type=

Change-Id: Ic4639628c8910b88a14b0fe8f37638bb4f9474be
This commit is contained in:
cao.yuan 2019-02-25 00:55:22 +08:00 committed by caoyuan
parent d1c8b7486e
commit 1f35b8f25c
2 changed files with 8 additions and 11 deletions
neutronclient

@ -14,16 +14,13 @@
# under the License. # under the License.
# #
try:
import json
except ImportError:
import simplejson as json
import logging import logging
import os import os
import debtcollector.renames import debtcollector.renames
from keystoneauth1 import access from keystoneauth1 import access
from keystoneauth1 import adapter from keystoneauth1 import adapter
from oslo_serialization import jsonutils
from oslo_utils import importutils from oslo_utils import importutils
import requests import requests
@ -239,14 +236,14 @@ class HTTPClient(object):
token_url = self.auth_url + "/tokens" token_url = self.auth_url + "/tokens"
resp, resp_body = self._cs_request(token_url, "POST", resp, resp_body = self._cs_request(token_url, "POST",
body=json.dumps(body), body=jsonutils.dumps(body),
content_type="application/json", content_type="application/json",
allow_redirects=True) allow_redirects=True)
if resp.status_code != 200: if resp.status_code != 200:
raise exceptions.Unauthorized(message=resp_body) raise exceptions.Unauthorized(message=resp_body)
if resp_body: if resp_body:
try: try:
resp_body = json.loads(resp_body) resp_body = jsonutils.loads(resp_body)
except ValueError: except ValueError:
pass pass
else: else:
@ -282,7 +279,7 @@ class HTTPClient(object):
self.authenticate() self.authenticate()
return self.endpoint_url return self.endpoint_url
body = json.loads(body) body = jsonutils.loads(body)
for endpoint in body.get('endpoints', []): for endpoint in body.get('endpoints', []):
if (endpoint['type'] == 'network' and if (endpoint['type'] == 'network' and
endpoint.get('region') == self.region_name): endpoint.get('region') == self.region_name):

@ -16,10 +16,10 @@
import contextlib import contextlib
import itertools import itertools
import json
import sys import sys
import mock import mock
from oslo_serialization import jsonutils
from oslo_utils import encodeutils from oslo_utils import encodeutils
from oslotest import base from oslotest import base
import requests import requests
@ -1153,7 +1153,7 @@ class CLITestV20OutputFormatter(CLITestV20Base):
def test_create_resource_json(self): def test_create_resource_json(self):
self._test_create_resource_with_formatter('json') self._test_create_resource_with_formatter('json')
data = json.loads(self.fake_stdout.make_string()) data = jsonutils.loads(self.fake_stdout.make_string())
self.assertEqual('myname', data['name']) self.assertEqual('myname', data['name'])
self.assertEqual('myid', data['id']) self.assertEqual('myid', data['id'])
@ -1178,7 +1178,7 @@ class CLITestV20OutputFormatter(CLITestV20Base):
def test_show_resource_json(self): def test_show_resource_json(self):
self._test_show_resource_with_formatter('json') self._test_show_resource_with_formatter('json')
data = json.loads(''.join(self.fake_stdout.content)) data = jsonutils.loads(''.join(self.fake_stdout.content))
self.assertEqual('myname', data['name']) self.assertEqual('myname', data['name'])
self.assertEqual('myid', data['id']) self.assertEqual('myid', data['id'])
@ -1206,7 +1206,7 @@ class CLITestV20OutputFormatter(CLITestV20Base):
def test_list_resources_json(self): def test_list_resources_json(self):
self._test_list_resources_with_formatter('json') self._test_list_resources_with_formatter('json')
data = json.loads(''.join(self.fake_stdout.content)) data = jsonutils.loads(''.join(self.fake_stdout.content))
self.assertEqual(['myid1', 'myid2'], [d['id'] for d in data]) self.assertEqual(['myid1', 'myid2'], [d['id'] for d in data])
def test_list_resources_yaml(self): def test_list_resources_yaml(self):