diff options
author | Tony Breeds <tony@bakeyournoodle.com> | 2016-07-15 14:49:54 +1000 |
---|---|---|
committer | Tony Breeds <tony@bakeyournoodle.com> | 2016-07-27 18:09:30 -0500 |
commit | 80738df83f4cdd7a3143b157b73d1a9e6b3b2c40 (patch) | |
tree | a154eb473c82378715cf5cc0ef993b6d3c815786 | |
parent | 66127c563ef31f2fdfe26c3dc9a5ad2f31b5da20 (diff) | |
download | nova-80738df83f4cdd7a3143b157b73d1a9e6b3b2c40.tar.gz |
Add support for oslo.context 2.6.0
The 2.6.0 release of oslo.context adds a new attribute
'is_admin_project'. Always include that attribute when serializing the
object, and expect it in our tests.
Change-Id: I563cf810385e84ab30d49ef079b75df279006f0d
Related-Bug: 1602081
-rw-r--r-- | nova/context.py | 7 | ||||
-rw-r--r-- | nova/tests/unit/test_context.py | 33 |
2 files changed, 40 insertions, 0 deletions
diff --git a/nova/context.py b/nova/context.py index 60f2b3f4c4..22e194a0fd 100644 --- a/nova/context.py +++ b/nova/context.py @@ -174,6 +174,13 @@ class RequestContext(context.RequestContext): 'instance_lock_checked': getattr(self, 'instance_lock_checked', False) }) + # NOTE(tonyb): This can be removed once we're certain to have a + # RequestContext contains 'is_admin_project', We can only get away with + # this because we "know" the default value of 'is_admin_project' which + # is very fragile. + values.update({ + 'is_admin_project': getattr(self, 'is_admin_project', True), + }) return values @classmethod diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index 4405c1bd54..f5ec1a3104 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -164,6 +164,7 @@ class ContextTestCase(test.NoDBTestCase): 'domain': None, 'instance_lock_checked': False, 'is_admin': False, + 'is_admin_project': True, 'project_id': 222, 'project_domain': None, 'project_name': None, @@ -186,6 +187,37 @@ class ContextTestCase(test.NoDBTestCase): 'user_name': None} self.assertEqual(expected_values, values2) + def test_convert_from_dict_to_dict_version_2_4_x(self): + # fake dict() created with oslo.context 2.4.x, Missing is_admin_project + # key + values = {'user': '111', + 'user_id': '111', + 'tenant': '222', + 'project_id': '222', + 'domain': None, 'project_domain': None, + 'auth_token': None, + 'resource_uuid': None, 'read_only': False, + 'user_identity': '111 222 - - -', + 'instance_lock_checked': False, + 'user_name': None, 'project_name': None, + 'timestamp': '2015-03-02T20:03:59.416299', + 'remote_address': None, 'quota_class': None, + 'is_admin': True, + 'service_catalog': [], + 'read_deleted': 'no', 'show_deleted': False, + 'roles': [], + 'request_id': 'req-956637ad-354a-4bc5-b969-66fd1cc00f50', + 'user_domain': None} + ctx = context.RequestContext.from_dict(values) + self.assertEqual('111', ctx.user) + self.assertEqual('222', ctx.tenant) + self.assertEqual('111', ctx.user_id) + self.assertEqual('222', ctx.project_id) + # to_dict() will add is_admin_project + values.update({'is_admin_project': True}) + values2 = ctx.to_dict() + self.assertEqual(values, values2) + def test_convert_from_dict_then_to_dict(self): values = {'user': '111', 'user_id': '111', @@ -200,6 +232,7 @@ class ContextTestCase(test.NoDBTestCase): 'timestamp': '2015-03-02T20:03:59.416299', 'remote_address': None, 'quota_class': None, 'is_admin': True, + 'is_admin_project': True, 'service_catalog': [], 'read_deleted': 'no', 'show_deleted': False, 'roles': [], |