Update json module to jsonutils
oslo project provide jsonutils, and zunclient 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-zunclient/search?q=jsonutils&unscoped_q=jsonutils Change-Id: I3e352c11824689ec9ef4338f151bd4cc562b1bf4
This commit is contained in:
@@ -15,9 +15,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
@@ -43,10 +43,10 @@ def _extract_error_json(body):
|
|||||||
"""Return error_message from the HTTP response body."""
|
"""Return error_message from the HTTP response body."""
|
||||||
error_json = {}
|
error_json = {}
|
||||||
try:
|
try:
|
||||||
body_json = json.loads(body)
|
body_json = jsonutils.loads(body)
|
||||||
if 'error_message' in body_json:
|
if 'error_message' in body_json:
|
||||||
raw_msg = body_json['error_message']
|
raw_msg = body_json['error_message']
|
||||||
error_json = json.loads(raw_msg)
|
error_json = jsonutils.loads(raw_msg)
|
||||||
elif 'error' in body_json:
|
elif 'error' in body_json:
|
||||||
error_body = body_json['error']
|
error_body = body_json['error']
|
||||||
error_json = {'faultstring': error_body['title'],
|
error_json = {'faultstring': error_body['title'],
|
||||||
@@ -219,7 +219,7 @@ class HTTPClient(object):
|
|||||||
kwargs['headers'].setdefault('Accept', 'application/json')
|
kwargs['headers'].setdefault('Accept', 'application/json')
|
||||||
|
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
kwargs['body'] = json.dumps(kwargs['body'])
|
kwargs['body'] = jsonutils.dumps(kwargs['body'])
|
||||||
|
|
||||||
resp, body_iter = self._http_request(url, method, **kwargs)
|
resp, body_iter = self._http_request(url, method, **kwargs)
|
||||||
content_type = resp.getheader('content-type', None)
|
content_type = resp.getheader('content-type', None)
|
||||||
@@ -230,7 +230,7 @@ class HTTPClient(object):
|
|||||||
if 'application/json' in content_type:
|
if 'application/json' in content_type:
|
||||||
body = ''.join([chunk for chunk in body_iter])
|
body = ''.join([chunk for chunk in body_iter])
|
||||||
try:
|
try:
|
||||||
body = json.loads(body)
|
body = jsonutils.loads(body)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
LOG.error('Could not decode response body as JSON')
|
LOG.error('Could not decode response body as JSON')
|
||||||
else:
|
else:
|
||||||
@@ -362,7 +362,7 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
|||||||
kwargs['headers'].setdefault('Accept', 'application/json')
|
kwargs['headers'].setdefault('Accept', 'application/json')
|
||||||
|
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
kwargs['data'] = json.dumps(kwargs.pop('body'))
|
kwargs['data'] = jsonutils.dumps(kwargs.pop('body'))
|
||||||
|
|
||||||
resp = self._http_request(url, method, **kwargs)
|
resp = self._http_request(url, method, **kwargs)
|
||||||
body = resp.content
|
body = resp.content
|
||||||
|
@@ -12,9 +12,10 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
|
|
||||||
if hasattr(yaml, 'CSafeDumper'):
|
if hasattr(yaml, 'CSafeDumper'):
|
||||||
yaml_dumper_base = yaml.CSafeDumper
|
yaml_dumper_base = yaml.CSafeDumper
|
||||||
@@ -53,7 +54,7 @@ def parse(tmpl_str):
|
|||||||
# strip any whitespace before the check
|
# strip any whitespace before the check
|
||||||
tmpl_str = tmpl_str.strip()
|
tmpl_str = tmpl_str.strip()
|
||||||
if tmpl_str.startswith('{'):
|
if tmpl_str.startswith('{'):
|
||||||
tpl = json.loads(tmpl_str)
|
tpl = jsonutils.loads(tmpl_str)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
tpl = yaml.safe_load(tmpl_str)
|
tpl = yaml.safe_load(tmpl_str)
|
||||||
|
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import netutils
|
from oslo_utils import netutils
|
||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse
|
from six.moves.urllib import parse
|
||||||
@@ -78,7 +78,7 @@ def split_and_deserialize(string):
|
|||||||
raise exc.CommandError(_('Attributes must be a list of '
|
raise exc.CommandError(_('Attributes must be a list of '
|
||||||
'PATH=VALUE not "%s"') % string)
|
'PATH=VALUE not "%s"') % string)
|
||||||
try:
|
try:
|
||||||
value = json.loads(value)
|
value = jsonutils.loads(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
from tempest.lib import exceptions
|
from tempest.lib import exceptions
|
||||||
@@ -50,7 +50,7 @@ class TestCase(base.FunctionalTestBase):
|
|||||||
output = self.openstack('appcontainer create {0}'
|
output = self.openstack('appcontainer create {0}'
|
||||||
' --name {1} {2} {3}'
|
' --name {1} {2} {3}'
|
||||||
.format(opts, name, image, params))
|
.format(opts, name, image, params))
|
||||||
container = json.loads(output)
|
container = jsonutils.loads(output)
|
||||||
|
|
||||||
if not output:
|
if not output:
|
||||||
self.fail('Container has not been created!')
|
self.fail('Container has not been created!')
|
||||||
@@ -71,7 +71,7 @@ class TestCase(base.FunctionalTestBase):
|
|||||||
output = self.openstack('appcontainer run {0}'
|
output = self.openstack('appcontainer run {0}'
|
||||||
' --name {1} {2} {3}'
|
' --name {1} {2} {3}'
|
||||||
.format(opts, name, image, params))
|
.format(opts, name, image, params))
|
||||||
container = json.loads(output)
|
container = jsonutils.loads(output)
|
||||||
|
|
||||||
if not output:
|
if not output:
|
||||||
self.fail('Container has not run!')
|
self.fail('Container has not run!')
|
||||||
@@ -105,7 +105,7 @@ class TestCase(base.FunctionalTestBase):
|
|||||||
opts = self.get_opts(fields=fields)
|
opts = self.get_opts(fields=fields)
|
||||||
output = self.openstack('appcontainer list {0} {1}'
|
output = self.openstack('appcontainer list {0} {1}'
|
||||||
.format(opts, params))
|
.format(opts, params))
|
||||||
return json.loads(output)
|
return jsonutils.loads(output)
|
||||||
|
|
||||||
def container_show(self, identifier, fields=None, params=''):
|
def container_show(self, identifier, fields=None, params=''):
|
||||||
"""Show specified container.
|
"""Show specified container.
|
||||||
@@ -118,7 +118,7 @@ class TestCase(base.FunctionalTestBase):
|
|||||||
opts = self.get_opts(fields)
|
opts = self.get_opts(fields)
|
||||||
output = self.openstack('appcontainer show {0} {1} {2}'
|
output = self.openstack('appcontainer show {0} {1} {2}'
|
||||||
.format(opts, identifier, params))
|
.format(opts, identifier, params))
|
||||||
return json.loads(output)
|
return jsonutils.loads(output)
|
||||||
|
|
||||||
def container_rename(self, identifier, name):
|
def container_rename(self, identifier, name):
|
||||||
"""Rename specified container.
|
"""Rename specified container.
|
||||||
|
@@ -13,11 +13,10 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from zunclient import api_versions
|
from zunclient import api_versions
|
||||||
from zunclient.common.apiclient import exceptions
|
from zunclient.common.apiclient import exceptions
|
||||||
@@ -31,9 +30,9 @@ def _get_error_body(faultstring=None, debuginfo=None):
|
|||||||
'faultstring': faultstring,
|
'faultstring': faultstring,
|
||||||
'debuginfo': debuginfo
|
'debuginfo': debuginfo
|
||||||
}
|
}
|
||||||
raw_error_body = json.dumps(error_body)
|
raw_error_body = jsonutils.dumps(error_body)
|
||||||
body = {'error_message': raw_error_body}
|
body = {'error_message': raw_error_body}
|
||||||
raw_body = json.dumps(body)
|
raw_body = jsonutils.dumps(body)
|
||||||
return raw_body
|
return raw_body
|
||||||
|
|
||||||
|
|
||||||
|
@@ -12,9 +12,10 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from zunclient.common import cliutils as utils
|
from zunclient.common import cliutils as utils
|
||||||
from zunclient.common import template_utils
|
from zunclient.common import template_utils
|
||||||
from zunclient.common import utils as zun_utils
|
from zunclient.common import utils as zun_utils
|
||||||
@@ -102,7 +103,7 @@ def do_capsule_describe(cs, args):
|
|||||||
"""Show details of a capsule."""
|
"""Show details of a capsule."""
|
||||||
capsule = cs.capsules.describe(args.capsule)
|
capsule = cs.capsules.describe(args.capsule)
|
||||||
if args.format == 'json':
|
if args.format == 'json':
|
||||||
print(json.dumps(capsule._info, indent=4, sort_keys=True))
|
print(jsonutils.dumps(capsule._info, indent=4, sort_keys=True))
|
||||||
elif args.format == 'yaml':
|
elif args.format == 'yaml':
|
||||||
print(yaml.safe_dump(capsule._info, default_flow_style=False))
|
print(yaml.safe_dump(capsule._info, default_flow_style=False))
|
||||||
elif args.format == 'table':
|
elif args.format == 'table':
|
||||||
|
@@ -15,12 +15,13 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
import io
|
import io
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import tarfile
|
import tarfile
|
||||||
import time
|
import time
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from zunclient.common import cliutils as utils
|
from zunclient.common import cliutils as utils
|
||||||
from zunclient.common import utils as zun_utils
|
from zunclient.common import utils as zun_utils
|
||||||
from zunclient.common.websocketclient import exceptions
|
from zunclient.common.websocketclient import exceptions
|
||||||
@@ -345,7 +346,7 @@ def do_show(cs, args):
|
|||||||
opts = zun_utils.remove_null_parms(**opts)
|
opts = zun_utils.remove_null_parms(**opts)
|
||||||
container = cs.containers.get(**opts)
|
container = cs.containers.get(**opts)
|
||||||
if args.format == 'json':
|
if args.format == 'json':
|
||||||
print(json.dumps(container._info, indent=4, sort_keys=True))
|
print(jsonutils.dumps(container._info, indent=4, sort_keys=True))
|
||||||
elif args.format == 'yaml':
|
elif args.format == 'yaml':
|
||||||
print(yaml.safe_dump(container._info, default_flow_style=False))
|
print(yaml.safe_dump(container._info, default_flow_style=False))
|
||||||
elif args.format == 'table':
|
elif args.format == 'table':
|
||||||
|
@@ -10,9 +10,10 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from zunclient.common import cliutils as utils
|
from zunclient.common import cliutils as utils
|
||||||
from zunclient.common import utils as zun_utils
|
from zunclient.common import utils as zun_utils
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ def do_host_show(cs, args):
|
|||||||
"""Show details of a host."""
|
"""Show details of a host."""
|
||||||
host = cs.hosts.get(args.host)
|
host = cs.hosts.get(args.host)
|
||||||
if args.format == 'json':
|
if args.format == 'json':
|
||||||
print(json.dumps(host._info, indent=4, sort_keys=True))
|
print(jsonutils.dumps(host._info, indent=4, sort_keys=True))
|
||||||
elif args.format == 'yaml':
|
elif args.format == 'yaml':
|
||||||
print(yaml.safe_dump(host._info, default_flow_style=False))
|
print(yaml.safe_dump(host._info, default_flow_style=False))
|
||||||
elif args.format == 'table':
|
elif args.format == 'table':
|
||||||
|
@@ -10,9 +10,10 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from zunclient.common import cliutils as utils
|
from zunclient.common import cliutils as utils
|
||||||
from zunclient.common import utils as zun_utils
|
from zunclient.common import utils as zun_utils
|
||||||
from zunclient import exceptions as exc
|
from zunclient import exceptions as exc
|
||||||
@@ -138,7 +139,7 @@ def do_registry_show(cs, args):
|
|||||||
opts = zun_utils.remove_null_parms(**opts)
|
opts = zun_utils.remove_null_parms(**opts)
|
||||||
registry = cs.registries.get(**opts)
|
registry = cs.registries.get(**opts)
|
||||||
if args.format == 'json':
|
if args.format == 'json':
|
||||||
print(json.dumps(registry._info, indent=4, sort_keys=True))
|
print(jsonutils.dumps(registry._info, indent=4, sort_keys=True))
|
||||||
elif args.format == 'yaml':
|
elif args.format == 'yaml':
|
||||||
print(yaml.safe_dump(registry._info, default_flow_style=False))
|
print(yaml.safe_dump(registry._info, default_flow_style=False))
|
||||||
elif args.format == 'table':
|
elif args.format == 'table':
|
||||||
|
Reference in New Issue
Block a user