]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port API v1 and v2 to Python 3
authorVictor Stinner <vstinner@redhat.com>
Tue, 9 Feb 2016 13:36:45 +0000 (14:36 +0100)
committerVictor Stinner <vstinner@redhat.com>
Mon, 15 Feb 2016 14:22:05 +0000 (15:22 +0100)
* Replace jsonutils.dumps() with jsonutils.dump_as_bytes() since
  output is used for the HTTP body, and HTTP body type is bytes, not
  Unicode. On Python 3, jsonutils.dumps() returns Unicode.
* FakeHttplibSocket: replace io.StringIO with io.BytesIO, HTTP body
  type is bytes. Encode Unicode to UTF-8.
* Fix FakeHttplibSocket.makefile() API: only the first parameter is
  mandatory. On Python 3, it's only called with the first 'mode'
  parameter.
* Use bytes strings to test HTTP bodies (JSON or XML).
* Replace dict.values() with list(dict.values()) to get a list on
  Python 3.
* Replace error.message with encodeutils.exception_to_unicode(error),
  exceptions loose their message attribute in Python 3.
* Update JSON serializer test in test_wsgi.py to use bytes.
* tests-py3.txt: add cinder.tests.unit.api.v1 and
  cinder.tests.unit.api.v2

Partial-Implements: blueprint cinder-python3
Change-Id: I0f0048f4a1344feaa3434cbf7ebd31e3f12d6ae4

14 files changed:
cinder/api/openstack/wsgi.py
cinder/api/v1/limits.py
cinder/api/v2/limits.py
cinder/api/v2/snapshots.py
cinder/tests/unit/api/openstack/test_wsgi.py
cinder/tests/unit/api/v1/test_limits.py
cinder/tests/unit/api/v1/test_snapshot_metadata.py
cinder/tests/unit/api/v1/test_types.py
cinder/tests/unit/api/v1/test_volume_metadata.py
cinder/tests/unit/api/v2/test_limits.py
cinder/tests/unit/api/v2/test_snapshot_metadata.py
cinder/tests/unit/api/v2/test_types.py
cinder/tests/unit/api/v2/test_volume_metadata.py
tests-py3.txt

index f490471737b6eb839e5a782e0262add50c3cd130..779018b45aad6fa44da6676762914a3be72b4169 100644 (file)
@@ -409,7 +409,7 @@ class JSONDictSerializer(DictSerializer):
     """Default JSON request body serialization."""
 
     def default(self, data):
-        return jsonutils.dumps(data)
+        return jsonutils.dump_as_bytes(data)
 
 
 class XMLDictSerializer(DictSerializer):
index b0124deaebf85090b5585b95500889195723ce46..f1143d7f646d76a9397b1d81ddb3880ffbb51a1c 100644 (file)
@@ -436,7 +436,7 @@ class WsgiLimiterProxy(object):
         self.limiter_address = limiter_address
 
     def check_for_delay(self, verb, path, username=None):
-        body = jsonutils.dumps({"verb": verb, "path": path})
+        body = jsonutils.dump_as_bytes({"verb": verb, "path": path})
         headers = {"Content-Type": "application/json"}
 
         conn = http_client.HTTPConnection(self.limiter_address)
index 0b6fb61397e7b83a1c6069ac259071fcbcbb167b..f50376bfd484e19f5a78835dc32356df17195458 100644 (file)
@@ -433,7 +433,7 @@ class WsgiLimiterProxy(object):
         self.limiter_address = limiter_address
 
     def check_for_delay(self, verb, path, username=None):
-        body = jsonutils.dumps({"verb": verb, "path": path})
+        body = jsonutils.dump_as_bytes({"verb": verb, "path": path})
         headers = {"Content-Type": "application/json"}
 
         conn = http_client.HTTPConnection(self.limiter_address)
index ee0a30249032122b82b248fe8204dc65a1e38728..536b27854b7e508b600f4daf17b8a7af8522e6c3 100644 (file)
@@ -16,6 +16,7 @@
 """The volumes snapshots api."""
 
 from oslo_log import log as logging
+from oslo_utils import encodeutils
 from oslo_utils import strutils
 import webob
 from webob import exc
@@ -177,7 +178,8 @@ class SnapshotsController(wsgi.Controller):
         try:
             force = strutils.bool_from_string(force, strict=True)
         except ValueError as error:
