Remove the deprecated argument tenant from RequestContext

The tenant argument of RequestContext have been deprecated long
time ago it is now removed by these changes.

Sem-Ver: api-break
Closes-Bug: 1505827
Change-Id: I2fded6f3476df1fb8c4e042ef28ed8ccb7ab0737
This commit is contained in:
Hervé Beraud 2021-10-29 09:08:57 +02:00
parent 57a4a5f576
commit f4cbe4c296
3 changed files with 29 additions and 30 deletions

View File

@ -181,13 +181,12 @@ class RequestContext(object):
accesses the system, as well as additional request information.
"""
user_idt_format = u'{user} {tenant} {domain} {user_domain} {p_domain}'
user_idt_format = u'{user} {project_id} {domain} {user_domain} {p_domain}'
# Can be overridden in subclasses to specify extra keys that should be
# read when constructing a context using from_dict.
FROM_DICT_EXTRA_KEYS = []
@_renamed_kwarg('user', 'user_id')
@_renamed_kwarg('tenant', 'project_id')
@_renamed_kwarg('domain', 'domain_id')
@_renamed_kwarg('user_domain', 'user_domain_id')
@_renamed_kwarg('project_domain', 'project_domain_id')
@ -277,9 +276,8 @@ class RequestContext(object):
self.update_store()
# NOTE(jamielennox): To prevent circular lookups on subclasses that might
# point user to user_id we make user/user_id tenant/project_id etc point
# point user to user_id we make user/user_id etc point
# to the same private variable rather than each other.
tenant = _moved_property('project_id', 'tenant', target='_project_id')
user = _moved_property('user_id', 'user', target='_user_id')
domain = _moved_property('domain_id', 'domain', target='_domain_id')
user_domain = _moved_property('user_domain_id',
@ -334,13 +332,13 @@ class RequestContext(object):
"""Return a dictionary of context attributes."""
user_idt = self.user_idt_format.format(
user=self.user_id or '-',
tenant=self.project_id or '-',
project_id=self.project_id or '-',
domain=self.domain_id or '-',
user_domain=self.user_domain_id or '-',
p_domain=self.project_domain_id or '-')
return {'user': self.user_id,
'tenant': self.project_id,
'project_id': self.project_id,
'system_scope': self.system_scope,
'project': self.project_id,
'domain': self.domain_id,
@ -392,7 +390,6 @@ class RequestContext(object):
@classmethod
@_renamed_kwarg('user', 'user_id')
@_renamed_kwarg('tenant', 'project_id')
@_renamed_kwarg('domain', 'domain_id')
@_renamed_kwarg('user_domain', 'user_domain_id')
@_renamed_kwarg('project_domain', 'project_domain_id')
@ -400,7 +397,7 @@ class RequestContext(object):
"""Construct a context object from a provided dictionary."""
kwargs.setdefault('auth_token', values.get('auth_token'))
kwargs.setdefault('user_id', values.get('user'))
kwargs.setdefault('project_id', values.get('tenant'))
kwargs.setdefault('project_id', values.get('project_id'))
kwargs.setdefault('domain_id', values.get('domain'))
kwargs.setdefault('user_domain_id', values.get('user_domain'))
kwargs.setdefault('project_domain_id', values.get('project_domain'))
@ -426,7 +423,6 @@ class RequestContext(object):
@classmethod
@_renamed_kwarg('user', 'user_id')
@_renamed_kwarg('tenant', 'project_id')
@_renamed_kwarg('domain', 'domain_id')
@_renamed_kwarg('user_domain', 'user_domain_id')
@_renamed_kwarg('project_domain', 'project_domain_id')

View File

@ -129,7 +129,7 @@ class ContextTest(test_base.BaseTestCase):
"auth_token": "token1",
"user": "user1",
"user_name": "user1_name",
"tenant": "tenant1",
"project_id": "tenant1",
"project_name": "tenant1_name",
"domain": "domain1",
"domain_name": "domain1_name",
@ -149,7 +149,7 @@ class ContextTest(test_base.BaseTestCase):
ctx = context.RequestContext.from_dict(dct)
self.assertEqual(dct['auth_token'], ctx.auth_token)
self.assertEqual(dct['user'], ctx.user_id)
self.assertEqual(dct['tenant'], ctx.project_id)
self.assertEqual(dct['project_id'], ctx.project_id)
self.assertEqual(dct['domain'], ctx.domain_id)
self.assertEqual(dct['user_domain'], ctx.user_domain_id)
self.assertEqual(dct['project_domain'], ctx.project_domain_id)
@ -198,7 +198,7 @@ class ContextTest(test_base.BaseTestCase):
self.assertEqual("token1", ctx.auth_token)
self.assertEqual("user2", ctx.user)
self.assertEqual("project1", ctx.project_name)
self.assertIsNone(ctx.tenant)
self.assertIsNone(ctx.project_id)
self.assertFalse(ctx.is_admin)
self.assertTrue(ctx.read_only)
@ -322,7 +322,7 @@ class ContextTest(test_base.BaseTestCase):
environ = {'HTTP_X_TENANT': value}
ctx = context.RequestContext.from_environ(environ=environ)
self.assertEqual(value, ctx.tenant)
self.assertEqual(value, ctx.project_id)
environ = {'HTTP_X_ROLE': value}
ctx = context.RequestContext.from_environ(environ=environ)
@ -354,7 +354,7 @@ class ContextTest(test_base.BaseTestCase):
self.assertEqual(new, ctx.project_id)
ctx = context.RequestContext.from_environ(environ=environ,
tenant=override)
project_id=override)
self.assertEqual(override, ctx.project_id)
environ = {'HTTP_X_TENANT_NAME': old,
@ -424,7 +424,7 @@ class ContextTest(test_base.BaseTestCase):
ctx = context.RequestContext(auth_token=auth_token,
user=user_id,
user_name=user_name,
tenant=project_id,
project_id=project_id,
project_name=project_name,
domain=domain_id,
domain_name=domain_name,
@ -458,7 +458,7 @@ class ContextTest(test_base.BaseTestCase):
d = ctx.to_dict()
self.assertIn('auth_token', d)
self.assertIn('user', d)
self.assertIn('tenant', d)
self.assertIn('project_id', d)
self.assertIn('domain', d)
self.assertIn('user_domain', d)
self.assertIn('project_domain', d)
@ -476,7 +476,7 @@ class ContextTest(test_base.BaseTestCase):
self.assertNotIn('project_domain_name', d)
self.assertEqual(auth_token, d['auth_token'])
self.assertEqual(project_id, d['tenant'])
self.assertEqual(project_id, d['project_id'])
self.assertEqual(domain_id, d['domain'])
self.assertEqual(user_domain_id, d['user_domain'])
self.assertEqual(project_domain_id, d['project_domain'])
@ -494,7 +494,7 @@ class ContextTest(test_base.BaseTestCase):
self.assertIn('auth_token', d)
self.assertEqual(d['auth_token'], '***')
self.assertIn('user', d)
self.assertIn('tenant', d)
self.assertIn('project_id', d)
self.assertIn('domain', d)
self.assertIn('user_domain', d)
self.assertIn('project_domain', d)
@ -546,7 +546,7 @@ class ContextTest(test_base.BaseTestCase):
def test_policy_dict(self):
user = uuid.uuid4().hex
user_domain = uuid.uuid4().hex
tenant = uuid.uuid4().hex
project_id = uuid.uuid4().hex
project_domain = uuid.uuid4().hex
roles = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex]
service_user_id = uuid.uuid4().hex
@ -556,7 +556,7 @@ class ContextTest(test_base.BaseTestCase):
# default is_admin_project is True
ctx = context.RequestContext(user=user,
user_domain=user_domain,
tenant=tenant,
project_id=project_id,
project_domain=project_domain,
roles=roles,
service_user_id=service_user_id,
@ -567,7 +567,7 @@ class ContextTest(test_base.BaseTestCase):
'user_domain_id': user_domain,
'system_scope': None,
'domain_id': None,
'project_id': tenant,
'project_id': project_id,
'project_domain_id': project_domain,
'roles': roles,
'is_admin_project': True,
@ -632,7 +632,7 @@ class ContextTest(test_base.BaseTestCase):
ctx = context.RequestContext(user=user,
user_domain=user_domain,
tenant=tenant,
project_id=project_id,
project_domain=project_domain,
roles=roles,
is_admin_project=False,
@ -644,7 +644,7 @@ class ContextTest(test_base.BaseTestCase):
'user_domain_id': user_domain,
'system_scope': None,
'domain_id': None,
'project_id': tenant,
'project_id': project_id,
'project_domain_id': project_domain,
'roles': roles,
'is_admin_project': False,
@ -658,13 +658,13 @@ class ContextTest(test_base.BaseTestCase):
def test_policy_deprecations(self):
user = uuid.uuid4().hex
user_domain = uuid.uuid4().hex
tenant = uuid.uuid4().hex
project_id = uuid.uuid4().hex
project_domain = uuid.uuid4().hex
roles = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex]
ctx = context.RequestContext(user=user,
user_domain=user_domain,
tenant=tenant,
project_id=project_id,
project_domain=project_domain,
roles=roles)
@ -707,11 +707,9 @@ class ContextTest(test_base.BaseTestCase):
self.assertEqual(0, len(self.warnings))
self.assertEqual(user_id, ctx.user)
self.assertEqual(1, len(self.warnings))
self.assertEqual(project_id, ctx.tenant)
self.assertEqual(2, len(self.warnings))
self.assertEqual(domain_id, ctx.domain)
self.assertEqual(3, len(self.warnings))
self.assertEqual(2, len(self.warnings))
self.assertEqual(user_domain_id, ctx.user_domain)
self.assertEqual(4, len(self.warnings))
self.assertEqual(3, len(self.warnings))
self.assertEqual(project_domain_id, ctx.project_domain)
self.assertEqual(5, len(self.warnings))
self.assertEqual(4, len(self.warnings))

View File

@ -0,0 +1,5 @@
---
upgrade:
- |
The ``tenant`` argument of ``RequestContext`` that was deprecated for
long time is now removed.