Convert all non-test imports of json to jsonutils
As requested in: https://review.openstack.org/#/c/116336/24/heat/engine/stack_resource.py Change-Id: Icea97aa44d2a3461fdfa2324292fd3b2c2f000e1
This commit is contained in:
parent
37727fcf1e
commit
ac536c6114
@ -15,10 +15,10 @@
|
||||
Stack endpoint for Heat CloudFormation v1 API.
|
||||
"""
|
||||
|
||||
import json
|
||||
import socket
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from heat.api.aws import exception
|
||||
from heat.api.aws import utils as api_utils
|
||||
@ -510,8 +510,8 @@ class StackController(object):
|
||||
action = e[rpc_api.EVENT_RES_ACTION]
|
||||
status = e[rpc_api.EVENT_RES_STATUS]
|
||||
result['ResourceStatus'] = '_'.join((action, status))
|
||||
result['ResourceProperties'] = json.dumps(result[
|
||||
'ResourceProperties'])
|
||||
result['ResourceProperties'] = jsonutils.dumps(result[
|
||||
'ResourceProperties'])
|
||||
|
||||
return self._id_format(result)
|
||||
|
||||
|
@ -16,8 +16,8 @@ Controller that returns information on the heat API versions
|
||||
"""
|
||||
|
||||
import httplib
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import webob.dec
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ class Controller(object):
|
||||
}]
|
||||
}]
|
||||
|
||||
body = json.dumps(dict(versions=version_objs))
|
||||
body = jsonutils.dumps(dict(versions=version_objs))
|
||||
|
||||
response = webob.Response(request=req,
|
||||
status=httplib.MULTIPLE_CHOICES,
|
||||
|
@ -14,8 +14,8 @@
|
||||
"""Controller that returns information on the heat API versions."""
|
||||
|
||||
import httplib
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import webob.dec
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ class Controller(object):
|
||||
}]
|
||||
}]
|
||||
|
||||
body = json.dumps(dict(versions=version_objs))
|
||||
body = jsonutils.dumps(dict(versions=version_objs))
|
||||
|
||||
response = webob.Response(request=req,
|
||||
status=httplib.MULTIPLE_CHOICES,
|
||||
|
@ -16,8 +16,8 @@ Controller that returns information on the heat API versions
|
||||
"""
|
||||
|
||||
import httplib
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import webob.dec
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ class Controller(object):
|
||||
}]
|
||||
}]
|
||||
|
||||
body = json.dumps(dict(versions=version_objs))
|
||||
body = jsonutils.dumps(dict(versions=version_objs))
|
||||
|
||||
response = webob.Response(request=req,
|
||||
status=httplib.MULTIPLE_CHOICES,
|
||||
|
@ -14,7 +14,6 @@
|
||||
"""Keystone Client functionality for use by resources."""
|
||||
|
||||
import collections
|
||||
import json
|
||||
import uuid
|
||||
|
||||
import keystoneclient.exceptions as kc_exception
|
||||
@ -22,6 +21,7 @@ from keystoneclient import session
|
||||
from keystoneclient.v3 import client as kc_v3
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import importutils
|
||||
|
||||
from heat.common import context
|
||||
@ -484,7 +484,7 @@ class KeystoneClientV3(object):
|
||||
# extensible-crud-manager-operations bp lands
|
||||
credentials = self.client.credentials.list()
|
||||
for cr in credentials:
|
||||
ec2_creds = json.loads(cr.blob)
|
||||
ec2_creds = jsonutils.loads(cr.blob)
|
||||
if ec2_creds.get('access') == access:
|
||||
return AccessKey(id=cr.id,
|
||||
access=ec2_creds['access'],
|
||||
@ -514,7 +514,7 @@ class KeystoneClientV3(object):
|
||||
# then we'll have to do a brute-force lookup locally
|
||||
if credential_id:
|
||||
cred = self.client.credentials.get(credential_id)
|
||||
ec2_creds = json.loads(cred.blob)
|
||||
ec2_creds = jsonutils.loads(cred.blob)
|
||||
return AccessKey(id=cred.id,
|
||||
access=ec2_creds['access'],
|
||||
secret=ec2_creds['secret'])
|
||||
@ -529,7 +529,7 @@ class KeystoneClientV3(object):
|
||||
data_blob = {'access': uuid.uuid4().hex,
|
||||
'secret': uuid.uuid4().hex}
|
||||
ec2_creds = self.client.credentials.create(
|
||||
user=user_id, type='ec2', data=json.dumps(data_blob),
|
||||
user=user_id, type='ec2', data=jsonutils.dumps(data_blob),
|
||||
project=project_id)
|
||||
|
||||
# Return a AccessKey namedtuple for easier access to the blob contents
|
||||
@ -550,7 +550,7 @@ class KeystoneClientV3(object):
|
||||
data_blob = {'access': uuid.uuid4().hex,
|
||||
'secret': uuid.uuid4().hex}
|
||||
creds = self.domain_admin_client.credentials.create(
|
||||
user=user_id, type='ec2', data=json.dumps(data_blob),
|
||||
user=user_id, type='ec2', data=jsonutils.dumps(data_blob),
|
||||
project=project_id)
|
||||
return AccessKey(id=creds.id,
|
||||
access=data_blob['access'],
|
||||
|
@ -21,10 +21,10 @@ Utility methods for serializing responses
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from lxml import etree
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -38,7 +38,7 @@ class JSONResponseSerializer(object):
|
||||
return obj.isoformat()
|
||||
return obj
|
||||
|
||||
response = json.dumps(data, default=sanitizer)
|
||||
response = jsonutils.dumps(data, default=sanitizer)
|
||||
LOG.debug("JSON response : %s" % response)
|
||||
return response
|
||||
|
||||
@ -67,7 +67,7 @@ class XMLResponseSerializer(object):
|
||||
# Need to use json.dumps for the JSON inside XML
|
||||
# otherwise quotes get mangled and json.loads breaks
|
||||
try:
|
||||
subelement.text = json.dumps(value)
|
||||
subelement.text = jsonutils.dumps(value)
|
||||
except TypeError:
|
||||
subelement.text = str(value)
|
||||
else:
|
||||
|
@ -12,10 +12,10 @@
|
||||
# under the License.
|
||||
|
||||
import itertools
|
||||
import json
|
||||
import re
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
import yaml
|
||||
|
||||
@ -50,7 +50,7 @@ yaml_loader.add_constructor(u'tag:yaml.org,2002:timestamp',
|
||||
|
||||
def simple_parse(tmpl_str):
|
||||
try:
|
||||
tpl = json.loads(tmpl_str)
|
||||
tpl = jsonutils.loads(tmpl_str)
|
||||
except ValueError:
|
||||
try:
|
||||
tpl = yaml.load(tmpl_str, Loader=yaml_loader)
|
||||
|
@ -22,7 +22,6 @@ Utility methods for working with WSGI servers
|
||||
|
||||
import abc
|
||||
import errno
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
@ -36,6 +35,7 @@ import eventlet.greenio
|
||||
import eventlet.wsgi
|
||||
from oslo_config import cfg
|
||||
import oslo_i18n as i18n
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import importutils
|
||||
from paste import deploy
|
||||
import routes
|
||||
@ -590,7 +590,7 @@ class JSONRequestDeserializer(object):
|
||||
) % {'len': len(datastring),
|
||||
'limit': cfg.CONF.max_json_body_size}
|
||||
raise exception.RequestLimitExceeded(message=msg)
|
||||
return json.loads(datastring)
|
||||
return jsonutils.loads(datastring)
|
||||
except ValueError as ex:
|
||||
raise webob.exc.HTTPBadRequest(six.text_type(ex))
|
||||
|
||||
|
@ -11,15 +11,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from sqlalchemy.dialects import mysql
|
||||
from sqlalchemy.ext import mutable
|
||||
from sqlalchemy import types
|
||||
|
||||
|
||||
dumps = json.dumps
|
||||
loads = json.loads
|
||||
dumps = jsonutils.dumps
|
||||
loads = jsonutils.loads
|
||||
|
||||
|
||||
class LongText(types.TypeDecorator):
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
import collections
|
||||
import itertools
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
from heat.api.aws import utils as aws_utils
|
||||
@ -238,7 +238,7 @@ class Select(function.Function):
|
||||
if isinstance(strings, six.string_types):
|
||||
# might be serialized json.
|
||||
try:
|
||||
strings = json.loads(strings)
|
||||
strings = jsonutils.loads(strings)
|
||||
except ValueError as json_ex:
|
||||
fmt_data = {'fn_name': self.fn_name,
|
||||
'err': json_ex}
|
||||
|
@ -15,7 +15,6 @@ import collections
|
||||
import email
|
||||
from email.mime import multipart
|
||||
from email.mime import text
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pkgutil
|
||||
@ -25,6 +24,7 @@ from novaclient import client as nc
|
||||
from novaclient import exceptions
|
||||
from novaclient import shell as novashell
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
@ -259,7 +259,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
'loguserdata.py', 'x-shellscript'))
|
||||
|
||||
if metadata:
|
||||
attachments.append((json.dumps(metadata),
|
||||
attachments.append((jsonutils.dumps(metadata),
|
||||
'cfn-init-data', 'x-cfninitdata'))
|
||||
|
||||
attachments.append((cfg.CONF.heat_watch_server_url,
|
||||
@ -386,7 +386,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
|
||||
return dict((key, (value if isinstance(value,
|
||||
six.string_types)
|
||||
else json.dumps(value))
|
||||
else jsonutils.dumps(value))
|
||||
) for (key, value) in metadata.items())
|
||||
|
||||
def meta_update(self, server, metadata):
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
import collections
|
||||
import itertools
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
@ -405,9 +405,10 @@ class JsonParam(Parameter):
|
||||
try:
|
||||
val = value
|
||||
if not isinstance(val, six.string_types):
|
||||
val = json.dumps(val)
|
||||
# turn off oslo_serialization's clever to_primitive()
|
||||
val = jsonutils.dumps(val, default=None)
|
||||
if val:
|
||||
return json.loads(val)
|
||||
return jsonutils.loads(val)
|
||||
except (ValueError, TypeError) as err:
|
||||
message = _('Value must be valid JSON: %s') % err
|
||||
raise ValueError(message)
|
||||
@ -431,7 +432,7 @@ class JsonParam(Parameter):
|
||||
def __str__(self):
|
||||
if self.hidden():
|
||||
return super(JsonParam, self).__str__()
|
||||
return encodeutils.safe_decode(json.dumps(self.value()))
|
||||
return encodeutils.safe_decode(jsonutils.dumps(self.value()))
|
||||
|
||||
def _validate(self, val, context):
|
||||
val = self.parse(val)
|
||||
|
@ -15,7 +15,6 @@
|
||||
import email
|
||||
from email.mime import multipart
|
||||
from email.mime import text
|
||||
import json
|
||||
import os
|
||||
import pkgutil
|
||||
import string
|
||||
@ -24,6 +23,7 @@ import warnings
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
@ -213,7 +213,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
|
||||
metadata = resource.metadata_get()
|
||||
if metadata:
|
||||
attachments.append((json.dumps(metadata),
|
||||
attachments.append((jsonutils.dumps(metadata),
|
||||
'cfn-init-data', 'x-cfninitdata'))
|
||||
|
||||
attachments.append((cfg.CONF.heat_watch_server_url,
|
||||
@ -354,7 +354,7 @@ def meta_serialize(metadata):
|
||||
'Use self.client_plugin("nova").meta_serialize')
|
||||
return dict((key, (value if isinstance(value,
|
||||
six.string_types)
|
||||
else json.dumps(value))
|
||||
else jsonutils.dumps(value))
|
||||
) for (key, value) in metadata.items())
|
||||
|
||||
|
||||
|
@ -11,9 +11,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
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
@ -213,7 +212,7 @@ class CinderVolume(aws_vol.Volume):
|
||||
cinder = self.client()
|
||||
vol = cinder.volumes.get(self.resource_id)
|
||||
if name == self.METADATA_ATTR:
|
||||
return six.text_type(json.dumps(vol.metadata))
|
||||
return six.text_type(jsonutils.dumps(vol.metadata))
|
||||
elif name == self.METADATA_VALUES_ATTR:
|
||||
return vol.metadata
|
||||
if cinder.volume_api_version >= 2:
|
||||
|
@ -11,9 +11,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
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
@ -142,7 +141,7 @@ class HeatWaitCondition(resource.Resource):
|
||||
'key': key,
|
||||
'res': res})
|
||||
|
||||
return six.text_type(json.dumps(res))
|
||||
return six.text_type(jsonutils.dumps(res))
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
|
@ -11,10 +11,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import urlparse
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
@ -262,7 +262,7 @@ class SwiftSignal(resource.Resource):
|
||||
obj_bodies.append({})
|
||||
continue
|
||||
try:
|
||||
obj_bodies.append(json.loads(body))
|
||||
obj_bodies.append(jsonutils.loads(body))
|
||||
except ValueError:
|
||||
raise exception.Error(_("Failed to parse JSON data: %s") %
|
||||
body)
|
||||
@ -330,7 +330,7 @@ class SwiftSignal(resource.Resource):
|
||||
|
||||
def _resolve_attribute(self, key):
|
||||
if key == self.DATA:
|
||||
return six.text_type(json.dumps(self.get_data()))
|
||||
return six.text_type(jsonutils.dumps(self.get_data()))
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
|
@ -11,8 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from requests import exceptions
|
||||
import six
|
||||
|
||||
@ -175,7 +174,7 @@ class TemplateResource(stack_resource.StackResource):
|
||||
|
||||
if t_data is None:
|
||||
if self.nested() is not None:
|
||||
t_data = json.dumps(self.nested().t.t)
|
||||
t_data = jsonutils.dumps(self.nested().t.t)
|
||||
|
||||
if t_data is not None:
|
||||
self.stack.t.files[self.template_name] = t_data
|
||||
|
@ -12,7 +12,6 @@
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import warnings
|
||||
@ -21,6 +20,7 @@ import eventlet
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import oslo_messaging as messaging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
from osprofiler import profiler
|
||||
import six
|
||||
@ -1039,7 +1039,7 @@ class EngineService(service.Service):
|
||||
|
||||
# fall back to looking for EC2 credentials in the context
|
||||
try:
|
||||
ec2_creds = json.loads(cnxt.aws_creds).get('ec2Credentials')
|
||||
ec2_creds = jsonutils.loads(cnxt.aws_creds).get('ec2Credentials')
|
||||
except (TypeError, AttributeError):
|
||||
ec2_creds = None
|
||||
|
||||
|
@ -11,8 +11,6 @@
|
||||
# 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
|
||||
from oslo_utils import timeutils
|
||||
@ -127,7 +125,7 @@ class SoftwareConfigService(service.Service):
|
||||
raise ex
|
||||
if obj:
|
||||
self.signal_software_deployment(
|
||||
cnxt, sd.id, json.loads(obj),
|
||||
cnxt, sd.id, jsonutils.loads(obj),
|
||||
timeutils.strtime(last_modified))
|
||||
|
||||
return db_api.software_deployment_get(cnxt, sd.id)
|
||||
|
@ -12,7 +12,6 @@
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
@ -22,7 +21,7 @@ import mock
|
||||
import mox
|
||||
from oslo_config import cfg
|
||||
from oslo_messaging.rpc import dispatcher
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_serialization import jsonutils as json
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
@ -3974,7 +3973,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
|
||||
{'rsrc_metadata': result_metadata})
|
||||
|
||||
put.assert_called_once_with(
|
||||
'http://192.168.2.2/foo/bar', jsonutils.dumps(result_metadata))
|
||||
'http://192.168.2.2/foo/bar', json.dumps(result_metadata))
|
||||
|
||||
@mock.patch.object(service_software_config.SoftwareConfigService,
|
||||
'signal_software_deployment')
|
||||
|
@ -11,8 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils as json
|
||||
import six
|
||||
import testtools
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user