-            msg = _("Invalid value for 'force': '%s'") % error.message
+            err_msg = encodeutils.exception_to_unicode(error)
+            msg = _("Invalid value for 'force': '%s'") % err_msg
             raise exception.InvalidParameterValue(err=msg)
 
         if force:
index e156007ee3959304e5f6ff6899df6be6dab29758..0c2cf906367281cbdbd0733aff6f61463bb77c9a 100644 (file)
@@ -216,10 +216,10 @@ class XMLDictSerializerTest(test.TestCase):
 class JSONDictSerializerTest(test.TestCase):
     def test_json(self):
         input_dict = dict(servers=dict(a=(2, 3)))
-        expected_json = '{"servers":{"a":[2,3]}}'
+        expected_json = b'{"servers":{"a":[2,3]}}'
         serializer = wsgi.JSONDictSerializer()
         result = serializer.serialize(input_dict)
-        result = result.replace('\n', '').replace(' ', '')
+        result = result.replace(b'\n', b'').replace(b' ', b'')
         self.assertEqual(expected_json, result)
 
 
index 7ca8afc94e74d54a980590a3913737c5692f9f25..d9f69fa47fc11031f2679242198f611ea92589ea 100644 (file)
@@ -569,7 +569,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
 
     def _request_data(self, verb, path):
         """Get data describing a limit request verb/path."""
-        return jsonutils.dumps({"verb": verb, "path": path})
+        return jsonutils.dump_as_bytes({"verb": verb, "path": path})
 
     def _request(self, verb, url, username=None):
         """Assert that POSTing to given url triggers given action.
@@ -636,9 +636,11 @@ class FakeHttplibSocket(object):
 
     def __init__(self, response_string):
         """Initialize new `FakeHttplibSocket`."""
-        self._buffer = six.StringIO(response_string)
+        if isinstance(response_string, six.text_type):
+            response_string = response_string.encode('utf-8')
+        self._buffer = six.BytesIO(response_string)
 
-    def makefile(self, _mode, _other):
+    def makefile(self, mode, *args):
         """Returns the socket's internal buffer."""
         return self._buffer
 
@@ -754,8 +756,9 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
         delay, error = self.proxy.check_for_delay("GET", "/delayed")
         error = error.strip()
 
-        expected = ("60.00", "403 Forbidden\n\nOnly 1 GET request(s) can be "
-                    "made to /delayed every minute.")
+        expected = ("60.00",
+                    b"403 Forbidden\n\nOnly 1 GET request(s) can be "
+                    b"made to /delayed every minute.")
 
         self.assertEqual(expected, (delay, error))
 
@@ -827,7 +830,7 @@ class LimitsXMLSerializationTest(test.TestCase):
                    "absolute": {}}}
 
         output = serializer.serialize(fixture)
-        has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
+        has_dec = output.startswith(b"<?xml version='1.0' encoding='UTF-8'?>")
         self.assertTrue(has_dec)
 
     def test_index(self):
