From 3e07dcc424f87d3afbfa90d781480a197f4dec1d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 5 Mar 2022 00:05:06 +0900 Subject: [PATCH] Fix compatibility with oslo.context >= 4.0.0 The tenant argument of RequestContext is no longer available since oslo.context >= 4.0.0 . This change fixes the compatibility issue caused by that removal. Note that this still keeps reference to 'tenant' argument to make the code compatible with older oslo.context, but that can be removed once oslo.context >= 4.0.0 becomes available in upper-constraints. Change-Id: Ie671f50e5ff5a7c746f9e95691eaf4dd19937b52 --- mistral/context.py | 3 +++ mistral/tests/unit/base.py | 6 ++++++ mistral/tests/unit/services/test_event_engine.py | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mistral/context.py b/mistral/context.py index 1746a509a..cd04b0522 100644 --- a/mistral/context.py +++ b/mistral/context.py @@ -153,7 +153,10 @@ def _extract_mistral_auth_params(headers): 'insecure': insecure, 'auth_token': headers.get('X-Target-Auth-Token'), 'auth_uri': headers.get('X-Target-Auth-Uri'), + # TODO(tkajinam): Remove this once oslo.context >= 4.0.0 becomes + # avaialble 'tenant': headers.get('X-Target-Project-Id'), + 'project_id': headers.get('X-Target-Project-Id'), 'user': headers.get('X-Target-User-Id'), 'user_name': headers.get('X-Target-User-Name'), 'region_name': headers.get('X-Target-Region-Name'), diff --git a/mistral/tests/unit/base.py b/mistral/tests/unit/base.py index 0453560f9..c06ebd0de 100644 --- a/mistral/tests/unit/base.py +++ b/mistral/tests/unit/base.py @@ -51,7 +51,10 @@ def get_context(default=True, admin=False): return auth_context.MistralContext.from_dict({ 'user_name': 'test-user', 'user': '1-2-3-4', + # TODO(tkajinam): Remove this once oslo.context >= 4.0.0 becomes + # avaialble 'tenant': security.DEFAULT_PROJECT_ID, + 'project_id': security.DEFAULT_PROJECT_ID, 'project_name': 'test-project', 'is_admin': admin }) @@ -59,7 +62,10 @@ def get_context(default=True, admin=False): return auth_context.MistralContext.from_dict({ 'user_name': 'test-user', 'user': '9-0-44-5', + # TODO(tkajinam): Remove this once oslo.context >= 4.0.0 becomes + # avaialble 'tenant': '99-88-33', + 'project_id': '99-88-33', 'project_name': 'test-another', 'is_admin': admin }) diff --git a/mistral/tests/unit/services/test_event_engine.py b/mistral/tests/unit/services/test_event_engine.py index d051747dd..69ede79e5 100644 --- a/mistral/tests/unit/services/test_event_engine.py +++ b/mistral/tests/unit/services/test_event_engine.py @@ -104,7 +104,7 @@ class EventEngineTest(base.DbTestCase): auth_context.set_ctx(self.ctx) t['scope'] = 'public' - t['project_id'] = self.ctx.tenant + t['project_id'] = self.ctx.project_id trigger = db_api.create_event_trigger(t) # Switch to the user.