Replace standard json module with openstack.common.jsonutils

Implements blueprint use-common-jsonutils

1. Edit openstack-common.conf and import nova/openstack/common/jsonutils.py
2. Remove json package imports and replace with jsonutils

Places where using json.load hasn't changed.

Change-Id: Ie6feab605fb0474fd505c56ef57b7a9ecfa5269d
This commit is contained in:
Zhongyue Luo 2012-06-03 16:36:06 +08:00
parent 7b7febb02b
commit 3dce38f325
60 changed files with 454 additions and 401 deletions

View File

@ -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 = {

View File

@ -20,7 +20,6 @@ Module dedicated functions/classes dealing with rate limiting requests.
import collections
import copy
import httplib
import json
import math
import re
import time
@ -32,6 +31,7 @@ from nova.api.openstack.compute.views import limits as limits_views
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
from nova import quota
from nova import wsgi as base_wsgi
@ -418,7 +418,7 @@ class WsgiLimiter(object):
raise webob.exc.HTTPMethodNotAllowed()
try:
info = dict(json.loads(request.body))
info = dict(jsonutils.loads(request.body))
except ValueError:
raise webob.exc.HTTPBadRequest()
@ -449,7 +449,7 @@ class WsgiLimiterProxy(object):
self.limiter_address = limiter_address
def check_for_delay(self, verb, path, username=None):
body = json.dumps({"verb": verb, "path": path})
body = jsonutils.dumps({"verb": verb, "path": path})
headers = {"Content-Type": "application/json"}
conn = httplib.HTTPConnection(self.limiter_address)

View File

@ -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

View File

@ -18,11 +18,11 @@
"""VMRC console drivers."""
import base64
import json
from nova import exception
from nova import flags
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
from nova.virt.vmwareapi import vim_util
@ -95,9 +95,9 @@ class VMRCConsole(object):
break
if vm_ref is None:
raise exception.InstanceNotFound(instance_id=instance_name)
json_data = json.dumps({'vm_id': vm_ds_path_name,
'username': username,
'password': password})
json_data = jsonutils.dumps({'vm_id': vm_ds_path_name,
'username': username,
'password': password})
return base64.b64encode(json_data)
def is_otp(self):
@ -133,9 +133,9 @@ class VMRCSessionConsole(VMRCConsole):
vim_session._get_vim(),
'AcquireCloneTicket',
vim_session._get_vim().get_service_content().sessionManager)
json_data = json.dumps({'vm_id': str(vm_ref.value),
'username': virtual_machine_ticket,
'password': virtual_machine_ticket})
json_data = jsonutils.dumps({'vm_id': str(vm_ref.value),
'username': virtual_machine_ticket,
'password': virtual_machine_ticket})
return base64.b64encode(json_data)
def is_otp(self):

View File

@ -20,7 +20,6 @@
from __future__ import absolute_import
import copy
import json
import random
import sys
import time
@ -32,6 +31,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
from nova import utils
@ -416,13 +416,13 @@ def _parse_glance_iso8601_timestamp(timestamp):
def _json_loads(properties, attr):
prop = properties[attr]
if isinstance(prop, basestring):
properties[attr] = json.loads(prop)
properties[attr] = jsonutils.loads(prop)
def _json_dumps(properties, attr):
prop = properties[attr]
if not isinstance(prop, basestring):
properties[attr] = json.dumps(prop)
properties[attr] = jsonutils.dumps(prop)
_CONVERT_PROPS = ('block_device_mapping', 'mappings')

View File

@ -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):

View File

@ -15,10 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import netaddr
from nova import exception
from nova.openstack.common import jsonutils
def ensure_string_keys(d):
@ -271,11 +271,11 @@ class NetworkInfo(list):
@classmethod
def hydrate(cls, network_info):
if isinstance(network_info, basestring):
network_info = json.loads(network_info)
network_info = jsonutils.loads(network_info)
return NetworkInfo([VIF.hydrate(vif) for vif in network_info])
def json(self):
return json.dumps(self)
return jsonutils.dumps(self)
def legacy(self):
"""

View File

@ -16,7 +16,6 @@
# under the License.
import httplib
import json
import socket
import time
import urllib
@ -25,6 +24,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
melange_opts = [
@ -111,13 +111,13 @@ class MelangeConnection(object):
"belonging to |%(project_id)s| ") % locals())
tenant_scope = "/tenants/%s" % (network_tenant_id
if network_tenant_id else "")
request_body = (json.dumps(dict(network=dict(mac_address=mac_address,
tenant_id=project_id)))
if mac_address else None)
network_info = dict(network=dict(mac_address=mac_address,
tenant_id=project_id))
request_body = jsonutils.dumps(network_info) if mac_address else None
url = ("ipam%(tenant_scope)s/networks/%(network_id)s/"
"interfaces/%(vif_id)s/ip_allocations" % locals())
response = self.post(url, body=request_body, headers=json_content_type)
return json.loads(response)['ip_addresses']
return jsonutils.loads(response)['ip_addresses']
def create_block(self, network_id, cidr,
project_id=None, gateway=None, dns1=None, dns2=None):
@ -128,7 +128,9 @@ class MelangeConnection(object):
req_params = dict(ip_block=dict(cidr=cidr, network_id=network_id,
type='private', gateway=gateway,
dns1=dns1, dns2=dns2))
self.post(url, body=json.dumps(req_params), headers=json_content_type)
self.post(url,
body=jsonutils.dumps(req_params),
headers=json_content_type)
def delete_block(self, block_id, project_id=None):
tenant_scope = "/tenants/%s" % project_id if project_id else ""
@ -143,7 +145,7 @@ class MelangeConnection(object):
url = "ipam%(tenant_scope)s/ip_blocks" % locals()
response = self.get(url, headers=json_content_type)
return json.loads(response)
return jsonutils.loads(response)
def get_routes(self, block_id, project_id=None):
tenant_scope = "/tenants/%s" % project_id if project_id else ""
@ -152,7 +154,7 @@ class MelangeConnection(object):
locals())
response = self.get(url, headers=json_content_type)
return json.loads(response)['ip_routes']
return jsonutils.loads(response)['ip_routes']
def get_allocated_ips(self, network_id, vif_id, project_id=None):
tenant_scope = "/tenants/%s" % project_id if project_id else ""
@ -161,7 +163,7 @@ class MelangeConnection(object):
"interfaces/%(vif_id)s/ip_allocations" % locals())
response = self.get(url, headers=json_content_type)
return json.loads(response)['ip_addresses']
return jsonutils.loads(response)['ip_addresses']
def get_allocated_ips_by_address(self, address):
url = "ipam/allocated_ip_addresses"
@ -169,7 +171,7 @@ class MelangeConnection(object):
response = self.get(url, params={'address': address},
headers=json_content_type)
return json.loads(response).get('ip_addresses', [])
return jsonutils.loads(response).get('ip_addresses', [])
def get_allocated_ips_for_network(self, network_id, project_id=None):
tenant_scope = "/tenants/%s" % project_id if project_id else ""
@ -177,7 +179,7 @@ class MelangeConnection(object):
# TODO(bgh): This request fails if you add the ".json" to the end so
# it has to call do_request itself. Melange bug?
response = self.do_request("GET", url, content_type="")
return json.loads(response)['ip_addresses']
return jsonutils.loads(response)['ip_addresses']
def deallocate_ips(self, network_id, vif_id, project_id=None):
tenant_scope = "/tenants/%s" % project_id if project_id else ""
@ -193,7 +195,8 @@ class MelangeConnection(object):
request_body = dict(interface=dict(id=vif_id, tenant_id=project_id,
device_id=instance_id))
response = self.post(url, body=json.dumps(request_body),
response = self.post(url,
body=jsonutils.dumps(request_body),
headers=json_content_type)
return json.loads(response)['interface']['mac_address']
return jsonutils.loads(response)['interface']['mac_address']

View File

@ -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))

View File

@ -17,11 +17,12 @@
"""Common Policy Engine Implementation"""
import json
import logging
import urllib
import urllib2
from nova.openstack.common import jsonutils
LOG = logging.getLogger(__name__)
@ -132,7 +133,7 @@ class Brain(object):
@classmethod
def load_json(cls, data, default_rule=None):
"""Init a brain using json instead of a rules dictionary."""
rules_dict = json.loads(data)
rules_dict = jsonutils.loads(data)
return cls(rules=rules_dict, default_rule=default_rule)
def __init__(self, rules=None, default_rule=None):
@ -231,8 +232,8 @@ class HttpBrain(Brain):
"""
url = match % target_dict
data = {'target': json.dumps(target_dict),
'credentials': json.dumps(cred_dict)}
data = {'target': jsonutils.dumps(target_dict),
'credentials': jsonutils.dumps(cred_dict)}
post_data = urllib.urlencode(data)
f = urllib2.urlopen(url, post_data)
return f.read() == "True"