index cfcbb39b8f94cb9310cb352d96e7c8650ba1ee61..94fbe107473695968c48953d02770966a1ae1c31 100644 (file)
@@ -292,7 +292,7 @@ class SnapshotMetaDataTest(test.TestCase):
         body = {"metadata": {"key1": "value1",
                              "key2": "value2",
                              "key3": "value3"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         res_dict = self.controller.create(req, self.req_id, body)
         self.assertEqual(body, res_dict)
 
@@ -326,7 +326,7 @@ class SnapshotMetaDataTest(test.TestCase):
                                  "key2": "value2",
                                  "key3": "value3",
                                  "KEY4": "value4"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         res_dict = self.controller.create(req, self.req_id, body)
         self.assertEqual(expected, res_dict)
 
@@ -346,7 +346,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -358,7 +358,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -375,7 +375,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'POST'
         req.content_type = "application/json"
         body = {"metadata": {"key9": "value9"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.create, req, self.req_id, body)
 
@@ -402,7 +402,7 @@ class SnapshotMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         res_dict = self.controller.update_all(req, self.req_id, expected)
 
         self.assertEqual(expected, res_dict)
@@ -442,7 +442,7 @@ class SnapshotMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         res_dict = self.controller.update_all(req, self.req_id, body)
 
         self.assertEqual(expected, res_dict)
@@ -465,7 +465,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         res_dict = self.controller.update_all(req, self.req_id, expected)
 
         self.assertEqual(expected, res_dict)
@@ -477,7 +477,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'meta': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -491,7 +491,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': ['asdf']}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -503,7 +503,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         body = {'metadata': {'key10': 'value10'}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
 
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.update_all, req, '100', body)
@@ -524,7 +524,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         res_dict = self.controller.update(req, self.req_id, 'key1', body)
         expected = {'meta': {'key1': 'value1'}}
@@ -537,7 +537,7 @@ class SnapshotMetaDataTest(test.TestCase):
             '/v1.1/fake/snapshots/asdf/metadata/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPNotFound,
@@ -562,7 +562,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -583,7 +583,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@@ -605,7 +605,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": ("a" * 260)}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@@ -618,7 +618,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1", "key2": "value2"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -631,7 +631,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/bad')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -656,18 +656,18 @@ class SnapshotMetaDataTest(test.TestCase):
 
         # test for long key
         data = {"metadata": {"a" * 260: "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                           self.controller.create, req, self.req_id, data)
 
         # test for long value
         data = {"metadata": {"key": "v" * 260}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                           self.controller.create, req, self.req_id, data)
 
         # test for empty key.
         data = {"metadata": {"": "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.create, req, self.req_id, data)
index 773c3ce22f401f087d7f9ab0fd719c0c3897431c..c5d220e3876c5093f65c00a00e660c2d1e14f8aa 100644 (file)
@@ -181,7 +181,7 @@ class VolumeTypesSerializerTest(test.TestCase):
 
         # Just getting some input data
         vtypes = return_volume_types_get_all_types(None)
-        text = serializer.serialize({'volume_types': vtypes.values()})
+        text = serializer.serialize({'volume_types': list(vtypes.values())})
 
         tree = etree.fromstring(text)
 
index 2b20b9b1d399c65f0d06f025350fe78ae64fe8cd..09e1b0987a754f7363598c0cc894df0d762d8e9c 100644 (file)
@@ -265,7 +265,7 @@ class volumeMetaDataTest(test.TestCase):
         body = {"metadata": {"key1": "value1",
                              "key2": "value2",
                              "key3": "value3", }}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -298,7 +298,7 @@ class volumeMetaDataTest(test.TestCase):
                                  "key2": "value2",
                                  "key3": "value3",
                                  "KEY4": "value4"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -323,7 +323,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -335,7 +335,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -353,7 +353,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'POST'
         req.content_type = "application/json"
         body = {"metadata": {"key9": "value9"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.create, req, self.req_id, body)
 
@@ -372,7 +372,7 @@ class volumeMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -409,7 +409,7 @@ class volumeMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -428,7 +428,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -446,7 +446,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": ("a" * 260)}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -466,7 +466,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'meta': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -481,7 +481,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': ['asdf']}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -497,7 +497,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         body = {'metadata': {'key10': 'value10'}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
 
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.update_all, req, '100', body)
@@ -510,7 +510,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -528,7 +528,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank('/v1.1/fake/volumes/asdf/metadata/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPNotFound,
@@ -554,7 +554,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -575,7 +575,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -594,7 +594,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1", "key2": "value2"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -607,7 +607,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/bad')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -625,7 +625,7 @@ class volumeMetaDataTest(test.TestCase):
 
         # test for long key
         data = {"metadata": {"a" * 260: "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -636,7 +636,7 @@ class volumeMetaDataTest(test.TestCase):
 
         # test for long value
         data = {"metadata": {"key": "v" * 260}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -647,7 +647,7 @@ class volumeMetaDataTest(test.TestCase):
 
         # test for empty key.
         data = {"metadata": {"": "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
index 7408d0193cd6bb607df65c8f843af1c77a164455..5a62e69af8522f13a662de8fa5ef7a202d334742 100644 (file)
@@ -575,7 +575,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
 
     def _request_data(self, verb, path):
         """Get data describing a limit request verb/path."""
-        return jsonutils.dumps({"verb": verb, "path": path})
+        return jsonutils.dump_as_bytes({"verb": verb, "path": path})
 
     def _request(self, verb, url, username=None):
         """POST request to given url by given username.
@@ -641,9 +641,11 @@ class FakeHttplibSocket(object):
 
     def __init__(self, response_string):
         """Initialize new `FakeHttplibSocket`."""
-        self._buffer = six.StringIO(response_string)
+        if isinstance(response_string, six.text_type):
+            response_string = response_string.encode('utf-8')
+        self._buffer = six.BytesIO(response_string)
 
-    def makefile(self, _mode, _other):
+    def makefile(self, mode, *args):
         """Returns the socket's internal buffer."""
         return self._buffer
 
@@ -761,8 +763,9 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
         delay, error = self.proxy.check_for_delay("GET", "/delayed")
         error = error.strip()
 
-        expected = ("60.00", "403 Forbidden\n\nOnly 1 GET request(s) can be "
-                    "made to /delayed every minute.")
+        expected = ("60.00",
+                    b"403 Forbidden\n\nOnly 1 GET request(s) can be "
+                    b"made to /delayed every minute.")
 
         self.assertEqual(expected, (delay, error))
 
@@ -834,7 +837,7 @@ class LimitsXMLSerializationTest(test.TestCase):
                    "absolute": {}}}
 
         output = serializer.serialize(fixture)
-        has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
+        has_dec = output.startswith(b"<?xml version='1.0' encoding='UTF-8'?>")
         self.assertTrue(has_dec)
 
     def test_index(self):
index c3676c0f93b1a35a015105050b64e5182a0ab851..adbaf2d971c23544625c950c924dd4a112feff05 100644 (file)
@@ -293,7 +293,7 @@ class SnapshotMetaDataTest(test.TestCase):
         body = {"metadata": {"key1": "value1",
                              "key2": "value2",
                              "key3": "value3"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         res_dict = self.controller.create(req, self.req_id, body)
         self.assertEqual(body, res_dict)
 
@@ -327,7 +327,7 @@ class SnapshotMetaDataTest(test.TestCase):
                                  "key2": "value2",
                                  "key3": "value3",
                                  "KEY4": "value4"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         res_dict = self.controller.create(req, self.req_id, body)
         self.assertEqual(expected, res_dict)
 
@@ -347,7 +347,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -359,7 +359,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -376,7 +376,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'POST'
         req.content_type = "application/json"
         body = {"metadata": {"key9": "value9"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.create, req, self.req_id, body)
 
@@ -403,7 +403,7 @@ class SnapshotMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         res_dict = self.controller.update_all(req, self.req_id, expected)
 
         self.assertEqual(expected, res_dict)
@@ -443,7 +443,7 @@ class SnapshotMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         res_dict = self.controller.update_all(req, self.req_id, body)
 
         self.assertEqual(expected, res_dict)
@@ -466,7 +466,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         res_dict = self.controller.update_all(req, self.req_id, expected)
 
         self.assertEqual(expected, res_dict)
@@ -478,7 +478,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'meta': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -491,7 +491,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': ['asdf']}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -503,7 +503,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         body = {'metadata': {'key10': 'value10'}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
 
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.update_all, req, '100', body)
@@ -524,7 +524,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         res_dict = self.controller.update(req, self.req_id, 'key1', body)
         expected = {'meta': {'key1': 'value1'}}
@@ -537,7 +537,7 @@ class SnapshotMetaDataTest(test.TestCase):
             '/v2/fake/snapshots/asdf/metadata/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPNotFound,
@@ -562,7 +562,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -583,7 +583,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@@ -605,7 +605,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": ("a" * 260)}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
@@ -618,7 +618,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1", "key2": "value2"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -631,7 +631,7 @@ class SnapshotMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/bad')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -656,18 +656,18 @@ class SnapshotMetaDataTest(test.TestCase):
 
         # test for long key
         data = {"metadata": {"a" * 260: "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                           self.controller.create, req, self.req_id, data)
 
         # test for long value
         data = {"metadata": {"key": "v" * 260}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                           self.controller.create, req, self.req_id, data)
 
         # test for empty key.
         data = {"metadata": {"": "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.create, req, self.req_id, data)
index 57e46ec826fec2a95ebd0521dd4c54b9ea0deb00..ddec2d39c9430f23b9afed7c62598eb890cbc17a 100644 (file)
@@ -54,7 +54,7 @@ def return_volume_types_get_all_types(context, filters=None, marker=None,
                   vol_type_3=stub_volume_type(3)
                   )
     if list_result:
-        return result.values()
+        return list(result.values())
     return result
 
 
@@ -416,7 +416,7 @@ class VolumeTypesSerializerTest(test.TestCase):
 
         # Just getting some input data
         vtypes = return_volume_types_get_all_types(None)
-        text = serializer.serialize({'volume_types': vtypes.values()})
+        text = serializer.serialize({'volume_types': list(vtypes.values())})
 
         tree = etree.fromstring(text)
 
index 53730fda39b55004a94adec438190ba472bcd087..2ceff4e4ca6848ed783ae217d57580a25850b405 100644 (file)
@@ -277,7 +277,7 @@ class volumeMetaDataTest(test.TestCase):
         body = {"metadata": {"key1": "value1",
                              "key2": "value2",
                              "key3": "value3", }}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -299,7 +299,7 @@ class volumeMetaDataTest(test.TestCase):
         body = {"metadata": {"key1": "value1",
                              "key2": "value2",
                              "key3": "value3", }}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -333,7 +333,7 @@ class volumeMetaDataTest(test.TestCase):
                                  "key2": "value2",
                                  "key3": "value3",
                                  "KEY4": "value4"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -358,7 +358,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -370,7 +370,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -388,7 +388,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'POST'
         req.content_type = "application/json"
         body = {"metadata": {"key9": "value9"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.create, req, self.req_id, body)
 
@@ -407,7 +407,7 @@ class volumeMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -432,7 +432,7 @@ class volumeMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -471,7 +471,7 @@ class volumeMetaDataTest(test.TestCase):
                 'KEY20': 'value20',
             },
         }
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -490,7 +490,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -507,7 +507,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'meta': {}}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -520,7 +520,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         expected = {'metadata': ['asdf']}
-        req.body = jsonutils.dumps(expected)
+        req.body = jsonutils.dump_as_bytes(expected)
 
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update_all, req, self.req_id,
@@ -532,7 +532,7 @@ class volumeMetaDataTest(test.TestCase):
         req.method = 'PUT'
         req.content_type = "application/json"
         body = {'metadata': {'key10': 'value10'}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
 
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller.update_all, req, '100', body)
@@ -545,7 +545,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -565,7 +565,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -584,7 +584,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank('/v2/fake/volumes/asdf/metadata/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPNotFound,
@@ -610,7 +610,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -631,7 +631,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {("a" * 260): "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -652,7 +652,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": ("a" * 260)}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
         req.environ['cinder.context'] = fake_context
 
@@ -671,7 +671,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/key1')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1", "key2": "value2"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -684,7 +684,7 @@ class volumeMetaDataTest(test.TestCase):
         req = fakes.HTTPRequest.blank(self.url + '/bad')
         req.method = 'PUT'
         body = {"meta": {"key1": "value1"}}
-        req.body = jsonutils.dumps(body)
+        req.body = jsonutils.dump_as_bytes(body)
         req.headers["content-type"] = "application/json"
 
         self.assertRaises(webob.exc.HTTPBadRequest,
@@ -702,7 +702,7 @@ class volumeMetaDataTest(test.TestCase):
 
         # test for long key
         data = {"metadata": {"a" * 260: "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -713,7 +713,7 @@ class volumeMetaDataTest(test.TestCase):
 
         # test for long value
         data = {"metadata": {"key": "v" * 260}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
@@ -724,7 +724,7 @@ class volumeMetaDataTest(test.TestCase):
 
         # test for empty key.
         data = {"metadata": {"": "value1"}}
-        req.body = jsonutils.dumps(data)
+        req.body = jsonutils.dump_as_bytes(data)
         req.environ['cinder.context'] = fake_context
 
         with mock.patch.object(self.controller.volume_api,
index cc2d520cff9668166b4bb2e6b7d798a10a564166..60fd3d1f82694088c0dc1bbaaeaec171042f87cb 100644 (file)
@@ -27,7 +27,8 @@ cinder.tests.unit.api.test_common
 cinder.tests.unit.api.test_extensions
 cinder.tests.unit.api.test_versions
 cinder.tests.unit.api.test_xmlutil
-cinder.tests.unit.api.v2.test_volumes
+cinder.tests.unit.api.v1
+cinder.tests.unit.api.v2
 cinder.tests.unit.backup.drivers.test_backup_glusterfs
 cinder.tests.unit.backup.drivers.test_backup_nfs
 cinder.tests.unit.backup.drivers.test_backup_posix