Fix context from_dict() for system_scope

A previous patch[1] added "system_scope" to the context for to_dict()
but the from_dict() method was not updated. This caused the
system_scope to always be None.
This patch corrects that by adding "system_scope" to the list of
values that may need to be extracted from the context dict.

[1] https://review.opendev.org/c/openstack/oslo.context/+/530509

Change-Id: Ica23d5c4183a692de3cb65a7ad72b19f47988ca6
(cherry picked from commit 8290621b05)
(cherry picked from commit 7187c672d4)
This commit is contained in:
Michael Johnson 2021-07-14 22:50:06 +00:00
parent be0e41e0fd
commit b124eb7df2
3 changed files with 8 additions and 1 deletions

View File

@ -419,6 +419,7 @@ class RequestContext(object):
values.get('project_domain_name'))
kwargs.setdefault('is_admin_project',
values.get('is_admin_project', True))
kwargs.setdefault('system_scope', values.get('system_scope'))
for key in cls.FROM_DICT_EXTRA_KEYS:
kwargs.setdefault(key, values.get(key))
return cls(**kwargs)

View File

@ -143,7 +143,8 @@ class ContextTest(test_base.BaseTestCase):
"request_id": "request1",
"global_request_id": "req-uuid",
"resource_uuid": "instance1",
"extra_data": "foo"
"extra_data": "foo",
"system_scope": "all"
}
ctx = context.RequestContext.from_dict(dct)
self.assertEqual(dct['auth_token'], ctx.auth_token)
@ -163,6 +164,7 @@ class ContextTest(test_base.BaseTestCase):
self.assertEqual(dct['domain_name'], ctx.domain_name)
self.assertEqual(dct['user_domain_name'], ctx.user_domain_name)
self.assertEqual(dct['project_domain_name'], ctx.project_domain_name)
self.assertEqual(dct['system_scope'], ctx.system_scope)
def test_from_dict_unknown_keys(self):
dct = {

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixes context from_dict() to properly handle system_scope.