View File

@ -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):

View File

@ -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)

View File

@ -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):

View File

@ -14,9 +14,9 @@
# under the License.
import json
import operator
from nova.openstack.common import jsonutils
from nova.scheduler import filters
@ -138,7 +138,7 @@ class JsonFilter(filters.BaseHostFilter):
# NOTE(comstud): Not checking capabilities or service for
# enabled/disabled so that a provided json filter can decide
result = self._process_filter(json.loads(query), host_state)
result = self._process_filter(jsonutils.loads(query), host_state)
if isinstance(result, list):
# If any succeeded, include the host
result = any(result)

View File

@ -45,13 +45,13 @@ the Open Attestation project at:
"""
import httplib
import json
import socket
import ssl
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
from nova.scheduler import filters
@ -155,7 +155,7 @@ class AttestationService(httplib.HTTPSConnection):
body = {}
body['count'] = 1
body['hosts'] = host
cooked = json.dumps(body)
cooked = jsonutils.dumps(body)
headers = {}
headers['content-type'] = 'application/json'
headers['Accept'] = 'application/json'
@ -164,7 +164,7 @@ class AttestationService(httplib.HTTPSConnection):
status, res = self._do_request(cmd, subcmd, cooked, headers)
if status == httplib.OK:
data = res.read()
return status, json.loads(data)
return status, jsonutils.loads(data)
else:
return status, None

View File

@ -15,10 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova.openstack.common import jsonutils
def webob_factory(url):
"""Factory for removing duplicate webob code from tests"""
@ -31,7 +31,7 @@ def webob_factory(url):
req.content_type = "application/json"
req.method = method
if body:
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
return req
return web_request

View File

@ -13,14 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
from nova.api.openstack.compute.contrib import accounts
from nova.auth import manager as auth_manager
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -51,7 +49,7 @@ class AccountsTest(test.TestCase):
def test_get_account(self):
req = webob.Request.blank('/v2/fake/accounts/test1')
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['account']['id'], 'test1')
@ -82,10 +80,10 @@ class AccountsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/accounts/newacct')
req.headers["Content-Type"] = "application/json"
req.method = 'PUT'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['account']['id'], 'newacct')
@ -102,7 +100,7 @@ class AccountsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/accounts/newacct.xml')
req.headers["Content-Type"] = "application/json"
req.method = 'PUT'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
res_tree = etree.fromstring(res.body)
@ -123,10 +121,10 @@ class AccountsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/accounts/test1')
req.headers["Content-Type"] = "application/json"
req.method = 'PUT'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['account']['id'], 'test1')
@ -141,7 +139,7 @@ class AccountsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/accounts/test1.xml')
req.headers["Content-Type"] = "application/json"
req.method = 'PUT'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
res_tree = etree.fromstring(res.body)

View File

@ -13,7 +13,6 @@
# under the License.
import datetime
import json
import webob
@ -23,6 +22,7 @@ from nova.compute import vm_states
from nova import context
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import test
from nova.tests.api.openstack import fakes
@ -98,7 +98,7 @@ class AdminActionsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/servers/%s/action' %
self.UUID)
req.method = 'POST'
req.body = json.dumps({_action: None})
req.body = jsonutils.dumps({_action: None})
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 202)
@ -113,7 +113,7 @@ class AdminActionsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/servers/%s/action' %
self.UUID)
req.method = 'POST'
req.body = json.dumps({_action: None})
req.body = jsonutils.dumps({_action: None})
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 409)
@ -128,9 +128,13 @@ class AdminActionsTest(test.TestCase):
app = fakes.wsgi_app(fake_auth_context=ctxt)
req = webob.Request.blank('/v2/fake/servers/%s/action' % self.UUID)
req.method = 'POST'
req.body = json.dumps({'os-migrateLive': {'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}})
req.body = jsonutils.dumps({
'os-migrateLive': {
'host': 'hostname',
'block_migration': False,
'disk_over_commit': False,
}
})
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 202)
@ -143,9 +147,13 @@ class AdminActionsTest(test.TestCase):
app = fakes.wsgi_app(fake_auth_context=ctxt)
req = webob.Request.blank('/v2/fake/servers/%s/action' % self.UUID)
req.method = 'POST'
req.body = json.dumps({'os-migrateLive': {'dummy': 'hostname',
'block_migration': False,
'disk_over_commit': False}})
req.body = jsonutils.dumps({
'os-migrateLive': {
'dummy': 'hostname',
'block_migration': False,
'disk_over_commit': False,
}
})
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 400)
@ -166,7 +174,7 @@ class CreateBackupTests(test.TestCase):
req = fakes.HTTPRequest.blank(url)
req.method = 'POST'
req.content_type = 'application/json'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
return req
def test_create_backup_with_metadata(self):

View File

@ -13,12 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova import compute
from nova import exception
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -56,11 +55,11 @@ class ConsoleOutputExtensionTest(test.TestCase):
body = {'os-getConsoleOutput': {}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
output = json.loads(res.body)
output = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(output, {'output': '0\n1\n2\n3\n4'})
@ -68,10 +67,10 @@ class ConsoleOutputExtensionTest(test.TestCase):
body = {'os-getConsoleOutput': {'length': 3}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
output = json.loads(res.body)
output = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(output, {'output': '2\n3\n4'})
@ -80,7 +79,7 @@ class ConsoleOutputExtensionTest(test.TestCase):
body = {'os-getConsoleOutput': {}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
@ -91,7 +90,7 @@ class ConsoleOutputExtensionTest(test.TestCase):
body = {'os-getConsoleOutput': {}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
@ -101,7 +100,7 @@ class ConsoleOutputExtensionTest(test.TestCase):
body = {}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())

View File

@ -13,12 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova import compute
from nova import exception
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -52,11 +51,11 @@ class ConsolesExtensionTest(test.TestCase):
body = {'os-getVNCConsole': {'type': 'novnc'}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
output = json.loads(res.body)
output = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(output,
{u'console': {u'url': u'http://fake', u'type': u'novnc'}})
@ -66,7 +65,7 @@ class ConsolesExtensionTest(test.TestCase):
body = {'os-getVNCConsole': {}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
@ -77,7 +76,7 @@ class ConsolesExtensionTest(test.TestCase):
body = {'os-getVNCConsole': {'type': 'novnc'}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
@ -88,7 +87,7 @@ class ConsolesExtensionTest(test.TestCase):
body = {'os-getVNCConsole': {'type': 'novnc'}}
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
@ -101,7 +100,7 @@ class ConsolesExtensionTest(test.TestCase):
fake_get_vnc_console_invalid_type)
req = webob.Request.blank('/v2/fake/servers/1/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())

View File

@ -16,7 +16,6 @@
# under the License.
import base64
import json
from xml.dom import minidom
import webob
@ -25,6 +24,7 @@ import nova
from nova import db
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -145,7 +145,7 @@ class CreateserverextTest(test.TestCase):
req = webob.Request.blank('/v2/fake/os-create-server-ext')
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
req.body = json.dumps(body_dict)
req.body = jsonutils.dumps(body_dict)
return req
def _run_create_instance_with_mock_compute_api(self, request):
@ -374,7 +374,7 @@ class CreateserverextTest(test.TestCase):
req.headers['Content-Type'] = 'application/json'
response = req.get_response(fakes.wsgi_app())
self.assertEquals(response.status_int, 200)
res_dict = json.loads(response.body)
res_dict = jsonutils.loads(response.body)
expected_security_group = [{"name": "test"}]
self.assertEquals(res_dict['server']['security_groups'],
expected_security_group)

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
@ -22,6 +20,7 @@ from nova.api.openstack.compute.contrib import extended_server_attributes
from nova import compute
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -62,10 +61,10 @@ class ExtendedServerAttributesTest(test.TestCase):
return res
def _get_server(self, body):
return json.loads(body).get('server')
return jsonutils.loads(body).get('server')
def _get_servers(self, body):
return json.loads(body).get('servers')
return jsonutils.loads(body).get('servers')
def assertServerAttributes(self, server, host, instance_name):
self.assertEqual(server.get('%shost' % self.prefix), host)

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
@ -22,6 +20,7 @@ from nova.api.openstack.compute.contrib import extended_status
from nova import compute
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -65,10 +64,10 @@ class ExtendedStatusTest(test.TestCase):
return res
def _get_server(self, body):
return json.loads(body).get('server')
return jsonutils.loads(body).get('server')
def _get_servers(self, body):
return json.loads(body).get('servers')
return jsonutils.loads(body).get('servers')
def assertServerStates(self, server, vm_state, power_state, task_state):
self.assertEqual(server.get('%svm_state' % self.prefix), vm_state)

View File

@ -14,13 +14,13 @@
# under the License.
import datetime
import json
import webob
from nova.api.openstack.compute.contrib import flavormanage
from nova.compute import instance_types
from nova import exception
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -107,9 +107,9 @@ class FlavorManageTest(test.TestCase):
req = webob.Request.blank(url)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
req.body = json.dumps(expected)
req.body = jsonutils.dumps(expected)
res = req.get_response(fakes.wsgi_app())
body = json.loads(res.body)
body = jsonutils.loads(res.body)
for key in expected["flavor"]:
self.assertEquals(body["flavor"][key], expected["flavor"][key])
@ -136,6 +136,6 @@ class FlavorManageTest(test.TestCase):
req = webob.Request.blank(url)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
req.body = json.dumps(expected)
req.body = jsonutils.dumps(expected)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 409)

View File

@ -14,11 +14,11 @@
# under the License.
import datetime
import json
import webob
from nova.compute import instance_types
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -79,7 +79,7 @@ class FlavorextradataTest(test.TestCase):
req = webob.Request.blank(url)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self._verify_server_response(body['flavor'], expected['flavor'])
def test_detail(self):
@ -110,6 +110,6 @@ class FlavorextradataTest(test.TestCase):
req = webob.Request.blank(url)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
body = json.loads(res.body)
body = jsonutils.loads(res.body)
for i, flavor in enumerate(body['flavors']):
self._verify_server_response(flavor, expected[i])

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
@ -22,6 +20,7 @@ from nova.api.openstack.compute.contrib import keypairs
from nova.api.openstack import wsgi
from nova import db
from nova import exception
from nova.openstack.common import jsonutils
from nova import quota
from nova import test
from nova.tests.api.openstack import fakes
@ -70,7 +69,7 @@ class KeypairsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/os-keypairs')
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
response = {'keypairs': [{'keypair': fake_keypair('FAKE')}]}
self.assertEqual(res_dict, response)
@ -78,11 +77,11 @@ class KeypairsTest(test.TestCase):
body = {'keypair': {'name': 'create_test'}}
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
self.assertTrue(len(res_dict['keypair']['fingerprint']) > 0)
self.assertTrue(len(res_dict['keypair']['private_key']) > 0)
@ -90,7 +89,7 @@ class KeypairsTest(test.TestCase):
body = {'keypair': {'name': ''}}
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
@ -103,7 +102,7 @@ class KeypairsTest(test.TestCase):
}
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
@ -116,10 +115,10 @@ class KeypairsTest(test.TestCase):
}
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 400)
def test_keypair_create_quota_limit(self):
@ -133,7 +132,7 @@ class KeypairsTest(test.TestCase):
req.method = 'POST'
req.headers['Content-Type'] = 'application/json'
body = {'keypair': {'name': 'foo'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 413)
@ -155,12 +154,12 @@ class KeypairsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
# FIXME(ja): sholud we check that public_key was sent to create?
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
self.assertTrue(len(res_dict['keypair']['fingerprint']) > 0)
self.assertFalse('private_key' in res_dict['keypair'])
@ -188,7 +187,7 @@ class KeypairsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 413)
@ -208,7 +207,7 @@ class KeypairsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 413)
@ -218,7 +217,7 @@ class KeypairsTest(test.TestCase):
body = {'keypair': {'name': 'create_duplicate'}}
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 409)
@ -233,7 +232,7 @@ class KeypairsTest(test.TestCase):
req = webob.Request.blank('/v2/fake/os-keypairs')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)

View File

@ -13,11 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova import compute
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -61,7 +60,7 @@ class FixedIpTest(test.TestCase):
body = dict(addFixedIp=dict(networkId='test_net'))
req = webob.Request.blank('/v2/fake/servers/%s/action' % UUID)
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
@ -75,7 +74,7 @@ class FixedIpTest(test.TestCase):
body = dict(addFixedIp=dict())
req = webob.Request.blank('/v2/fake/servers/%s/action' % UUID)
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
@ -89,7 +88,7 @@ class FixedIpTest(test.TestCase):
body = dict(removeFixedIp=dict(address='10.10.10.1'))
req = webob.Request.blank('/v2/fake/servers/%s/action' % UUID)
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
@ -103,7 +102,7 @@ class FixedIpTest(test.TestCase):
body = dict(removeFixedIp=dict())
req = webob.Request.blank('/v2/fake/servers/%s/action' % UUID)
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())

View File

@ -12,13 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova import compute
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -49,24 +48,24 @@ class RescueTest(test.TestCase):
body = {"rescue": {"adminPass": "AABBCC112233"}}
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(fakes.wsgi_app())
self.assertEqual(resp.status_int, 200)
resp_json = json.loads(resp.body)
resp_json = jsonutils.loads(resp.body)
self.assertEqual("AABBCC112233", resp_json['adminPass'])
def test_rescue_generates_password(self):
body = dict(rescue=None)
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(fakes.wsgi_app())
self.assertEqual(resp.status_int, 200)
resp_json = json.loads(resp.body)
resp_json = jsonutils.loads(resp.body)
self.assertEqual(FLAGS.password_length, len(resp_json['adminPass']))
def test_rescue_of_rescued_instance(self):
@ -78,7 +77,7 @@ class RescueTest(test.TestCase):
self.stubs.Set(compute.api.API, "rescue", fake_rescue)
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(fakes.wsgi_app())
@ -88,7 +87,7 @@ class RescueTest(test.TestCase):
body = dict(unrescue=None)
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(fakes.wsgi_app())
@ -103,7 +102,7 @@ class RescueTest(test.TestCase):
self.stubs.Set(compute.api.API, "unrescue", fake_unrescue)
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(fakes.wsgi_app())

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import unittest
from lxml import etree
@ -22,6 +21,7 @@ from nova.api.openstack import compute
from nova.api.openstack.compute.contrib import server_diagnostics
from nova.api.openstack import wsgi
import nova.compute
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
import nova.utils
@ -54,7 +54,7 @@ class ServerDiagnosticsTest(test.TestCase):
def test_get_diagnostics(self):
req = fakes.HTTPRequest.blank('/fake/servers/%s/diagnostics' % UUID)
res = req.get_response(self.router)
output = json.loads(res.body)
output = jsonutils.loads(res.body)
self.assertEqual(output, {'data': 'Some diagnostic info'})

View File

@ -16,7 +16,6 @@
# under the License.
import datetime
import json
from lxml import etree
import webob
@ -25,6 +24,7 @@ from nova.api.openstack.compute.contrib import simple_tenant_usage
from nova.compute import api
from nova import context
from nova import flags
from nova.openstack.common import jsonutils
from nova.openstack.common import policy as common_policy
from nova import policy
from nova import test
@ -103,7 +103,7 @@ class SimpleTenantUsageTest(test.TestCase):
fake_auth_context=self.admin_context))
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
usages = res_dict['tenant_usages']
for i in xrange(TENANTS):
self.assertEqual(int(usages[i]['total_hours']),
@ -127,7 +127,7 @@ class SimpleTenantUsageTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.admin_context))
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
return res_dict['tenant_usages']
def test_verify_detailed_index(self):
@ -159,7 +159,7 @@ class SimpleTenantUsageTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_context))
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
usage = res_dict['tenant_usage']
servers = usage['server_usages']

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
@ -23,6 +21,7 @@ from nova import context
from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
from nova import utils
@ -117,7 +116,7 @@ class SnapshotApiTest(test.TestCase):
body = dict(snapshot=snapshot)
req = webob.Request.blank('/v2/fake/os-snapshots')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
@ -129,7 +128,7 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(_last_param['display_description'],
"Snapshot Test Desc")
resp_dict = json.loads(resp.body)
resp_dict = jsonutils.loads(resp.body)
LOG.debug(_("test_snapshot_create: resp_dict=%s"), resp_dict)
self.assertTrue('snapshot' in resp_dict)
self.assertEqual(resp_dict['snapshot']['displayName'],
@ -148,7 +147,7 @@ class SnapshotApiTest(test.TestCase):
body = dict(snapshot=snapshot)
req = webob.Request.blank('/v2/fake/os-snapshots')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
@ -160,7 +159,7 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(_last_param['display_description'],
"Snapshot Test Desc")
resp_dict = json.loads(resp.body)
resp_dict = jsonutils.loads(resp.body)
LOG.debug(_("test_snapshot_create_force: resp_dict=%s"), resp_dict)
self.assertTrue('snapshot' in resp_dict)
self.assertEqual(resp_dict['snapshot']['displayName'],
@ -205,7 +204,7 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(resp.status_int, 200)
self.assertEqual(str(_last_param['snapshot_id']), str(snapshot_id))
resp_dict = json.loads(resp.body)
resp_dict = jsonutils.loads(resp.body)
self.assertTrue('snapshot' in resp_dict)
self.assertEqual(resp_dict['snapshot']['id'], str(snapshot_id))
@ -226,7 +225,7 @@ class SnapshotApiTest(test.TestCase):
resp = req.get_response(fakes.wsgi_app())
self.assertEqual(resp.status_int, 200)
resp_dict = json.loads(resp.body)
resp_dict = jsonutils.loads(resp.body)
LOG.debug(_("test_snapshot_detail: resp_dict=%s"), resp_dict)
self.assertTrue('snapshots' in resp_dict)
resp_snapshots = resp_dict['snapshots']

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
@ -22,6 +20,7 @@ from nova.api.openstack.compute.contrib import virtual_interfaces
from nova.api.openstack import wsgi
from nova import compute
from nova import network
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -54,7 +53,7 @@ class ServerVirtualInterfaceTest(test.TestCase):
req = webob.Request.blank(url)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
res_dict = jsonutils.loads(res.body)
response = {'virtual_interfaces': [
{'id': '00000000-0000-0000-0000-00000000000000000',
'mac_address': '00-00-00-00-00-00'},

View File

@ -14,7 +14,6 @@
# under the License.
import datetime
import json
from lxml import etree
import webob
@ -25,6 +24,7 @@ from nova.compute import instance_types
from nova import context
import nova.db
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
from nova import utils
@ -118,11 +118,11 @@ class BootFromVolumeTest(test.TestCase):
_block_device_mapping_seen = None
req = webob.Request.blank('/v2/fake/os-volumes_boot')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
server = json.loads(res.body)['server']
server = jsonutils.loads(res.body)['server']
self.assertEqual(FAKE_UUID, server['id'])
self.assertEqual(FLAGS.password_length, len(server['adminPass']))
self.assertEqual(len(_block_device_mapping_seen), 1)
@ -160,13 +160,13 @@ class VolumeApiTest(test.TestCase):
body = {"volume": vol}
req = webob.Request.blank('/v2/fake/os-volumes')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
self.assertEqual(resp.status_int, 200)
resp_dict = json.loads(resp.body)
resp_dict = jsonutils.loads(resp.body)
self.assertTrue('volume' in resp_dict)
self.assertEqual(resp_dict['volume']['size'],
vol['size'])
@ -180,7 +180,7 @@ class VolumeApiTest(test.TestCase):
def test_volume_create_no_body(self):
req = webob.Request.blank('/v2/fake/os-volumes')
req.method = 'POST'
req.body = json.dumps({})
req.body = jsonutils.dumps({})
req.headers['content-type'] = 'application/json'
resp = req.get_response(fakes.wsgi_app())
@ -242,7 +242,7 @@ class VolumeAttachTests(test.TestCase):
attachments = volumes.VolumeAttachmentController()
req = webob.Request.blank('/v2/fake/os-volumes/show')
req.method = 'POST'
req.body = json.dumps({})
req.body = jsonutils.dumps({})
req.headers['content-type'] = 'application/json'
req.environ['nova.context'] = self.context
@ -254,7 +254,7 @@ class VolumeAttachTests(test.TestCase):
attachments = volumes.VolumeAttachmentController()
req = webob.Request.blank('/v2/fake/os-volumes/delete')
req.method = 'POST'
req.body = json.dumps({})
req.body = jsonutils.dumps({})
req.headers['content-type'] = 'application/json'
req.environ['nova.context'] = self.context
@ -266,7 +266,7 @@ class VolumeAttachTests(test.TestCase):
attachments = volumes.VolumeAttachmentController()
req = webob.Request.blank('/v2/fake/os-volumes/delete')
req.method = 'POST'
req.body = json.dumps({})
req.body = jsonutils.dumps({})
req.headers['content-type'] = 'application/json'
req.environ['nova.context'] = self.context
@ -283,7 +283,7 @@ class VolumeAttachTests(test.TestCase):
'device': '/dev/fake'}}
req = webob.Request.blank('/v2/fake/os-volumes/attach')
req.method = 'POST'
req.body = json.dumps({})
req.body = jsonutils.dumps({})
req.headers['content-type'] = 'application/json'
req.environ['nova.context'] = self.context
result = attachments.create(req, FAKE_UUID, body)

View File

@ -15,8 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from lxml import etree
import webob
import webob.dec
@ -25,6 +23,7 @@ import webob.exc
from nova.api import openstack as openstack_api
from nova.api.openstack import wsgi
import nova.context
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -63,7 +62,7 @@ class APITest(test.TestCase):
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, ctype)
body = json.loads(res.body)
body = jsonutils.loads(res.body)
def test_vendor_content_type_xml(self):
ctype = 'application/vnd.openstack.compute+xml'

View File

@ -16,8 +16,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import iso8601
from lxml import etree
import webob
@ -28,6 +26,7 @@ from nova.api.openstack import extensions as base_extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -197,7 +196,7 @@ class ExtensionControllerTest(ExtensionTestCase):
self.assertEqual(200, response.status_int)
# Make sure we have all the extensions, extra extensions being OK.
data = json.loads(response.body)
data = jsonutils.loads(response.body)
names = [str(x['name']) for x in data['extensions']
if str(x['name']) in self.ext_list]
names.sort()
@ -224,7 +223,7 @@ class ExtensionControllerTest(ExtensionTestCase):
url = '/fake/extensions/%s' % ext['alias']
request = webob.Request.blank(url)
response = request.get_response(app)
output = json.loads(response.body)
output = jsonutils.loads(response.body)
self.assertEqual(output['extension']['alias'], ext['alias'])
def test_get_extension_json(self):
@ -233,7 +232,7 @@ class ExtensionControllerTest(ExtensionTestCase):
response = request.get_response(app)
self.assertEqual(200, response.status_int)
data = json.loads(response.body)
data = jsonutils.loads(response.body)
self.assertEqual(data['extension'], {
"namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
"name": "Fox In Socks",
@ -333,7 +332,7 @@ class ResourceExtensionTest(ExtensionTestCase):
response = request.get_response(app)
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
body = json.loads(response.body)
body = jsonutils.loads(response.body)
expected = {
"badRequest": {
"message": "All aboard the fail train!",
@ -351,7 +350,7 @@ class ResourceExtensionTest(ExtensionTestCase):
response = request.get_response(app)
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
body = json.loads(response.body)
body = jsonutils.loads(response.body)
expected = {
"itemNotFound": {
"message": "The resource could not be found.",
@ -394,7 +393,7 @@ class ActionExtensionTest(ExtensionTestCase):
request = webob.Request.blank(url)
request.method = 'POST'
request.content_type = 'application/json'
request.body = json.dumps(body)
request.body = jsonutils.dumps(body)
response = request.get_response(app)
return response
@ -416,7 +415,7 @@ class ActionExtensionTest(ExtensionTestCase):
response = self._send_server_action_request(url, body)
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
body = json.loads(response.body)
body = jsonutils.loads(response.body)
expected = {
"badRequest": {
"message": "There is no such action: blah",
@ -437,7 +436,7 @@ class ActionExtensionTest(ExtensionTestCase):
response = self._send_server_action_request(url, body)
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
body = json.loads(response.body)
body = jsonutils.loads(response.body)
expected = {
"badRequest": {
"message": "Tweedle fail",
@ -465,7 +464,7 @@ class RequestExtensionTest(ExtensionTestCase):
request.environ['api.version'] = '2'
response = request.get_response(app)
self.assertEqual(200, response.status_int)
response_data = json.loads(response.body)
response_data = jsonutils.loads(response.body)
self.assertEqual('bluegoo', response_data['flavor']['googoose'])
def test_get_resources_with_mgr(self):
@ -475,7 +474,7 @@ class RequestExtensionTest(ExtensionTestCase):
request.environ['api.version'] = '2'
response = request.get_response(app)
self.assertEqual(200, response.status_int)
response_data = json.loads(response.body)
response_data = jsonutils.loads(response.body)
self.assertEqual('newblue', response_data['flavor']['googoose'])
self.assertEqual("Pig Bands!", response_data['big_bands'])
@ -529,7 +528,7 @@ class ControllerExtensionTest(ExtensionTestCase):
request = webob.Request.blank("/fake/tweedles/foo/action")
request.method = 'POST'
request.headers['Content-Type'] = 'application/json'
request.body = json.dumps(dict(fooAction=True))
request.body = jsonutils.dumps(dict(fooAction=True))
response = request.get_response(app)
self.assertEqual(200, response.status_int)
self.assertEqual(extension_body, response.body)
@ -552,7 +551,7 @@ class ControllerExtensionTest(ExtensionTestCase):
request = webob.Request.blank("/fake/tweedles/foo/action")
request.method = 'POST'
request.headers['Content-Type'] = 'application/json'
request.body = json.dumps(dict(fooAction=True))
request.body = jsonutils.dumps(dict(fooAction=True))
response = request.get_response(app)
self.assertEqual(200, response.status_int)
self.assertEqual(extension_body, response.body)

View File

@ -15,11 +15,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova.api.openstack.compute import image_metadata
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -61,7 +61,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata')
req.method = 'POST'
body = {"metadata": {"key7": "value7"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, '123', body)
@ -72,7 +72,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/100/metadata')
req.method = 'POST'
body = {"metadata": {"key7": "value7"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
@ -82,7 +82,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata')
req.method = 'PUT'
body = {"metadata": {"key9": "value9"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.update_all(req, '123', body)
@ -93,7 +93,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/100/metadata')
req.method = 'PUT'
body = {"metadata": {"key9": "value9"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
@ -103,7 +103,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "zz"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.update(req, '123', 'key1', body)
@ -114,7 +114,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/100/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "zz"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
@ -137,7 +137,7 @@ class ImageMetaDataTest(test.TestCase):
for num in range(FLAGS.quota_metadata_items + 1):
overload['key%s' % num] = 'value%s' % num
body = {'meta': overload}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -147,7 +147,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -180,7 +180,7 @@ class ImageMetaDataTest(test.TestCase):
data['metadata']['key%i' % num] = "blah"
req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata')
req.method = 'POST'
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@ -193,7 +193,7 @@ class ImageMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata/blah')
req.method = 'PUT'
body = {"meta": {"blah": "blah"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,

View File

@ -18,7 +18,6 @@ Tests dealing with HTTP rate-limiting.
"""
import httplib
import json
import StringIO
import unittest
from xml.dom import minidom
@ -32,6 +31,7 @@ from nova.api.openstack.compute import views
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
import nova.context
from nova.openstack.common import jsonutils
from nova import test
@ -112,7 +112,7 @@ class LimitsControllerTest(BaseLimitTestSuite):
"absolute": {},
},
}
body = json.loads(response.body)
body = jsonutils.loads(response.body)
self.assertEqual(expected, body)
def test_index_json(self):
@ -170,7 +170,7 @@ class LimitsControllerTest(BaseLimitTestSuite):
},
},
}
body = json.loads(response.body)
body = jsonutils.loads(response.body)
self.assertEqual(expected, body)
def _populate_limits_diff_regex(self, request):
@ -221,13 +221,13 @@ class LimitsControllerTest(BaseLimitTestSuite):
"absolute": {},
},
}
body = json.loads(response.body)
body = jsonutils.loads(response.body)
self.assertEqual(expected, body)
def _test_index_absolute_limits_json(self, expected):
request = self._get_index_request()
response = request.get_response(self.controller)
body = json.loads(response.body)
body = jsonutils.loads(response.body)
self.assertEqual(expected, body['limits']['absolute'])
def test_index_ignores_extra_absolute_limits_json(self):
@ -314,7 +314,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
retry_after = int(response.headers['Retry-After'])
self.assertAlmostEqual(retry_after, 60, 1)
body = json.loads(response.body)
body = jsonutils.loads(response.body)
expected = "Only 1 GET request(s) can be made to * every minute."
value = body["overLimitFault"]["details"].strip()
self.assertEqual(value, expected)
@ -604,7 +604,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
def _request_data(self, verb, path):
"""Get data decribing a limit request verb/path."""
return json.dumps({"verb": verb, "path": path})
return jsonutils.dumps({"verb": verb, "path": path})
def _request(self, verb, url, username=None):
"""Make sure that POSTing to the given url causes the given username

View File

@ -15,13 +15,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova.api.openstack.compute import server_metadata
import nova.db
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
from nova import utils
@ -185,7 +185,7 @@ class ServerMetaDataTest(test.TestCase):
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res_dict = self.controller.create(req, self.uuid, body)
body['metadata'].update({
@ -211,7 +211,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -223,7 +223,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -236,7 +236,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url)
req.method = 'POST'
body = {"metadata": {"key1": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
@ -254,7 +254,7 @@ class ServerMetaDataTest(test.TestCase):
'key99': 'value99',
},
}
req.body = json.dumps(expected)
req.body = jsonutils.dumps(expected)
res_dict = self.controller.update_all(req, self.uuid, expected)
self.assertEqual(expected, res_dict)
@ -266,7 +266,7 @@ class ServerMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': {}}
req.body = json.dumps(expected)
req.body = jsonutils.dumps(expected)
res_dict = self.controller.update_all(req, self.uuid, expected)
self.assertEqual(expected, res_dict)
@ -278,7 +278,7 @@ class ServerMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
expected = {'meta': {}}
req.body = json.dumps(expected)
req.body = jsonutils.dumps(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.uuid, expected)
@ -290,7 +290,7 @@ class ServerMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': ['asdf']}
req.body = json.dumps(expected)
req.body = jsonutils.dumps(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.uuid, expected)
@ -301,7 +301,7 @@ class ServerMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
body = {'metadata': {'key10': 'value10'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.update_all, req, '100', body)
@ -312,7 +312,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res_dict = self.controller.update(req, self.uuid, 'key1', body)
expected = {'meta': {'key1': 'value1'}}
@ -324,7 +324,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/asdf/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
@ -346,7 +346,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -358,7 +358,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -371,7 +371,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": ("a" * 260)}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -384,7 +384,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -396,7 +396,7 @@ class ServerMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -410,7 +410,7 @@ class ServerMetaDataTest(test.TestCase):
data['metadata']['key%i' % num] = "blah"
req = fakes.HTTPRequest.blank(self.url)
req.method = 'POST'
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@ -425,19 +425,19 @@ class ServerMetaDataTest(test.TestCase):
#test for long key
data = {"metadata": {"a" * 260: "value1"}}
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.uuid, data)
#test for long value
data = {"metadata": {"key": "v" * 260}}
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.uuid, data)
#test for empty key.
data = {"metadata": {"": "value1"}}
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.uuid, data)
@ -449,7 +449,7 @@ class ServerMetaDataTest(test.TestCase):
data['metadata']['key%i' % num] = "blah"
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@ -463,23 +463,23 @@ class ServerMetaDataTest(test.TestCase):
data['metadata']['key%i' % num] = "blah"
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
req.headers["content-type"] = "application/json"
#test for long key
data = {"metadata": {"a" * 260: "value1"}}
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.uuid, data)
#test for long value
data = {"metadata": {"key": "v" * 260}}
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.uuid, data)
#test for empty key.
data = {"metadata": {"": "value1"}}
req.body = json.dumps(data)
req.body = jsonutils.dumps(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.uuid, data)

View File

@ -17,7 +17,6 @@
# under the License.
import datetime
import json
import urlparse
import iso8601
@ -37,6 +36,7 @@ import nova.db
from nova.db.sqlalchemy import models
from nova import flags
import nova.image.fake
from nova.openstack.common import jsonutils
import nova.rpc
from nova import test
from nova.tests.api.openstack import fakes
@ -872,7 +872,7 @@ class ServersControllerTest(test.TestCase):
'accessIPv4': '0.0.0.0',
'accessIPv6': 'beef::0123',
}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res_dict = self.controller.update(req, FAKE_UUID, body)
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
@ -887,7 +887,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'name': 'server_test'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res_dict = self.controller.update(req, FAKE_UUID, body)
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
@ -900,7 +900,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'name': 'x' * 256}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
req, FAKE_UUID, body)
@ -911,7 +911,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'accessIPv4': '0.0.0.0'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res_dict = self.controller.update(req, FAKE_UUID, body)
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
@ -924,7 +924,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'accessIPv4': 'bad_format'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
req, FAKE_UUID, body)
@ -935,7 +935,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'accessIPv6': 'beef::0123'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res_dict = self.controller.update(req, FAKE_UUID, body)
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
@ -948,7 +948,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'accessIPv6': 'bad_format'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
req, FAKE_UUID, body)
@ -972,7 +972,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID)
req.method = 'PUT'
req.content_type = "application/json"
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
res_dict = self.controller.update(req, FAKE_UUID, body)
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
@ -987,7 +987,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'name': 'server_test'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
req, FAKE_UUID, body)
@ -1000,7 +1000,7 @@ class ServersControllerTest(test.TestCase):
req.method = 'PUT'
req.content_type = 'application/json'
body = {'server': {'name': 'server_test'}}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
req, FAKE_UUID, body)
@ -1033,7 +1033,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1067,7 +1067,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1101,7 +1101,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1135,7 +1135,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1162,7 +1162,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1189,7 +1189,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1223,7 +1223,7 @@ class ServersControllerTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers/a/action')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, req, FAKE_UUID, body)
@ -1517,7 +1517,7 @@ class ServersControllerCreateTest(test.TestCase):
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
server = self.controller.create(req, body).obj['server']
@ -1538,7 +1538,7 @@ class ServersControllerCreateTest(test.TestCase):
}
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
@ -1565,7 +1565,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1593,7 +1593,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1621,7 +1621,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body)
@ -1644,7 +1644,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1665,7 +1665,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, body)
@ -1703,7 +1703,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1743,7 +1743,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1780,7 +1780,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, body)
@ -1814,7 +1814,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, body)
@ -1845,7 +1845,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, body)
@ -1876,7 +1876,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1911,7 +1911,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -1939,7 +1939,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@ -1963,7 +1963,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -1987,7 +1987,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2011,7 +2011,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2025,7 +2025,7 @@ class ServersControllerCreateTest(test.TestCase):
key_name='nonexistentkey'))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2039,7 +2039,7 @@ class ServersControllerCreateTest(test.TestCase):
key_name='key'))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -2055,7 +2055,7 @@ class ServersControllerCreateTest(test.TestCase):
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2070,7 +2070,7 @@ class ServersControllerCreateTest(test.TestCase):
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2085,7 +2085,7 @@ class ServersControllerCreateTest(test.TestCase):
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2110,7 +2110,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -2136,7 +2136,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -2162,7 +2162,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2187,7 +2187,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -2203,7 +2203,7 @@ class ServersControllerCreateTest(test.TestCase):
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2222,7 +2222,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = self.controller.create(req, body).obj
@ -2242,7 +2242,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = "application/json"
res = self.controller.create(req, body).obj
@ -2263,7 +2263,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = "application/json"
res = self.controller.create(req, body).obj
@ -2284,7 +2284,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = "application/json"
# The fact that the action doesn't raise is enough validation
@ -2294,7 +2294,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
body = {'server': 'string'}
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -2326,7 +2326,7 @@ class ServersControllerCreateTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers['content-type'] = 'application/json'
robj = self.controller.create(req, body)
@ -2341,7 +2341,7 @@ class ServersControllerCreateTest(test.TestCase):
personality={}))
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
try:
server = self.controller.create(req, body).obj['server']

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import webob
from nova import log as logging
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
@ -35,7 +35,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['version']['id'], 'v2.0')
def test_content_type_version_v1_1(self):
@ -46,7 +46,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['version']['id'], 'v2.0')
def test_accept_version_v1_1(self):
@ -56,7 +56,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['version']['id'], 'v2.0')
def test_path_version_v2(self):
@ -66,7 +66,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['version']['id'], 'v2.0')
def test_content_type_version_v2(self):
@ -77,7 +77,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['version']['id'], 'v2.0')
def test_accept_version_v2(self):
@ -87,7 +87,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['version']['id'], 'v2.0')
def test_path_content_type(self):
@ -98,7 +98,7 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['image']['id'],
'cedef40a-ed67-4d10-800e-17455edce175')
@ -110,6 +110,6 @@ class UrlmapTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
body = json.loads(res.body)
body = jsonutils.loads(res.body)
self.assertEqual(body['image']['id'],
'cedef40a-ed67-4d10-800e-17455edce175')

View File

@ -15,8 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import feedparser
from lxml import etree
import webob
@ -24,6 +22,7 @@ import webob
from nova.api.openstack.compute import versions
from nova.api.openstack.compute import views
from nova.api.openstack import xmlutil
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import common
from nova.tests.api.openstack import fakes
@ -88,7 +87,7 @@ class VersionsTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
versions = json.loads(res.body)["versions"]
versions = jsonutils.loads(res.body)["versions"]
expected = [
{
"id": "v2.0",
@ -117,7 +116,7 @@ class VersionsTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
version = json.loads(res.body)
version = jsonutils.loads(res.body)
expected = {
"version": {
"id": "v2.0",
@ -161,7 +160,7 @@ class VersionsTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, "application/json")
version = json.loads(res.body)
version = jsonutils.loads(res.body)
expected = {
"version": {
"id": "v2.0",
@ -347,7 +346,7 @@ class VersionsTest(test.TestCase):
},
], }
self.assertDictMatch(expected, json.loads(res.body))
self.assertDictMatch(expected, jsonutils.loads(res.body))
def test_multi_choice_image_xml(self):
req = webob.Request.blank('/images/1')
@ -417,7 +416,7 @@ class VersionsTest(test.TestCase):
},
], }
self.assertDictMatch(expected, json.loads(res.body))
self.assertDictMatch(expected, jsonutils.loads(res.body))
class VersionsViewBuilderTests(test.TestCase):

View File

@ -15,7 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from xml.dom import minidom
import webob
@ -24,6 +23,7 @@ import webob.exc
from nova.api.openstack import common
from nova.api.openstack import wsgi
from nova.openstack.common import jsonutils
from nova import test
@ -54,7 +54,7 @@ class TestFaults(test.TestCase):
"code": 400,
},
}
actual = json.loads(response.body)
actual = jsonutils.loads(response.body)
self.assertEqual(response.content_type, "application/json")
self.assertEqual(expected, actual)
@ -79,7 +79,7 @@ class TestFaults(test.TestCase):
"retryAfter": 4,
},
}
actual = json.loads(response.body)
actual = jsonutils.loads(response.body)
self.assertEqual(response.content_type, "application/json")
self.assertEqual(expected, actual)

View File

@ -16,8 +16,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import iso8601
from lxml import etree
import webob
@ -25,6 +23,7 @@ import webob
from nova.api.openstack import volume
from nova.api.openstack import xmlutil
from nova import flags
from nova.openstack.common import jsonutils
from nova import test
FLAGS = flags.FLAGS
@ -59,7 +58,7 @@ class ExtensionControllerTest(ExtensionTestCase):
self.assertEqual(200, response.status_int)
# Make sure we have all the extensions, extra extensions being OK.
data = json.loads(response.body)
data = jsonutils.loads(response.body)
names = [str(x['name']) for x in data['extensions']
if str(x['name']) in self.ext_list]
names.sort()
@ -86,7 +85,7 @@ class ExtensionControllerTest(ExtensionTestCase):
url = '/fake/extensions/%s' % ext['alias']
request = webob.Request.blank(url)
response = request.get_response(app)
output = json.loads(response.body)
output = jsonutils.loads(response.body)
self.assertEqual(output['extension']['alias'], ext['alias'])
def test_get_extension_json(self):
@ -95,7 +94,7 @@ class ExtensionControllerTest(ExtensionTestCase):
response = request.get_response(app)
self.assertEqual(200, response.status_int)
data = json.loads(response.body)
data = jsonutils.loads(response.body)
self.assertEqual(data['extension'], {
"namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
"name": "Fox In Socks",

View File

@ -15,11 +15,11 @@
# under the License.
import httplib
import json
import urllib
import urlparse
from nova import log as logging
from nova.openstack.common import jsonutils
LOG = logging.getLogger(__name__)
@ -167,7 +167,7 @@ class TestOpenStackClient(object):
body = response.read()
LOG.debug(_("Decoding JSON: %s") % (body))
if body:
return json.loads(body)
return jsonutils.loads(body)
else:
return ""
@ -181,7 +181,7 @@ class TestOpenStackClient(object):
if body:
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = 'application/json'
kwargs['body'] = json.dumps(body)
kwargs['body'] = jsonutils.dumps(body)
kwargs.setdefault('check_response_status', [200, 202])
response = self.api_request(relative_uri, **kwargs)
@ -192,7 +192,7 @@ class TestOpenStackClient(object):
if body:
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = 'application/json'
kwargs['body'] = json.dumps(body)
kwargs['body'] = jsonutils.dumps(body)
kwargs.setdefault('check_response_status', [200, 202, 204])
response = self.api_request(relative_uri, **kwargs)

View File

@ -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))

View File

@ -16,12 +16,12 @@ Tests For Scheduler Host Filters.
"""
import httplib
import json
import stubout
from nova import context
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova.scheduler import filters
from nova.scheduler.filters.trusted_filter import AttestationService
from nova import test
@ -71,7 +71,7 @@ class HostFiltersTestCase(test.TestCase):
self.stubs = stubout.StubOutForTesting()
stub_out_https_backend(self.stubs)
self.context = context.RequestContext('fake', 'fake')
self.json_query = json.dumps(
self.json_query = jsonutils.dumps(
['and', ['>=', '$free_ram_mb', 1024],
['>=', '$free_disk_mb', 200 * 1024]])
# This has a side effect of testing 'get_filter_classes'
@ -411,7 +411,7 @@ class HostFiltersTestCase(test.TestCase):
def test_json_filter_fails_on_caps_disabled(self):
filt_cls = self.class_map['JsonFilter']()
json_query = json.dumps(
json_query = jsonutils.dumps(
['and', ['>=', '$free_ram_mb', 1024],
['>=', '$free_disk_mb', 200 * 1024],
'$capabilities.enabled'])
@ -428,7 +428,7 @@ class HostFiltersTestCase(test.TestCase):
def test_json_filter_fails_on_service_disabled(self):
filt_cls = self.class_map['JsonFilter']()
json_query = json.dumps(
json_query = jsonutils.dumps(
['and', ['>=', '$free_ram_mb', 1024],
['>=', '$free_disk_mb', 200 * 1024],
['not', '$service.disabled']])
@ -456,7 +456,11 @@ class HostFiltersTestCase(test.TestCase):
['and',
['>', '$free_ram_mb', 30],
['>', '$free_disk_mb', 300]]]]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
# Passes
capabilities = {'enabled': True, 'opt1': 'match'}
@ -553,26 +557,42 @@ class HostFiltersTestCase(test.TestCase):
for (op, args, expected) in ops_to_test:
raw = [op] + args
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertEqual(expected,
filt_cls.host_passes(host, filter_properties))
# This results in [False, True, False, True] and if any are True
# then it passes...
raw = ['not', True, False, True, False]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
# This results in [False, False, False] and if any are True
# then it passes...which this doesn't
raw = ['not', True, True, True]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_json_filter_unknown_operator_raises(self):
filt_cls = self.class_map['JsonFilter']()
raw = ['!=', 1, 2]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
host = fakes.FakeHostState('host1', 'compute',
{'capabilities': {'enabled': True}})
self.assertRaises(KeyError,
@ -584,10 +604,18 @@ class HostFiltersTestCase(test.TestCase):
{'capabilities': {'enabled': True}})
raw = []
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
raw = {}
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_json_filter_invalid_num_arguments_fails(self):
@ -596,11 +624,19 @@ class HostFiltersTestCase(test.TestCase):
{'capabilities': {'enabled': True}})
raw = ['>', ['and', ['or', ['not', ['<', ['>=', ['<=', ['in', ]]]]]]]]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertFalse(filt_cls.host_passes(host, filter_properties))
raw = ['>', 1]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_json_filter_unknown_variable_ignored(self):
@ -609,11 +645,19 @@ class HostFiltersTestCase(test.TestCase):
{'capabilities': {'enabled': True}})
raw = ['=', '$........', 1, 1]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
raw = ['=', '$foo', 2, 2]
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
filter_properties = {
'scheduler_hints': {
'query': jsonutils.dumps(raw),
},
}
self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_trusted_filter_default_passes(self):

