From 783c7f6117eee1be693b3136ee85c1f708250991 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Wed, 27 Jun 2018 17:11:17 -0700 Subject: [PATCH] py3: port proxy/controllers/info.py Yes, this means you can now start a proxy-server process on py3! And it will give you something useful on /info! Apparently you can even get auth tokens from tempauth, although the tempauth unit tests don't pass yet. Change-Id: I86ead2989b5934a7584cdd75719ce239826e01ec --- swift/common/middleware/gatekeeper.py | 11 +++++------ swift/proxy/controllers/info.py | 2 +- swift/proxy/server.py | 4 +++- test/unit/proxy/controllers/test_info.py | 10 +++++----- tox.ini | 3 ++- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/swift/common/middleware/gatekeeper.py b/swift/common/middleware/gatekeeper.py index 17a985defd..511394691a 100644 --- a/swift/common/middleware/gatekeeper.py +++ b/swift/common/middleware/gatekeeper.py @@ -109,15 +109,14 @@ class GatekeeperMiddleware(object): ] response_headers = fixed_response_headers() - removed = filter( - lambda h: self.outbound_condition(h[0]), - response_headers) + removed = [(header, value) for header, value in response_headers + if self.outbound_condition(header)] if removed: self.logger.debug('removed response headers: %s' % removed) - new_headers = filter( - lambda h: not self.outbound_condition(h[0]), - response_headers) + new_headers = [ + (header, value) for header, value in response_headers + if not self.outbound_condition(header)] return start_response(status, new_headers, exc_info) return start_response(status, response_headers, exc_info) return self.app(env, gatekeeper_response) diff --git a/swift/proxy/controllers/info.py b/swift/proxy/controllers/info.py index 89c5a8b3bf..1d148e9988 100644 --- a/swift/proxy/controllers/info.py +++ b/swift/proxy/controllers/info.py @@ -103,5 +103,5 @@ class InfoController(Controller): return HTTPOk(request=req, headers=headers, - body=info, + body=info.encode('ascii'), content_type='application/json; charset=UTF-8') diff --git a/swift/proxy/server.py b/swift/proxy/server.py index acc8bc7c36..51ca3fc24d 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -649,11 +649,13 @@ class Application(object): kwargs['exc_info'] = sys.exc_info() else: log = self.logger.exception + if isinstance(additional_info, bytes): + additional_info = additional_info.decode('utf-8') log(_('ERROR with %(type)s server %(ip)s:%(port)s/%(device)s' ' re: %(info)s'), {'type': typ, 'ip': node['ip'], 'port': node['port'], 'device': node['device'], - 'info': additional_info.decode('utf-8')}, + 'info': additional_info}, **kwargs) def modify_wsgi_pipeline(self, pipe): diff --git a/test/unit/proxy/controllers/test_info.py b/test/unit/proxy/controllers/test_info.py index 2317acfbe1..e9ba2a76aa 100644 --- a/test/unit/proxy/controllers/test_info.py +++ b/test/unit/proxy/controllers/test_info.py @@ -62,7 +62,7 @@ class TestInfoController(unittest.TestCase): resp = controller.GET(req) self.assertIsInstance(resp, HTTPException) self.assertEqual('200 OK', str(resp)) - info = json.loads(resp.body) + info = json.loads(resp.body.decode('ascii')) self.assertNotIn('admin', info) self.assertIn('foo', info) self.assertIn('bar', info['foo']) @@ -89,7 +89,7 @@ class TestInfoController(unittest.TestCase): resp = controller.GET(req) self.assertIsInstance(resp, HTTPException) self.assertEqual('200 OK', str(resp)) - info = json.loads(resp.body) + info = json.loads(resp.body.decode('ascii')) self.assertNotIn('admin', info) self.assertIn('foo', info) self.assertIn('bar', info['foo']) @@ -120,7 +120,7 @@ class TestInfoController(unittest.TestCase): resp = controller.GET(req) self.assertIsInstance(resp, HTTPException) self.assertEqual('200 OK', str(resp)) - info = json.loads(resp.body) + info = json.loads(resp.body.decode('ascii')) self.assertIn('foo', info) self.assertIn('bar', info['foo']) self.assertEqual(info['foo']['bar'], 'baz') @@ -156,7 +156,7 @@ class TestInfoController(unittest.TestCase): resp = controller.GET(req) self.assertIsInstance(resp, HTTPException) self.assertEqual('200 OK', str(resp)) - info = json.loads(resp.body) + info = json.loads(resp.body.decode('ascii')) self.assertIn('admin', info) self.assertIn('qux', info['admin']) self.assertIn('quux', info['admin']['qux']) @@ -279,7 +279,7 @@ class TestInfoController(unittest.TestCase): resp = controller.GET(req) self.assertIsInstance(resp, HTTPException) self.assertEqual('200 OK', str(resp)) - info = json.loads(resp.body) + info = json.loads(resp.body.decode('ascii')) self.assertNotIn('foo2', info) self.assertIn('admin', info) self.assertIn('disallowed_sections', info['admin']) diff --git a/tox.ini b/tox.ini index 2d9ded8ad2..47b5f55d0f 100644 --- a/tox.ini +++ b/tox.ini @@ -54,7 +54,8 @@ commands = test/unit/common/test_storage_policy.py \ test/unit/common/test_swob.py \ test/unit/common/test_utils.py \ - test/unit/common/test_wsgi.py} + test/unit/common/test_wsgi.py \ + test/unit/proxy/controllers/test_info.py} [testenv:py36] commands = {[testenv:py35]commands}