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
This commit is contained in:
Angus Salkeld 2015-03-27 14:33:23 +10:00
parent 7ae372104e
commit 04d0e22bf8
2 changed files with 9 additions and 2 deletions

View File

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

View File

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