View File

@ -19,8 +19,6 @@
Tests For Scheduler
"""
import json
from nova.compute import api as compute_api
from nova.compute import power_state
from nova.compute import rpcapi as compute_rpcapi
@ -29,6 +27,7 @@ from nova import context
from nova import db
from nova import exception
from nova import flags
from nova.openstack.common import jsonutils
from nova import rpc
from nova.rpc import common as rpc_common
from nova.scheduler import driver
@ -529,12 +528,18 @@ class SchedulerTestCase(test.TestCase):
'disk_available_least').AndReturn(1025)
rpc.queue_get_for(self.context, FLAGS.compute_topic,
instance['host']).AndReturn('src_queue1')
rpc.call(self.context, 'src_queue1',
{'method': 'get_instance_disk_info',
'args': {'instance_name': instance['name']},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION},
None).AndReturn(
json.dumps([{'disk_size': 1024 * (1024 ** 3)}]))
instance_disk_info_msg = {
'method': 'get_instance_disk_info',
'args': {
'instance_name': instance['name'],
},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION,
}
instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}]
rpc.call(self.context,
'src_queue1',
instance_disk_info_msg,
None).AndReturn(jsonutils.dumps(instance_disk_info))
# Common checks (shared storage ok, same hypervisor, etc)
self._check_shared_storage(dest, instance, False)
@ -734,12 +739,18 @@ class SchedulerTestCase(test.TestCase):
'disk_available_least').AndReturn(1023)
rpc.queue_get_for(self.context, FLAGS.compute_topic,
instance['host']).AndReturn('src_queue')
rpc.call(self.context, 'src_queue',
{'method': 'get_instance_disk_info',
'args': {'instance_name': instance['name']},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION},
None).AndReturn(
json.dumps([{'disk_size': 1024 * (1024 ** 3)}]))
instance_disk_info_msg = {
'method': 'get_instance_disk_info',
'args': {
'instance_name': instance['name'],
},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION,
}
instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}]
rpc.call(self.context,
'src_queue',
instance_disk_info_msg,
None).AndReturn(jsonutils.dumps(instance_disk_info))
self.mox.ReplayAll()
self.assertRaises(exception.MigrationError,

View File

@ -17,9 +17,9 @@ Tests For PickledScheduler.
"""
import datetime
import json
import StringIO
from nova.openstack.common import jsonutils
from nova.scheduler import scheduler_options
from nova import test
@ -58,7 +58,7 @@ class SchedulerOptionsTestCase(test.TestCase):
file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
data = dict(a=1, b=2, c=3)
jdata = json.dumps(data)
jdata = jsonutils.dumps(data)
fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
{}, jdata)
@ -86,7 +86,7 @@ class SchedulerOptionsTestCase(test.TestCase):
file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
data = dict(a=1, b=2, c=3)
jdata = json.dumps(data)
jdata = jsonutils.dumps(data)
fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
{}, jdata)
@ -100,7 +100,7 @@ class SchedulerOptionsTestCase(test.TestCase):
file_now = datetime.datetime(2012, 1, 1, 1, 1, 1)
data = dict(a=1, b=2, c=3)
jdata = json.dumps(data)
jdata = jsonutils.dumps(data)
fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
data, jdata)
@ -115,7 +115,7 @@ class SchedulerOptionsTestCase(test.TestCase):
old_data = dict(a=1, b=2, c=3)
data = dict(a=11, b=12, c=13)
jdata = json.dumps(data)
jdata = jsonutils.dumps(data)
fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
old_data, jdata)
@ -130,7 +130,7 @@ class SchedulerOptionsTestCase(test.TestCase):
old_data = dict(a=1, b=2, c=3)
data = dict(a=11, b=12, c=13)
jdata = json.dumps(data)
jdata = jsonutils.dumps(data)
fake = FakeSchedulerOptions(last_checked, now, file_old, file_now,
old_data, jdata)

