From: Luis A. Garcia Date: Tue, 11 Mar 2014 15:34:02 +0000 (-0600) Subject: Adding domain to context X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=bb5228cf79ff5bea543abc321b2dfad9fea5e9a5;p=openstack-build%2Fcinder-build.git Adding domain to context Add support for upcoming "domain" concept in Keystone V3 API in the context. This fix ensures there is a user_identity in the context for the corresponding new attribute in the log format string added in oslo. The oslo change has the same change-id as this one. Closes-Bug: #1290503 Change-Id: Ic2cf3e52cfcc0b8adccdf9c59afaa4014708a303 --- diff --git a/cinder/context.py b/cinder/context.py index c97fdea8e..e2a7f46e1 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -39,11 +39,13 @@ class RequestContext(object): Represents the user taking a given action within the system. """ + user_idt_format = '{user} {tenant} {domain} {user_domain} {p_domain}' def __init__(self, user_id, project_id, is_admin=None, read_deleted="no", roles=None, project_name=None, remote_address=None, timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, service_catalog=None, + domain=None, user_domain=None, project_domain=None, **kwargs): """Initialize RequestContext. @@ -63,6 +65,9 @@ class RequestContext(object): self.user_id = user_id self.project_id = project_id + self.domain = domain + self.user_domain = user_domain + self.project_domain = project_domain self.roles = roles or [] self.project_name = project_name self.is_admin = is_admin @@ -113,9 +118,19 @@ class RequestContext(object): local.store.context = self def to_dict(self): + user_idt = ( + self.user_idt_format.format(user=self.user or '-', + tenant=self.tenant or '-', + domain=self.domain or '-', + user_domain=self.user_domain or '-', + p_domain=self.project_domain or '-')) + return {'user_id': self.user_id, 'project_id': self.project_id, 'project_name': self.project_name, + 'domain': self.domain, + 'user_domain': self.user_domain, + 'project_domain': self.project_domain, 'is_admin': self.is_admin, 'read_deleted': self.read_deleted, 'roles': self.roles, @@ -126,7 +141,8 @@ class RequestContext(object): 'quota_class': self.quota_class, 'service_catalog': self.service_catalog, 'tenant': self.tenant, - 'user': self.user} + 'user': self.user, + 'user_identity': user_idt} @classmethod def from_dict(cls, values): diff --git a/cinder/tests/test_context.py b/cinder/tests/test_context.py index 81afed73f..1eea1a995 100644 --- a/cinder/tests/test_context.py +++ b/cinder/tests/test_context.py @@ -86,3 +86,11 @@ class ContextTestCase(test.TestCase): ctxt = context.RequestContext('111', '222', service_catalog=service_catalog) self.assertEqual(ctxt.service_catalog, compute_catalog) + + def test_user_identity(self): + ctx = context.RequestContext("user", "tenant", + domain="domain", + user_domain="user-domain", + project_domain="project-domain") + self.assertEqual('user tenant domain user-domain project-domain', + ctx.to_dict()["user_identity"])