diff options
author | Sean Dague <sean@dague.net> | 2017-05-25 10:10:46 -0400 |
---|---|---|
committer | Sean Dague <sean@dague.net> | 2017-05-25 10:37:26 -0400 |
commit | 39c279e2edc8657a8925fa2126a98f6a85e402a3 (patch) | |
tree | 96c470f285856aea377c5dc2bbcdd8680b37b50a /nova/tests/unit/test_context.py | |
parent | a2beeab7204064aad33e51d10a39578f7802ae99 (diff) | |
download | nova-39c279e2edc8657a8925fa2126a98f6a85e402a3.tar.gz |
Have nova.context use super from_context
The nova.context should be a super set of oslo.context in all cases,
especially after we've deserialized on the other side of the RPC
bus. Our current code actually has a completely decoupled from_dict,
which means that as fields are added to oslo.context we don't pick up
any of those, and end up with a potentially broken and fragmented
context on the workers.
This fixes that by using the parent constructor for all the fields we
can, and only explicitly load in a few fields that we also need.
It also simplifies the testing so that we're just testing that our
extra fields end up in the context, and not exact matching everything
in the context, as oslo.context may add important things over time.
Change-Id: Ie683adb36d5e2a736ddbf714524c9c18f3c0d69c
Diffstat (limited to 'nova/tests/unit/test_context.py')
-rw-r--r-- | nova/tests/unit/test_context.py | 63 |
1 files changed, 3 insertions, 60 deletions
diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index bd48bc01c4..984b9c6c9f 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -198,66 +198,9 @@ class ContextTestCase(test.NoDBTestCase): 'user_id': 111, 'user_identity': '111 222 - - -', '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', - '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, - 'is_admin_project': 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) - values2 = ctx.to_dict() - self.assertEqual(values, values2) + for k, v in expected_values.items(): + self.assertIn(k, values2) + self.assertEqual(values2[k], v) @mock.patch.object(context.policy, 'authorize') def test_can(self, mock_authorize): |