View File

@ -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'])

View File

@ -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:

View File

@ -26,7 +26,6 @@ Includes injection of SSH PGP keys into authorized_keys file.
"""
import crypt
import json
import os
import random
import re
@ -36,6 +35,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
from nova import utils
from nova.virt.disk import guestfs
from nova.virt.disk import loop
@ -320,7 +320,7 @@ def _inject_metadata_into_fs(metadata, fs, execute=None):
metadata = dict([(m.key, m.value) for m in metadata])
utils.execute('tee', metadata_path,
process_input=json.dumps(metadata), run_as_root=True)
process_input=jsonutils.dumps(metadata), run_as_root=True)
def _inject_key_into_fs(key, fs, execute=None):

View File

@ -20,7 +20,6 @@
# under the License.
import hashlib
import json
import os
import random
import re
@ -29,6 +28,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
from nova import utils
from nova.virt import images
@ -375,7 +375,7 @@ def read_stored_info(base_path, field=None):
LOG.info(_('Read: %s'), serialized)
try:
d = json.loads(serialized)
d = jsonutils.loads(serialized)
except ValueError, e:
LOG.error(_('Error reading image info file %(filename)s: '
@ -400,7 +400,7 @@ def write_stored_info(target, field=None, value=None):
d = read_stored_info(info_file)
d[field] = value
serialized = json.dumps(d)
serialized = jsonutils.dumps(d)
LOG.info(_('Writing image info file: %s'), info_file)
LOG.info(_('Wrote: %s'), serialized)

View File

@ -51,7 +51,6 @@ A fake XenAPI SDK.
"""
import json
import random
import uuid
from xml.sax import saxutils
@ -60,6 +59,7 @@ import pprint
from nova import exception
from nova import log as logging
from nova.openstack.common import jsonutils
from nova import utils
@ -337,7 +337,7 @@ def as_json(*args, **kwargs):
then these are rendered as a JSON list. If it's given keyword
arguments then these are rendered as a JSON dict."""
arg = args or kwargs
return json.dumps(arg)
return jsonutils.dumps(arg)
class Failure(Exception):
@ -510,17 +510,17 @@ class SessionBase(object):
elif (plugin, method) == ('migration', 'transfer_vhd'):
return ''
elif (plugin, method) == ('xenhost', 'host_data'):
return json.dumps({'host_memory': {'total': 10,
'overhead': 20,
'free': 30,
'free-computed': 40}, })
return jsonutils.dumps({'host_memory': {'total': 10,
'overhead': 20,
'free': 30,
'free-computed': 40}, })
elif (plugin == 'xenhost' and method in ['host_reboot',
'host_startup',
'host_shutdown']):
return json.dumps({"power_action": method[5:]})
return jsonutils.dumps({"power_action": method[5:]})
elif (plugin, method) == ('xenhost', 'set_host_enabled'):
enabled = 'enabled' if _5.get('enabled') == 'true' else 'disabled'
return json.dumps({"status": enabled})
return jsonutils.dumps({"status": enabled})
else:
raise Exception('No simulation in host_call_plugin for %s,%s' %
(plugin, method))

View File

@ -17,13 +17,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from nova import context
from nova.db import api as db
from nova import flags
from nova import log as logging
from nova.openstack.common import jsonutils
from nova.virt import firewall
from nova.virt import netutils
@ -49,9 +47,9 @@ class Dom0IptablesFirewallDriver(firewall.IptablesFirewallDriver):
# Prepare arguments for plugin call
args = {}
args.update(map(lambda x: (x, str(kwargs[x])), kwargs))
args['cmd_args'] = json.dumps(cmd)
args['cmd_args'] = jsonutils.dumps(cmd)
ret = self._session.call_plugin('xenhost', 'iptables_config', args)
json_ret = json.loads(ret)
json_ret = jsonutils.loads(ret)
return (json_ret['out'], json_ret['err'])
def __init__(self, xenapi_session=None, **kwargs):

View File

@ -19,7 +19,6 @@
Management class for host-related functions (start, reboot, etc).
"""
import json
import logging
from nova.compute import vm_states
@ -27,6 +26,7 @@ from nova import context
from nova import db
from nova import exception
from nova import notifications
from nova.openstack.common import jsonutils
from nova.virt.xenapi import vm_utils
LOG = logging.getLogger(__name__)
@ -42,7 +42,7 @@ class Host(object):
def host_power_action(self, _host, action):
"""Reboots or shuts down the host."""
args = {"action": json.dumps(action)}
args = {"action": jsonutils.dumps(action)}
methods = {"reboot": "host_reboot", "shutdown": "host_shutdown"}
response = call_xenhost(self._session, methods[action], args)
return response.get("power_action", response)
@ -112,7 +112,7 @@ class Host(object):
def set_host_enabled(self, _host, enabled):
"""Sets the specified host's ability to accept new instances."""
args = {"enabled": json.dumps(enabled)}
args = {"enabled": jsonutils.dumps(enabled)}
response = call_xenhost(self._session, "set_host_enabled", args)
return response.get("status", response)
@ -177,7 +177,7 @@ def call_xenhost(session, method, arg_dict):
result = session.call_plugin('xenhost', method, args=arg_dict)
if not result:
return ''
return json.loads(result)
return jsonutils.loads(result)
except ValueError:
LOG.exception(_("Unable to get updated status"))
return None

