diff options
author | Zhongyue Luo <lzyeval@gmail.com> | 2012-06-03 16:36:06 +0800 |
---|---|---|
committer | Zhongyue Luo <lzyeval@gmail.com> | 2012-06-07 09:24:03 +0800 |
commit | 3dce38f32559659978dd2ae69e9ffcb39c608582 (patch) | |
tree | 7735a91c738dbd944344eb4fa3724bc9aa4dcf4b /nova/tests/api | |
parent | 7b7febb02b37420c759eab59b07c7e3e2de9bab1 (diff) | |
download | nova-3dce38f32559659978dd2ae69e9ffcb39c608582.tar.gz nova-3dce38f32559659978dd2ae69e9ffcb39c608582.tar.xz nova-3dce38f32559659978dd2ae69e9ffcb39c608582.zip |
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
Diffstat (limited to 'nova/tests/api')
28 files changed, 247 insertions, 254 deletions
diff --git a/nova/tests/api/openstack/common.py b/nova/tests/api/openstack/common.py index 19515ca67..cfc7fb86d 100644 --- a/nova/tests/api/openstack/common.py +++ b/nova/tests/api/openstack/common.py @@ -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 diff --git a/nova/tests/api/openstack/compute/contrib/test_accounts.py b/nova/tests/api/openstack/compute/contrib/test_accounts.py index d98baf7e9..f5c8ff62e 100644 --- a/nova/tests/api/openstack/compute/contrib/test_accounts.py +++ b/nova/tests/api/openstack/compute/contrib/test_accounts.py @@ -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) diff --git a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py index ebab28472..922e09f0b 100644 --- a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py @@ -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): diff --git a/nova/tests/api/openstack/compute/contrib/test_console_output.py b/nova/tests/api/openstack/compute/contrib/test_console_output.py index c553df0ca..ab0fe35b9 100644 --- a/nova/tests/api/openstack/compute/contrib/test_console_output.py +++ b/nova/tests/api/openstack/compute/contrib/test_console_output.py @@ -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()) diff --git a/nova/tests/api/openstack/compute/contrib/test_consoles.py b/nova/tests/api/openstack/compute/contrib/test_consoles.py index 668d896ec..8749aa5ed 100644 --- a/nova/tests/api/openstack/compute/contrib/test_consoles.py +++ b/nova/tests/api/openstack/compute/contrib/test_consoles.py @@ -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()) diff --git a/nova/tests/api/openstack/compute/contrib/test_createserverext.py b/nova/tests/api/openstack/compute/contrib/test_createserverext.py index 382d26e69..aaef09f8b 100644 --- a/nova/tests/api/openstack/compute/contrib/test_createserverext.py +++ b/nova/tests/api/openstack/compute/contrib/test_createserverext.py @@ -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) diff --git a/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py b/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py index 63efba6d3..d50749060 100644 --- a/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py +++ b/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py @@ -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) diff --git a/nova/tests/api/openstack/compute/contrib/test_extended_status.py b/nova/tests/api/openstack/compute/contrib/test_extended_status.py index 2bfe797ec..75f86a8ea 100644 --- a/nova/tests/api/openstack/compute/contrib/test_extended_status.py +++ b/nova/tests/api/openstack/compute/contrib/test_extended_status.py @@ -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) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py index f0b51b960..140efc325 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py @@ -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) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py b/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py index 295772889..4f24b08ad 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py @@ -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]) diff --git a/nova/tests/api/openstack/compute/contrib/test_keypairs.py b/nova/tests/api/openstack/compute/contrib/test_keypairs.py index 8a9849d2c..bcb33eb47 100644 --- a/nova/tests/api/openstack/compute/contrib/test_keypairs.py +++ b/nova/tests/api/openstack/compute/contrib/test_keypairs.py @@ -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) diff --git a/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py b/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py index 441f75c24..b11fe2972 100644 --- a/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py +++ b/nova/tests/api/openstack/compute/contrib/test_multinic_xs.py @@ -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()) diff --git a/nova/tests/api/openstack/compute/contrib/test_rescue.py b/nova/tests/api/openstack/compute/contrib/test_rescue.py index 00efc2f27..bc6c872f2 100644 --- a/nova/tests/api/openstack/compute/contrib/test_rescue.py +++ b/nova/tests/api/openstack/compute/contrib/test_rescue.py @@ -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()) diff --git a/nova/tests/api/openstack/compute/contrib/test_server_diagnostics.py b/nova/tests/api/openstack/compute/contrib/test_server_diagnostics.py index f7ec4543b..cea04d39e 100644 --- a/nova/tests/api/openstack/compute/contrib/test_server_diagnostics.py +++ b/nova/tests/api/openstack/compute/contrib/test_server_diagnostics.py @@ -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'}) diff --git a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py index cc5475de1..e26d64262 100644 --- a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py +++ b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py @@ -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'] diff --git a/nova/tests/api/openstack/compute/contrib/test_snapshots.py b/nova/tests/api/openstack/compute/contrib/test_snapshots.py index f0a735ccd..18e31f0e4 100644 --- a/nova/tests/api/openstack/compute/contrib/test_snapshots.py +++ b/nova/tests/api/openstack/compute/contrib/test_snapshots.py @@ -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'] diff --git a/nova/tests/api/openstack/compute/contrib/test_virtual_interfaces.py b/nova/tests/api/openstack/compute/contrib/test_virtual_interfaces.py index 16f946bfc..7ca950d9a 100644 --- a/nova/tests/api/openstack/compute/contrib/test_virtual_interfaces.py +++ b/nova/tests/api/openstack/compute/contrib/test_virtual_interfaces.py @@ -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'}, diff --git a/nova/tests/api/openstack/compute/contrib/test_volumes.py b/nova/tests/api/openstack/compute/contrib/test_volumes.py index aee7260ef..734836d3f 100644 --- a/nova/tests/api/openstack/compute/contrib/test_volumes.py +++ b/nova/tests/api/openstack/compute/contrib/test_volumes.py @@ -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) diff --git a/nova/tests/api/openstack/compute/test_api.py b/nova/tests/api/openstack/compute/test_api.py index c451f86ab..434befdb9 100644 --- a/nova/tests/api/openstack/compute/test_api.py +++ b/nova/tests/api/openstack/compute/test_api.py @@ -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' diff --git a/nova/tests/api/openstack/compute/test_extensions.py b/nova/tests/api/openstack/compute/test_extensions.py index 4d4ecdd2a..7db25100a 100644 --- a/nova/tests/api/openstack/compute/test_extensions.py +++ b/nova/tests/api/openstack/compute/test_extensions.py @@ -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) diff --git a/nova/tests/api/openstack/compute/test_image_metadata.py b/nova/tests/api/openstack/compute/test_image_metadata.py index 16d8e47b8..1cd46902b 100644 --- a/nova/tests/api/openstack/compute/test_image_metadata.py +++ b/nova/tests/api/openstack/compute/test_image_metadata.py @@ -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, diff --git a/nova/tests/api/openstack/compute/test_limits.py b/nova/tests/api/openstack/compute/test_limits.py index e104c148d..b9450ae5d 100644 --- a/nova/tests/api/openstack/compute/test_limits.py +++ b/nova/tests/api/openstack/compute/test_limits.py @@ -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 diff --git a/nova/tests/api/openstack/compute/test_server_metadata.py b/nova/tests/api/openstack/compute/test_server_metadata.py index 577fb84ff..37d54e09b 100644 --- a/nova/tests/api/openstack/compute/test_server_metadata.py +++ b/nova/tests/api/openstack/compute/test_server_metadata.py @@ -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) diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 44741596b..787792d54 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -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'] diff --git a/nova/tests/api/openstack/compute/test_urlmap.py b/nova/tests/api/openstack/compute/test_urlmap.py index 12c22792e..67524bcf5 100644 --- a/nova/tests/api/openstack/compute/test_urlmap.py +++ b/nova/tests/api/openstack/compute/test_urlmap.py @@ -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') diff --git a/nova/tests/api/openstack/compute/test_versions.py b/nova/tests/api/openstack/compute/test_versions.py index 1680226d8..4520faa48 100644 --- a/nova/tests/api/openstack/compute/test_versions.py +++ b/nova/tests/api/openstack/compute/test_versions.py @@ -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): diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py index 9cb76b7fd..1bd799f8c 100644 --- a/nova/tests/api/openstack/test_faults.py +++ b/nova/tests/api/openstack/test_faults.py @@ -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) diff --git a/nova/tests/api/openstack/volume/test_extensions.py b/nova/tests/api/openstack/volume/test_extensions.py index e86d18fd4..e291e74dd 100644 --- a/nova/tests/api/openstack/volume/test_extensions.py +++ b/nova/tests/api/openstack/volume/test_extensions.py @@ -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", |