diff --git a/glance/common/client.py b/glance/common/client.py index b4d523bc..d7b5b49f 100644 --- a/glance/common/client.py +++ b/glance/common/client.py @@ -456,7 +456,7 @@ class BaseClient(object): return method.lower() in ('post', 'put') def _simple(body): - return body is None or isinstance(body, six.string_types) + return body is None or isinstance(body, bytes) def _filelike(body): return hasattr(body, 'read') diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 212cddf5..2a14e1b1 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -813,7 +813,7 @@ class JSONResponseSerializer(object): return jsonutils.to_primitive(obj) def to_json(self, data): - return jsonutils.dumps(data, default=self._sanitizer) + return jsonutils.dump_as_bytes(data, default=self._sanitizer) def default(self, response, result): response.content_type = 'application/json' diff --git a/glance/tests/unit/common/test_rpc.py b/glance/tests/unit/common/test_rpc.py index bc6619d8..17113dde 100644 --- a/glance/tests/unit/common/test_rpc.py +++ b/glance/tests/unit/common/test_rpc.py @@ -265,7 +265,7 @@ class TestRPCJSONSerializer(test_utils.BaseTestCase): def test_to_json(self): fixture = {"key": "value"} - expected = '{"key": "value"}' + expected = b'{"key": "value"}' actual = rpc.RPCJSONSerializer().to_json(fixture) self.assertEqual(expected, actual) diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py index ee7591af..3a4c37bc 100644 --- a/glance/tests/unit/common/test_wsgi.py +++ b/glance/tests/unit/common/test_wsgi.py @@ -377,13 +377,13 @@ class JSONResponseSerializerTest(test_utils.BaseTestCase): def test_to_json(self): fixture = {"key": "value"} - expected = '{"key": "value"}' + expected = b'{"key": "value"}' actual = wsgi.JSONResponseSerializer().to_json(fixture) self.assertEqual(expected, actual) def test_to_json_with_date_format_value(self): fixture = {"date": datetime.datetime(1901, 3, 8, 2)} - expected = '{"date": "1901-03-08T02:00:00.000000"}' + expected = b'{"date": "1901-03-08T02:00:00.000000"}' actual = wsgi.JSONResponseSerializer().to_json(fixture) self.assertEqual(expected, actual) @@ -397,7 +397,7 @@ class JSONResponseSerializerTest(test_utils.BaseTestCase): def test_to_json_with_set(self): fixture = set(["foo"]) - expected = '["foo"]' + expected = b'["foo"]' actual = wsgi.JSONResponseSerializer().to_json(fixture) self.assertEqual(expected, actual) diff --git a/glance/tests/unit/v2/test_registry_client.py b/glance/tests/unit/v2/test_registry_client.py index fc174aca..ca3ec1a2 100644 --- a/glance/tests/unit/v2/test_registry_client.py +++ b/glance/tests/unit/v2/test_registry_client.py @@ -26,6 +26,7 @@ import uuid from mock import patch from oslo_utils import timeutils +from six.moves import reload_module from glance.common import config from glance.common import exception @@ -592,7 +593,7 @@ class TestRegistryV2Client(base.IsolatedUnitTest, next_state = 'saving' fixture = {'name': 'fake image', 'disk_format': 'vmdk', - 'min_disk': str(2 ** 31 + 1), + 'min_disk': 2 ** 31 + 1, 'status': next_state} image = self.client.image_get(image_id=UUID2) @@ -611,7 +612,7 @@ class TestRegistryV2Client(base.IsolatedUnitTest, next_state = 'saving' fixture = {'name': 'fake image', 'disk_format': 'vmdk', - 'min_ram': str(2 ** 31 + 1), + 'min_ram': 2 ** 31 + 1, 'status': next_state} image = self.client.image_get(image_id=UUID2) @@ -731,7 +732,7 @@ class TestRegistryV2ClientApi(base.IsolatedUnitTest): def setUp(self): """Establish a clean test environment""" super(TestRegistryV2ClientApi, self).setUp() - reload(rapi) + reload_module(rapi) def tearDown(self): """Clear the test environment""" diff --git a/tox.ini b/tox.ini index e1786ca3..e310725a 100644 --- a/tox.ini +++ b/tox.ini @@ -81,6 +81,7 @@ commands = glance.tests.unit.v2.test_images_resource \ glance.tests.unit.v2.test_metadef_resources \ glance.tests.unit.v2.test_registry_api \ + glance.tests.unit.v2.test_registry_client \ glance.tests.unit.v2.test_schemas_resource \ glance.tests.unit.v2.test_tasks_resource