Skip to content

Commit a89b979

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Improve application credential validation speed" into unmaintained/yoga
2 parents 03a2163 + a0f3e4c commit a89b979

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

keystone/assignment/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ def _list_direct_role_assignments(self, role_id, user_id, group_id, system,
938938

939939
return assignments
940940

941+
@MEMOIZE_COMPUTED_ASSIGNMENTS
941942
def list_role_assignments(self, role_id=None, user_id=None, group_id=None,
942943
system=None, domain_id=None, project_id=None,
943944
include_subtree=False, inherited=None,
@@ -1080,6 +1081,7 @@ def delete_group_assignments(self, group_id):
10801081
system_assignments = self.list_system_grants_for_group(group_id)
10811082
for assignment in system_assignments:
10821083
self.delete_system_grant_for_group(group_id, assignment['id'])
1084+
COMPUTED_ASSIGNMENTS_REGION.invalidate()
10831085

10841086
def delete_user_assignments(self, user_id):
10851087
# FIXME(lbragstad): This should be refactored in the Rocky release so
@@ -1091,6 +1093,7 @@ def delete_user_assignments(self, user_id):
10911093
system_assignments = self.list_system_grants_for_user(user_id)
10921094
for assignment in system_assignments:
10931095
self.delete_system_grant_for_user(user_id, assignment['id'])
1096+
COMPUTED_ASSIGNMENTS_REGION.invalidate()
10941097

10951098
def check_system_grant_for_user(self, user_id, role_id):
10961099
"""Check if a user has a specific role on the system.
@@ -1163,6 +1166,7 @@ def delete_system_grant_for_user(self, user_id, role_id):
11631166
target_id = self._SYSTEM_SCOPE_TOKEN
11641167
inherited = False
11651168
self.driver.delete_system_grant(role_id, user_id, target_id, inherited)
1169+
COMPUTED_ASSIGNMENTS_REGION.invalidate()
11661170

11671171
def check_system_grant_for_group(self, group_id, role_id):
11681172
"""Check if a group has a specific role on the system.
@@ -1237,6 +1241,7 @@ def delete_system_grant_for_group(self, group_id, role_id):
12371241
self.driver.delete_system_grant(
12381242
role_id, group_id, target_id, inherited
12391243
)
1244+
COMPUTED_ASSIGNMENTS_REGION.invalidate()
12401245

12411246
def list_all_system_grants(self):
12421247
"""Return a list of all system grants."""

keystone/models/revoke_model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ def build_token_values(token):
242242
token_values['assignment_domain_id'] = None
243243

244244
role_list = []
245-
if token.roles is not None:
246-
for role in token.roles:
245+
token_roles = token.roles
246+
if token_roles is not None:
247+
for role in token_roles:
247248
role_list.append(role['id'])
248249
token_values['roles'] = role_list
249250

keystone/tests/unit/assignment/test_backends.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@ def _group_not_found(value):
643643
# attempts to lookup a group that has been deleted in the backend
644644
with mock.patch.object(PROVIDERS.identity_api, 'get_group',
645645
_group_not_found):
646+
# Mocking a dependent function makes the cache invalid
647+
keystone.assignment.COMPUTED_ASSIGNMENTS_REGION.invalidate()
648+
646649
assignment_list = PROVIDERS.assignment_api.list_role_assignments(
647650
include_names=True
648651
)
@@ -669,6 +672,9 @@ def _group_not_found(value):
669672
# in the backend
670673
with mock.patch.object(PROVIDERS.identity_api, 'list_users_in_group',
671674
_group_not_found):
675+
# Mocking a dependent function makes the cache invalid
676+
keystone.assignment.COMPUTED_ASSIGNMENTS_REGION.invalidate()
677+
672678
assignment_list = PROVIDERS.assignment_api.list_role_assignments(
673679
effective=True
674680
)

0 commit comments

Comments
 (0)