diff --git a/glance/api/v2/tasks.py b/glance/api/v2/tasks.py index a7f064707f..fe11695ead 100644 --- a/glance/api/v2/tasks.py +++ b/glance/api/v2/tasks.py @@ -249,7 +249,9 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def _inject_location_header(self, response, task): location = self._get_task_location(task) - response.headers['Location'] = location.encode('utf-8') + if six.PY2: + location = location.encode('utf-8') + response.headers['Location'] = location def _get_task_location(self, task): return '/v2/tasks/%s' % task.task_id diff --git a/glance/tests/integration/legacy_functional/base.py b/glance/tests/integration/legacy_functional/base.py index 174e3e69d6..f37bdfa0c2 100644 --- a/glance/tests/integration/legacy_functional/base.py +++ b/glance/tests/integration/legacy_functional/base.py @@ -202,7 +202,7 @@ class ApiTest(test_utils.BaseTestCase): def _load_paste_app(self, name, flavor, conf): conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name) - with open(conf_file_path, 'wb') as conf_file: + with open(conf_file_path, 'w') as conf_file: conf_file.write(conf) conf_file.flush() return config.load_paste_app(name, flavor=flavor, diff --git a/glance/tests/integration/legacy_functional/test_v1_api.py b/glance/tests/integration/legacy_functional/test_v1_api.py index 87f1136f81..a589591798 100644 --- a/glance/tests/integration/legacy_functional/test_v1_api.py +++ b/glance/tests/integration/legacy_functional/test_v1_api.py @@ -46,7 +46,7 @@ class TestApi(base.ApiTest): # 2. POST /images with public image named Image1 # attribute and no custom properties. Verify a 200 OK is returned - image_data = "*" * FIVE_KB + image_data = b"*" * FIVE_KB headers = minimal_headers('Image1') path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers, @@ -100,8 +100,9 @@ class TestApi(base.ApiTest): expected_value, response[expected_key])) - self.assertEqual("*" * FIVE_KB, content) - self.assertEqual(hashlib.md5("*" * FIVE_KB).hexdigest(), + content = content.encode('utf-8') + self.assertEqual(image_data, content) + self.assertEqual(hashlib.md5(image_data).hexdigest(), hashlib.md5(content).hexdigest()) # 5. GET /images @@ -290,7 +291,7 @@ class TestApi(base.ApiTest): self.assertEqual(image_id, response['x-image-meta-id']) # 4. PUT image with image data, verify 200 returned - image_data = "*" * FIVE_KB + image_data = b"*" * FIVE_KB headers = {'Content-Type': 'application/octet-stream'} path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'PUT', headers=headers, @@ -388,7 +389,7 @@ class TestApi(base.ApiTest): # Content-Type to application/octet-stream, verify a # 400 returned and that the error is readable. with tempfile.NamedTemporaryFile() as test_data_file: - test_data_file.write("XXX") + test_data_file.write(b"XXX") test_data_file.flush() path = "/v1/images" headers = minimal_headers('Image1') @@ -1003,7 +1004,7 @@ class TestApi(base.ApiTest): headers = minimal_headers('Image1') headers['X-Image-Meta-' + format] = 'bad_value' with tempfile.NamedTemporaryFile() as test_data_file: - test_data_file.write("XXX") + test_data_file.write(b"XXX") test_data_file.flush() response, content = self.http.request(path, 'POST', headers=headers, @@ -1054,7 +1055,7 @@ class TestApi(base.ApiTest): headers = minimal_headers('Image1') del headers['X-Image-Meta-' + format] with tempfile.NamedTemporaryFile() as test_data_file: - test_data_file.write("XXX") + test_data_file.write(b"XXX") test_data_file.flush() response, content = self.http.request(path, 'PUT', headers=headers, diff --git a/glance/tests/integration/v2/base.py b/glance/tests/integration/v2/base.py index 71cec787fa..f38c4e5721 100644 --- a/glance/tests/integration/v2/base.py +++ b/glance/tests/integration/v2/base.py @@ -197,7 +197,7 @@ class ApiTest(test_utils.BaseTestCase): def _load_paste_app(self, name, flavor, conf): conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name) - with open(conf_file_path, 'wb') as conf_file: + with open(conf_file_path, 'w') as conf_file: conf_file.write(conf) conf_file.flush() return config.load_paste_app(name, flavor=flavor, diff --git a/glance/tests/integration/v2/test_tasks_api.py b/glance/tests/integration/v2/test_tasks_api.py index 6df8019805..9bb5f9a9ba 100644 --- a/glance/tests/integration/v2/test_tasks_api.py +++ b/glance/tests/integration/v2/test_tasks_api.py @@ -114,6 +114,8 @@ class TestTasksApi(base.ApiTest): self.assertEqual(task_owner, task['owner']) self.assertEqual(task_data['type'], task['type']) self.assertEqual(task_data['input'], task['input']) + self.assertEqual("http://localhost" + path + "/" + task_id, + response.webob_resp.headers['Location']) return task, task_data diff --git a/glance/tests/utils.py b/glance/tests/utils.py index cdbb03c64a..19899c2f20 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -627,9 +627,12 @@ class Httplib2WsgiAdapter(object): def request(self, uri, method="GET", body=None, headers=None): req = webob.Request.blank(uri, method=method, headers=headers) - req.body = body + if isinstance(body, str): + req.body = body.encode('utf-8') + else: + req.body = body resp = req.get_response(self.app) - return Httplib2WebobResponse(resp), resp.body + return Httplib2WebobResponse(resp), resp.body.decode('utf-8') class Httplib2WebobResponse(object): diff --git a/tox.ini b/tox.ini index 2baf717e62..b880c0b4e0 100644 --- a/tox.ini +++ b/tox.ini @@ -64,7 +64,10 @@ commands = glance.tests.functional.v2.test_metadef_resourcetypes \ glance.tests.functional.v2.test_metadef_tags \ glance.tests.functional.v2.test_images \ - glance.tests.functional.v2.test_metadef_namespaces + glance.tests.functional.v2.test_metadef_namespaces \ + glance.tests.integration.v2.test_tasks_api \ + glance.tests.integration.v2.test_property_quota_violations \ + glance.tests.integration.legacy_functional.test_v1_api [testenv:pep8] commands =