View File

@ -19,7 +19,6 @@
Management class for Pool-related functions (join, eject, etc).
"""
import json
import urlparse
from nova.compute import aggregate_states
@ -28,6 +27,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
from nova import rpc
from nova.virt.xenapi import vm_utils
@ -134,7 +134,7 @@ class ResourcePool(object):
'url': url,
'user': user,
'password': passwd,
'force': json.dumps(FLAGS.use_join_force),
'force': jsonutils.dumps(FLAGS.use_join_force),
'master_addr': self._host_addr,
'master_user': FLAGS.xenapi_connection_username,
'master_pass': FLAGS.xenapi_connection_password, }

View File

@ -23,7 +23,6 @@ their attributes like VDIs, VIFs, as well as their lookup functions.
import contextlib
import cPickle as pickle
import decimal
import json
import os
import re
import time
@ -43,6 +42,7 @@ from nova.image import glance
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import excutils
from nova.openstack.common import jsonutils
from nova import utils
from nova.virt.disk import api as disk
from nova.virt import xenapi
@ -711,7 +711,7 @@ def _retry_glance_download_vhd(context, session, image):
try:
result = session.call_plugin('glance', 'download_vhd', kwargs)
return json.loads(result)
return jsonutils.loads(result)
except session.XenAPI.Failure as exc:
_type, _method, error = exc.details[:3]
if error == 'RetryableError':

View File

@ -23,7 +23,6 @@ import base64
import binascii
import cPickle as pickle
import functools
import json
import os
import time
import uuid
@ -39,6 +38,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 utils
from nova.virt import driver
from nova.virt.xenapi import firewall
@ -517,7 +517,7 @@ class VMOps(object):
# Check if this is a JSON-encoded string and convert if needed.
if isinstance(injected_files, basestring):
try:
injected_files = json.loads(injected_files)
injected_files = jsonutils.loads(injected_files)
except ValueError:
LOG.exception(_("Invalid value for injected_files: %r"),
injected_files, instance=instance)
@ -1409,7 +1409,9 @@ class VMOps(object):
xs_data = self._vif_xenstore_data(vif)
location = ('vm-data/networking/%s' %
vif['address'].replace(':', ''))
self._add_to_param_xenstore(vm_ref, location, json.dumps(xs_data))
self._add_to_param_xenstore(vm_ref,
location,
jsonutils.dumps(xs_data))
try:
self._write_to_xenstore(instance, location, xs_data,
vm_ref=vm_ref)
@ -1466,7 +1468,7 @@ class VMOps(object):
"""
return self._make_plugin_call('xenstore.py', 'write_record', instance,
vm_ref=vm_ref, path=path,
value=json.dumps(value))
value=jsonutils.dumps(value))
def _make_agent_call(self, method, instance, args=None, vm_ref=None):
"""Abstracts out the interaction with the agent xenapi plugin."""
@ -1478,7 +1480,7 @@ class VMOps(object):
if isinstance(ret, dict):
return ret
try:
return json.loads(ret)
return jsonutils.loads(ret)
except TypeError:
LOG.error(_('The agent call to %(method)s returned an invalid'
' response: %(ret)r. path=%(path)s; args=%(args)r'),

View File

@ -22,10 +22,10 @@
.. moduleauthor:: Yuriy Taraday <yorik.sar@gmail.com>
"""
import json
import urllib2
from nova import log as logging
from nova.openstack.common import jsonutils
from nova.volume import nexenta
LOG = logging.getLogger(__name__)
@ -55,9 +55,9 @@ class NexentaJSONProxy(object):
obj, method)
def __call__(self, *args):
data = json.dumps({'object': self.obj,
'method': self.method,
'params': args})
data = jsonutils.dumps({'object': self.obj,
'method': self.method,
'params': args})
auth = ('%s:%s' % (self.user, self.password)).encode('base64')[:-1]
headers = {'Content-Type': 'application/json',
'Authorization': 'Basic %s' % (auth,)}
@ -77,7 +77,7 @@ class NexentaJSONProxy(object):
response_data = response_obj.read()
LOG.debug(_('Got response: %s'), response_data)
response = json.loads(response_data)
response = jsonutils.loads(response_data)
if response.get('error') is not None:
raise NexentaJSONException(response['error'].get('message', ''))
else:

View File

@ -23,7 +23,6 @@ controller on the SAN hardware. We expect to access it over SSH or some API.
import base64
import httplib
import json
import os
import paramiko
import random
@ -37,6 +36,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import jsonutils
from nova import utils
import nova.volume.driver
@ -673,7 +673,7 @@ class SolidFireSanISCSIDriver(SanISCSIDriver):
if params is not None:
command['params'] = params
payload = json.dumps(command, ensure_ascii=False)
payload = jsonutils.dumps(command, ensure_ascii=False)
payload.encode('utf-8')
# we use json-rpc, webserver needs to see json-rpc in header
header = {'Content-Type': 'application/json-rpc; charset=utf-8'}
@ -698,11 +698,12 @@ class SolidFireSanISCSIDriver(SanISCSIDriver):
else:
data = response.read()
try:
data = json.loads(data)
data = jsonutils.loads(data)
except (TypeError, ValueError), exc:
connection.close()
msg = _("Call to json.loads() raised an exception: %s") % exc
msg = _("Call to jsonutils.loads() "
"raised an exception: %s") % exc
raise exception.SfJsonEncodeFailure(msg)
connection.close()