From 04d0e22bf8d7a13434939fc00bcb5c11635addcf Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Fri, 27 Mar 2015 14:33:23 +1000 Subject: [PATCH] Add user_identity to RequestContext.to_dict() This makes heat logging format more consistent with other services as oslo.log uses this in the Context formatter: https://github.com/openstack/oslo.log/blob/master/oslo_log/formatters.py#L214 Change-Id: If85fca19d1e37decc35f965b92e6430e46d9842a Closes-bug: #1437144 --- heat/common/context.py | 6 +++++- heat/tests/test_common_context.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/heat/common/context.py b/heat/common/context.py index b716870dd..09969a0cb 100644 --- a/heat/common/context.py +++ b/heat/common/context.py @@ -129,6 +129,9 @@ class RequestContext(context.RequestContext): return self._clients def to_dict(self): + user_idt = '{user} {tenant}'.format(user=self.username or '-', + tenant=self.tenant or '-') + return {'auth_token': self.auth_token, 'username': self.username, 'user_id': self.user_id, @@ -145,7 +148,8 @@ class RequestContext(context.RequestContext): 'user': self.user, 'request_id': self.request_id, 'show_deleted': self.show_deleted, - 'region_name': self.region_name} + 'region_name': self.region_name, + 'user_identity': user_idt} @classmethod def from_dict(cls, values): diff --git a/heat/tests/test_common_context.py b/heat/tests/test_common_context.py index d470acc69..d53d47e61 100644 --- a/heat/tests/test_common_context.py +++ b/heat/tests/test_common_context.py @@ -43,7 +43,8 @@ class TestRequestContext(common.HeatTestCase): 'tenant': 'atenant', 'auth_url': 'http://xyz', 'aws_creds': 'blah', - 'region_name': 'regionOne'} + 'region_name': 'regionOne', + 'user_identity': 'mick atenant'} super(TestRequestContext, self).setUp() @@ -79,6 +80,8 @@ class TestRequestContext(common.HeatTestCase): ctx = context.RequestContext.from_dict(self.ctx) for k in self.ctx: + if k == 'user_identity': + continue self.assertEqual(self.ctx.get(k), ctx.to_dict().get(k)) override = '%s_override' % k setattr(ctx, k, override)