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() response_headers = fixed_response_headers()
removed = filter( removed = [(header, value) for header, value in response_headers
lambda h: self.outbound_condition(h[0]), if self.outbound_condition(header)]
response_headers)
if removed: if removed:
self.logger.debug('removed response headers: %s' % removed) self.logger.debug('removed response headers: %s' % removed)
new_headers = filter( new_headers = [
lambda h: not self.outbound_condition(h[0]), (header, value) for header, value in response_headers
response_headers) if not self.outbound_condition(header)]
return start_response(status, new_headers, exc_info) return start_response(status, new_headers, exc_info)
return start_response(status, response_headers, exc_info) return start_response(status, response_headers, exc_info)
return self.app(env, gatekeeper_response) return self.app(env, gatekeeper_response)

View File

@ -103,5 +103,5 @@ class InfoController(Controller):
return HTTPOk(request=req, return HTTPOk(request=req,
headers=headers, headers=headers,
body=info, body=info.encode('ascii'),
content_type='application/json; charset=UTF-8') content_type='application/json; charset=UTF-8')

View File

@ -649,11 +649,13 @@ class Application(object):
kwargs['exc_info'] = sys.exc_info() kwargs['exc_info'] = sys.exc_info()
else: else:
log = self.logger.exception 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' log(_('ERROR with %(type)s server %(ip)s:%(port)s/%(device)s'
' re: %(info)s'), ' re: %(info)s'),
{'type': typ, 'ip': node['ip'], {'type': typ, 'ip': node['ip'],
'port': node['port'], 'device': node['device'], 'port': node['port'], 'device': node['device'],
'info': additional_info.decode('utf-8')}, 'info': additional_info},
**kwargs) **kwargs)
def modify_wsgi_pipeline(self, pipe): def modify_wsgi_pipeline(self, pipe):

View File

@ -62,7 +62,7 @@ class TestInfoController(unittest.TestCase):
resp = controller.GET(req) resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException) self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp)) self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body) info = json.loads(resp.body.decode('ascii'))
self.assertNotIn('admin', info) self.assertNotIn('admin', info)
self.assertIn('foo', info) self.assertIn('foo', info)
self.assertIn('bar', info['foo']) self.assertIn('bar', info['foo'])
@ -89,7 +89,7 @@ class TestInfoController(unittest.TestCase):
resp = controller.GET(req) resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException) self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp)) self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body) info = json.loads(resp.body.decode('ascii'))
self.assertNotIn('admin', info) self.assertNotIn('admin', info)
self.assertIn('foo', info) self.assertIn('foo', info)
self.assertIn('bar', info['foo']) self.assertIn('bar', info['foo'])
@ -120,7 +120,7 @@ class TestInfoController(unittest.TestCase):
resp = controller.GET(req) resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException) self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp)) self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body) info = json.loads(resp.body.decode('ascii'))
self.assertIn('foo', info) self.assertIn('foo', info)
self.assertIn('bar', info['foo']) self.assertIn('bar', info['foo'])
self.assertEqual(info['foo']['bar'], 'baz') self.assertEqual(info['foo']['bar'], 'baz')
@ -156,7 +156,7 @@ class TestInfoController(unittest.TestCase):
resp = controller.GET(req) resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException) self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp)) self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body) info = json.loads(resp.body.decode('ascii'))
self.assertIn('admin', info) self.assertIn('admin', info)
self.assertIn('qux', info['admin']) self.assertIn('qux', info['admin'])
self.assertIn('quux', info['admin']['qux']) self.assertIn('quux', info['admin']['qux'])
@ -279,7 +279,7 @@ class TestInfoController(unittest.TestCase):
resp = controller.GET(req) resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException) self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp)) self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body) info = json.loads(resp.body.decode('ascii'))
self.assertNotIn('foo2', info) self.assertNotIn('foo2', info)
self.assertIn('admin', info) self.assertIn('admin', info)
self.assertIn('disallowed_sections', info['admin']) self.assertIn('disallowed_sections', info['admin'])

View File

@ -54,7 +54,8 @@ commands =
test/unit/common/test_storage_policy.py \ test/unit/common/test_storage_policy.py \
test/unit/common/test_swob.py \ test/unit/common/test_swob.py \
test/unit/common/test_utils.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] [testenv:py36]
commands = {[testenv:py35]commands} commands = {[testenv:py35]commands}