Merge "Replace standard json module with openstack.common.jsonutils"
This commit is contained in:
@@ -57,7 +57,6 @@
|
||||
import ast
|
||||
import errno
|
||||
import gettext
|
||||
import json
|
||||
import math
|
||||
import netaddr
|
||||
import optparse
|
||||
@@ -90,6 +89,7 @@ from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import quota
|
||||
from nova import rpc
|
||||
from nova.scheduler import rpcapi as scheduler_rpcapi
|
||||
@@ -1536,7 +1536,7 @@ class ExportCommands(object):
|
||||
|
||||
def auth(self):
|
||||
"""Export Nova auth data in format that can be consumed by Keystone"""
|
||||
print json.dumps(self._get_auth_data())
|
||||
print jsonutils.dumps(self._get_auth_data())
|
||||
|
||||
def _get_auth_data(self):
|
||||
output = {
|
||||
|
||||
@@ -24,7 +24,8 @@ library to work with nova.
|
||||
"""
|
||||
|
||||
import fnmatch
|
||||
import json
|
||||
|
||||
from nova.openstack.common import jsonutils
|
||||
|
||||
|
||||
class Store(object):
|
||||
@@ -191,7 +192,7 @@ def _from_json(encoded):
|
||||
Returns a list of strings
|
||||
|
||||
"""
|
||||
return [str(x) for x in json.loads(encoded)]
|
||||
return [str(x) for x in jsonutils.loads(encoded)]
|
||||
|
||||
|
||||
def _to_json(unencoded):
|
||||
@@ -204,7 +205,7 @@ def _to_json(unencoded):
|
||||
Returns a json string
|
||||
|
||||
"""
|
||||
return json.dumps(list(unencoded))
|
||||
return jsonutils.dumps(list(unencoded))
|
||||
|
||||
|
||||
server_fail = False
|
||||
|
||||
@@ -32,7 +32,6 @@ It also allows setting of formatting information through flags.
|
||||
import cStringIO
|
||||
import inspect
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
@@ -44,6 +43,7 @@ import traceback
|
||||
import nova
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import local
|
||||
from nova import version
|
||||
|
||||
@@ -222,7 +222,7 @@ class JSONFormatter(logging.Formatter):
|
||||
if record.exc_info:
|
||||
message['traceback'] = self.formatException(record.exc_info)
|
||||
|
||||
return json.dumps(message)
|
||||
return jsonutils.dumps(message)
|
||||
|
||||
|
||||
class LegacyNovaFormatter(logging.Formatter):
|
||||
|
||||
@@ -13,10 +13,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import jsonutils
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -31,4 +30,4 @@ def notify(_context, message):
|
||||
priority = priority.lower()
|
||||
logger = logging.getLogger(
|
||||
'nova.notification.%s' % message['event_type'])
|
||||
getattr(logger, priority)(json.dumps(message))
|
||||
getattr(logger, priority)(jsonutils.dumps(message))
|
||||
|
||||
@@ -18,11 +18,11 @@ queues. Casts will block, but this is very useful for tests.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
import json
|
||||
import time
|
||||
|
||||
import eventlet
|
||||
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.rpc import common as rpc_common
|
||||
|
||||
CONSUMERS = {}
|
||||
@@ -121,7 +121,7 @@ def create_connection(conf, new=True):
|
||||
|
||||
def check_serialize(msg):
|
||||
"""Make sure a message intended for rpc can be serialized."""
|
||||
json.dumps(msg)
|
||||
jsonutils.dumps(msg)
|
||||
|
||||
|
||||
def multicall(conf, context, topic, msg, timeout=None):
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
import functools
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
import uuid
|
||||
@@ -28,6 +27,7 @@ import qpid.messaging
|
||||
import qpid.messaging.exceptions
|
||||
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.rpc import amqp as rpc_amqp
|
||||
from nova.rpc import common as rpc_common
|
||||
|
||||
@@ -124,7 +124,7 @@ class ConsumerBase(object):
|
||||
addr_opts["node"]["x-declare"].update(node_opts)
|
||||
addr_opts["link"]["x-declare"].update(link_opts)
|
||||
|
||||
self.address = "%s ; %s" % (node_name, json.dumps(addr_opts))
|
||||
self.address = "%s ; %s" % (node_name, jsonutils.dumps(addr_opts))
|
||||
|
||||
self.reconnect(session)
|
||||
|
||||
@@ -222,7 +222,7 @@ class Publisher(object):
|
||||
if node_opts:
|
||||
addr_opts["node"]["x-declare"].update(node_opts)
|
||||
|
||||
self.address = "%s ; %s" % (node_name, json.dumps(addr_opts))
|
||||
self.address = "%s ; %s" % (node_name, jsonutils.dumps(addr_opts))
|
||||
|
||||
self.reconnect(session)
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import pprint
|
||||
import string
|
||||
import sys
|
||||
@@ -27,6 +26,7 @@ import greenlet
|
||||
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.rpc import common as rpc_common
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ def _serialize(data):
|
||||
Error if a developer passes us bad data.
|
||||
"""
|
||||
try:
|
||||
return str(json.dumps(data, ensure_ascii=True))
|
||||
return str(jsonutils.dumps(data, ensure_ascii=True))
|
||||
except TypeError:
|
||||
LOG.error(_("JSON serialization failed."))
|
||||
raise
|
||||
@@ -85,7 +85,7 @@ def _deserialize(data):
|
||||
Deserialization wrapper
|
||||
"""
|
||||
LOG.debug(_("Deserializing: %s"), data)
|
||||
return json.loads(data)
|
||||
return jsonutils.loads(data)
|
||||
|
||||
|
||||
class ZmqSocket(object):
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
Unit Tests for 'common' functons used through rpc code.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.rpc import common as rpc_common
|
||||
from nova import test
|
||||
|
||||
@@ -52,7 +52,7 @@ class RpcCommonTestCase(test.TestCase):
|
||||
except Exception as exc:
|
||||
failure = rpc_common.serialize_remote_exception(sys.exc_info())
|
||||
|
||||
failure = json.loads(failure)
|
||||
failure = jsonutils.loads(failure)
|
||||
#assure the traceback was added
|
||||
self.assertEqual(expected['class'], failure['class'])
|
||||
self.assertEqual(expected['module'], failure['module'])
|
||||
@@ -74,7 +74,7 @@ class RpcCommonTestCase(test.TestCase):
|
||||
except Exception as exc:
|
||||
failure = rpc_common.serialize_remote_exception(sys.exc_info())
|
||||
|
||||
failure = json.loads(failure)
|
||||
failure = jsonutils.loads(failure)
|
||||
#assure the traceback was added
|
||||
self.assertEqual(expected['class'], failure['class'])
|
||||
self.assertEqual(expected['module'], failure['module'])
|
||||
@@ -88,7 +88,7 @@ class RpcCommonTestCase(test.TestCase):
|
||||
'message': 'test message',
|
||||
'tb': ['raise NovaException'],
|
||||
}
|
||||
serialized = json.dumps(failure)
|
||||
serialized = jsonutils.dumps(failure)
|
||||
|
||||
after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
|
||||
self.assertTrue(isinstance(after_exc, exception.NovaException))
|
||||
@@ -103,7 +103,7 @@ class RpcCommonTestCase(test.TestCase):
|
||||
'kwargs': {'cmd': '/bin/echo failed'},
|
||||
'message': 'foo',
|
||||
}
|
||||
serialized = json.dumps(failure)
|
||||
serialized = jsonutils.dumps(failure)
|
||||
|
||||
after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
|
||||
self.assertTrue(isinstance(after_exc, rpc_common.RemoteError))
|
||||
@@ -116,7 +116,7 @@ class RpcCommonTestCase(test.TestCase):
|
||||
'module': self.__class__.__module__,
|
||||
'tb': ['raise FakeUserDefinedException'],
|
||||
}
|
||||
serialized = json.dumps(failure)
|
||||
serialized = jsonutils.dumps(failure)
|
||||
|
||||
after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
|
||||
self.assertTrue(isinstance(after_exc, FakeUserDefinedException))
|
||||
@@ -136,7 +136,7 @@ class RpcCommonTestCase(test.TestCase):
|
||||
'module': self.__class__.__module__,
|
||||
'tb': ['raise FakeIDontExistException'],
|
||||
}
|
||||
serialized = json.dumps(failure)
|
||||
serialized = jsonutils.dumps(failure)
|
||||
|
||||
after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
|
||||
self.assertTrue(isinstance(after_exc, rpc_common.RemoteError))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import cStringIO
|
||||
import json
|
||||
import logging
|
||||
|
||||
from nova import context
|
||||
from nova import flags
|
||||
from nova import log
|
||||
from nova.notifier import api as notifier
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -179,7 +179,7 @@ class JSONFormatterTestCase(test.TestCase):
|
||||
test_data = {'test': 'log'}
|
||||
self.log.debug(test_msg, test_data)
|
||||
|
||||
data = json.loads(self.stream.getvalue())
|
||||
data = jsonutils.loads(self.stream.getvalue())
|
||||
self.assertTrue(data)
|
||||
self.assertTrue('extra' in data)
|
||||
self.assertEqual('test-json', data['name'])
|
||||
@@ -203,7 +203,7 @@ class JSONFormatterTestCase(test.TestCase):
|
||||
except Exception:
|
||||
self.log.exception(test_msg, test_data)
|
||||
|
||||
data = json.loads(self.stream.getvalue())
|
||||
data = jsonutils.loads(self.stream.getvalue())
|
||||
self.assertTrue(data)
|
||||
self.assertTrue('extra' in data)
|
||||
self.assertEqual('test-json', data['name'])
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
|
||||
"""Stubouts, mocks and fixtures for the test suite"""
|
||||
|
||||
import json
|
||||
import random
|
||||
|
||||
from eventlet import tpool
|
||||
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.virt.xenapi import connection as xenapi_conn
|
||||
from nova.virt.xenapi import fake
|
||||
from nova.virt.xenapi import vm_utils
|
||||
@@ -248,7 +248,7 @@ class FakeSessionForFirewallTests(FakeSessionForVMTests):
|
||||
if plugin == "xenhost" and method == "iptables_config":
|
||||
# The command to execute is a json-encoded list
|
||||
cmd_args = args.get('cmd_args', None)
|
||||
cmd = json.loads(cmd_args)
|
||||
cmd = jsonutils.loads(cmd_args)
|
||||
if not cmd:
|
||||
ret_str = ''
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user