Move context from tenant to project_id

in the sudo context unit test:
DeprecationWarning: Property 'tenant' has moved to 'project_id'
in version '2.6' and will be removed in version '3.0'

oslo_context is deprecating the tenant field, so move to using
project_id. This does leave a less than ideal state where both
project_id and tenant are referenced (since all_tenants remains
untouched) but replacing 'tenant' with 'project' across the
entire codebase is a much larger task.

Change-Id: Id78112b49d5c0e99064fcb271aaded871da3f633
This commit is contained in:
michaeltchapman 2020-07-06 14:10:04 +10:00 committed by Erik Olof Gunnar Andersson
parent bff3d5f6e3
commit 6c80f6161a
2 changed files with 14 additions and 14 deletions

View File

@ -31,16 +31,16 @@ class DesignateContext(context.RequestContext):
_all_tenants = False
_hide_counts = False
_abandon = None
original_tenant = None
original_project_id = None
_edit_managed_records = False
_client_addr = None
FROM_DICT_EXTRA_KEYS = [
'original_tenant', 'service_catalog', 'all_tenants', 'abandon',
'original_project_id', 'service_catalog', 'all_tenants', 'abandon',
'edit_managed_records', 'tsigkey_id', 'hide_counts', 'client_addr',
]
def __init__(self, service_catalog=None, all_tenants=False, abandon=None,
tsigkey_id=None, original_tenant=None,
tsigkey_id=None, original_project_id=None,
edit_managed_records=False, hide_counts=False,
client_addr=None, user_auth_plugin=None, **kwargs):
super(DesignateContext, self).__init__(**kwargs)
@ -49,7 +49,7 @@ class DesignateContext(context.RequestContext):
self.service_catalog = service_catalog
self.tsigkey_id = tsigkey_id
self.original_tenant = original_tenant
self.original_project_id = original_project_id
self.all_tenants = all_tenants
self.abandon = abandon
@ -85,7 +85,7 @@ class DesignateContext(context.RequestContext):
# Update the dict with Designate specific extensions and overrides
d.update({
'user_identity': user_idt,
'original_tenant': self.original_tenant,
'original_project_id': self.original_project_id,
'service_catalog': self.service_catalog,
'all_tenants': self.all_tenants,
'abandon': self.abandon,
@ -121,14 +121,14 @@ class DesignateContext(context.RequestContext):
return context
def sudo(self, tenant):
def sudo(self, project_id):
policy.check('use_sudo', self)
LOG.info('Accepted sudo from user %(user)s to tenant %(tenant)s',
{'user': self.user_id, 'tenant': tenant})
self.original_tenant = self.tenant
self.tenant = tenant
LOG.info('Accepted sudo from user %(user)s to project_id %(project)s',
{'user': self.user_id, 'project': project_id})
self.original_project_id = self.project_id
self.project_id = project_id
@classmethod
def get_admin_context(cls, **kwargs):

View File

@ -99,10 +99,10 @@ class TestDesignateContext(designate.tests.TestCase):
@mock.patch.object(policy, 'check')
def test_sudo(self, mock_policy_check):
ctxt = context.DesignateContext(
user_id='12345', project_id='old_tenant'
user_id='12345', project_id='old_project'
)
ctxt.sudo('new_tenant')
ctxt.sudo('new_project')
self.assertTrue(mock_policy_check.called)
self.assertEqual('new_tenant', ctxt.tenant)
self.assertEqual('old_tenant', ctxt.original_tenant)
self.assertEqual('new_project', ctxt.project_id)
self.assertEqual('old_project', ctxt.original_project_id)