Merge "Append 'Openstack-Request-Id' header to the response"
This commit is contained in:
commit
250d26b05b
@ -89,6 +89,15 @@ class ContextHook(hooks.PecanHook):
|
|||||||
show_password=show_password,
|
show_password=show_password,
|
||||||
**creds)
|
**creds)
|
||||||
|
|
||||||
|
def after(self, state):
|
||||||
|
if state.request.context == {}:
|
||||||
|
# An incorrect url path will not create RequestContext
|
||||||
|
return
|
||||||
|
# NOTE(lintan): RequestContext will generate a request_id if no one
|
||||||
|
# passing outside, so it always contain a request_id.
|
||||||
|
request_id = state.request.context.request_id
|
||||||
|
state.response.headers['Openstack-Request-Id'] = request_id
|
||||||
|
|
||||||
|
|
||||||
class RPCHook(hooks.PecanHook):
|
class RPCHook(hooks.PecanHook):
|
||||||
"""Attach the rpcapi object to the request so controllers can get to it."""
|
"""Attach the rpcapi object to the request so controllers can get to it."""
|
||||||
|
@ -285,6 +285,26 @@ class TestContextHook(base.BaseApiTest):
|
|||||||
is_admin=False,
|
is_admin=False,
|
||||||
roles=headers['X-Roles'].split(','))
|
roles=headers['X-Roles'].split(','))
|
||||||
|
|
||||||
|
@mock.patch.object(context, 'RequestContext')
|
||||||
|
def test_context_hook_after_add_request_id(self, mock_ctx):
|
||||||
|
headers = fake_headers(admin=True)
|
||||||
|
reqstate = FakeRequestState(headers=headers)
|
||||||
|
reqstate.set_context()
|
||||||
|
reqstate.request.context.request_id = 'fake-id'
|
||||||
|
context_hook = hooks.ContextHook(None)
|
||||||
|
context_hook.after(reqstate)
|
||||||
|
self.assertIn('Openstack-Request-Id',
|
||||||
|
reqstate.response.headers)
|
||||||
|
self.assertEqual(
|
||||||
|
'fake-id',
|
||||||
|
reqstate.response.headers['Openstack-Request-Id'])
|
||||||
|
|
||||||
|
def test_context_hook_after_miss_context(self):
|
||||||
|
response = self.get_json('/bad/path',
|
||||||
|
expect_errors=True)
|
||||||
|
self.assertNotIn('Openstack-Request-Id',
|
||||||
|
response.headers)
|
||||||
|
|
||||||
|
|
||||||
class TestTrustedCallHook(base.BaseApiTest):
|
class TestTrustedCallHook(base.BaseApiTest):
|
||||||
def test_trusted_call_hook_not_admin(self):
|
def test_trusted_call_hook_not_admin(self):
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Append request_id as ``Openstack-Request-Id`` header to the response.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user