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
This commit is contained in:
Tim Burke 2018-06-27 17:11:17 -07:00
parent d03fc9bc54
commit 783c7f6117
5 changed files with 16 additions and 14 deletions

View File

@ -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)

View File

@ -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')

View File

@ -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):

View File

@ -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'])

View File

@ -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}