From 8af178c38fa2510fc4da726e1b7ac578b4a3070f Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Tue, 8 Mar 2022 22:28:59 +0100 Subject: [PATCH] Fix context unit test This was caused by the bump of oslo.context to 4.1.0 [1], which includes removal of the deprecated argument tenant from RequestContext [2]. Replace tenant key in the context object by project_id to fix the lower constraints job, which is still using oslo.context 2.22.0. [1] https://review.opendev.org/c/openstack/requirements/+/829599 [2] https://review.opendev.org/c/openstack/oslo.context/+/815938 Change-Id: I281ffa4f6fc29c691da48a792bc203818e334d9d --- blazar/tests/test_context.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/blazar/tests/test_context.py b/blazar/tests/test_context.py index ddeda2de..c7af1cd1 100644 --- a/blazar/tests/test_context.py +++ b/blazar/tests/test_context.py @@ -38,6 +38,14 @@ class TestBlazarContext(tests.TestCase): ctx = context.BlazarContext( user_id=111, project_id=222, request_id='req-679033b7-1755-4929-bf85-eb3bfaef7e0b') + + # NOTE(priteau): for compatibility with oslo.context<4.0.0 which + # returns a tenant key instead of project_id + ctx_dict = ctx.to_dict() + if 'tenant' in ctx_dict: + ctx_dict['project_id'] = ctx_dict['tenant'] + del ctx_dict['tenant'] + expected = { 'auth_token': None, 'domain': None, @@ -46,6 +54,7 @@ class TestBlazarContext(tests.TestCase): 'is_admin_project': True, 'project': 222, 'project_domain': None, + 'project_id': 222, 'read_only': False, 'request_id': 'req-679033b7-1755-4929-bf85-eb3bfaef7e0b', 'resource_uuid': None, @@ -53,11 +62,10 @@ class TestBlazarContext(tests.TestCase): 'service_catalog': [], 'show_deleted': False, 'system_scope': None, - 'tenant': 222, 'user': 111, 'user_domain': None, 'user_identity': '111 222 - - -'} - self.assertEqual(expected, ctx.to_dict()) + self.assertEqual(expected, ctx_dict) def test_service_catalog_default(self): ctxt = context.BlazarContext(user_id=uuidsentinel.user_id,