]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Adding domain to context
authorLuis A. Garcia <luis@linux.vnet.ibm.com>
Tue, 11 Mar 2014 15:34:02 +0000 (09:34 -0600)
committerLuis A. Garcia <luis@linux.vnet.ibm.com>
Tue, 11 Mar 2014 16:18:21 +0000 (10:18 -0600)
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

cinder/context.py
cinder/tests/test_context.py

index c97fdea8e5ea5fc97b4847096b9fb6912e18f991..e2a7f46e157e62bc6dba05447f84fb6765cd6d8b 100644 (file)
@@ -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):
index 81afed73fe0ebba50ddd4f698013e5431bf13790..1eea1a995dea4b63ea607453a6a7672d7ed2c3a4 100644 (file)
@@ -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"])