Merge "Lazy-load context information requiring Keystone calls"
This commit is contained in:
commit
f83ad9d526
@ -238,6 +238,46 @@ class RequestContext(context.RequestContext):
|
||||
return self._auth_plugin
|
||||
|
||||
|
||||
class StoredContext(RequestContext):
|
||||
def _load_keystone_data(self):
|
||||
self._keystone_loaded = True
|
||||
auth_ref = self.clients.client('keystone').auth_ref
|
||||
|
||||
self.roles = auth_ref.role_names
|
||||
self.user_domain = auth_ref.user_domain_id
|
||||
self.project_domain = auth_ref.project_domain_id
|
||||
|
||||
@property
|
||||
def roles(self):
|
||||
if not getattr(self, '_keystone_loaded', False):
|
||||
self._load_keystone_data()
|
||||
return self._roles
|
||||
|
||||
@roles.setter
|
||||
def roles(self, roles):
|
||||
self._roles = roles
|
||||
|
||||
@property
|
||||
def user_domain(self):
|
||||
if not getattr(self, '_keystone_loaded', False):
|
||||
self._load_keystone_data()
|
||||
return self._user_domain
|
||||
|
||||
@user_domain.setter
|
||||
def user_domain(self, user_domain):
|
||||
self._user_domain = user_domain
|
||||
|
||||
@property
|
||||
def project_domain(self):
|
||||
if not getattr(self, '_keystone_loaded', False):
|
||||
self._load_keystone_data()
|
||||
return self._project_domain
|
||||
|
||||
@project_domain.setter
|
||||
def project_domain(self, project_domain):
|
||||
self._project_domain = project_domain
|
||||
|
||||
|
||||
def get_admin_context(show_deleted=False):
|
||||
return RequestContext(is_admin=True, show_deleted=show_deleted)
|
||||
|
||||
|
@ -209,12 +209,6 @@ class Stack(collections.Mapping):
|
||||
|
||||
if use_stored_context:
|
||||
self.context = self.stored_context()
|
||||
self.context.roles = self.context.clients.client(
|
||||
'keystone').auth_ref.role_names
|
||||
self.context.user_domain = self.context.clients.client(
|
||||
'keystone').auth_ref.user_domain_id
|
||||
self.context.project_domain = self.context.clients.client(
|
||||
'keystone').auth_ref.project_domain_id
|
||||
|
||||
self.clients = self.context.clients
|
||||
|
||||
@ -283,7 +277,7 @@ class Stack(collections.Mapping):
|
||||
creds['is_admin'] = False
|
||||
creds['overwrite'] = False
|
||||
|
||||
return common_context.RequestContext.from_dict(creds)
|
||||
return common_context.StoredContext.from_dict(creds)
|
||||
else:
|
||||
msg = _("Attempt to use stored_context with no user_creds")
|
||||
raise exception.Error(msg)
|
||||
|
@ -1339,6 +1339,8 @@ class StackTest(common.HeatTestCase):
|
||||
enforce_type=True)
|
||||
|
||||
self.m.StubOutWithMock(keystone.KeystoneClientPlugin, '_create')
|
||||
keystone.KeystoneClientPlugin._create().AndReturn(
|
||||
fakes.FakeKeystoneClient(user_id='auser123'))
|
||||
keystone.KeystoneClientPlugin._create().AndReturn(
|
||||
fakes.FakeKeystoneClient(user_id='auser123'))
|
||||
self.m.ReplayAll()
|
||||
|
Loading…
Reference in New Issue
Block a user