Remove deprecation warning messages

Below deprecation warning message is emitted continuously during each
API call due to the introduction of glance_store library in patch [1].

DeprecationWarning: Property 'user'  has moved to 'user_id' in version
'2.6' and will be removed in version '3.0'"
DeprecationWarning: Property 'tenant'  has moved to 'project_id' in
version '2.6' and will be removed in version '3.0'"

There is an issue in glance_store library which is reported in
LP bug [2] and it will be fixed by patch [3].
But we are not sure whether this issue will be fixed in Train
cycle Moreover, in future we will need to deal and remove
`tenant` and `user` attributes from context as these attributes
are deprecated from oslo.context in version 2.6 and it's planned
to be removed in 3.0. so this patch removes these 'tenant' and
'user' attributes from context. Also, added warnings fixture in
the unit test to ensure these attributes are not used anywhere
in the code. If used, it will result in test failure.

[1] : https://review.opendev.org/#/c/675600
[2] : https://bugs.launchpad.net/glance-store/+bug/1844462
[3] : https://review.opendev.org/#/c/683034

Implements: blueprint tosca-csar-mgmt-driver
Change-Id: I0cb320bbf237ebfac72b8e65128901c70cdd6780
This commit is contained in:
bhagyashris 2019-09-18 19:33:25 +05:30
parent d7ca6c5f9b
commit 554f7cd0a6
4 changed files with 47 additions and 23 deletions

View File

@ -60,17 +60,13 @@ class ContextBase(oslo_context.RequestContext):
if self.is_admin is None: if self.is_admin is None:
self.is_admin = policy.check_is_admin(self) self.is_admin = policy.check_is_admin(self)
@property
def project_id(self):
return self.tenant
@property @property
def tenant_id(self): def tenant_id(self):
return self.tenant return self.project_id
@tenant_id.setter @tenant_id.setter
def tenant_id(self, tenant_id): def tenant_id(self, tenant_id):
self.tenant = tenant_id self.project_id = tenant_id
@property @property
def tenant_name(self): def tenant_name(self):
@ -80,14 +76,6 @@ class ContextBase(oslo_context.RequestContext):
def tenant_name(self, tenant_name): def tenant_name(self, tenant_name):
self.project_name = tenant_name self.project_name = tenant_name
@property
def user_id(self):
return self.user
@user_id.setter
def user_id(self, user_id):
self.user = user_id
def to_dict(self): def to_dict(self):
context = super(ContextBase, self).to_dict() context = super(ContextBase, self).to_dict()
context.update({ context.update({
@ -103,7 +91,7 @@ class ContextBase(oslo_context.RequestContext):
@classmethod @classmethod
def from_dict(cls, values): def from_dict(cls, values):
return cls(user_id=values.get('user_id', values.get('user')), return cls(user_id=values.get('user_id'),
tenant_id=values.get('tenant_id', values.get('project_id')), tenant_id=values.get('tenant_id', values.get('project_id')),
is_admin=values.get('is_admin'), is_admin=values.get('is_admin'),
roles=values.get('roles'), roles=values.get('roles'),
@ -122,8 +110,8 @@ class ContextBase(oslo_context.RequestContext):
# but kept for backwards compatibility. Remove them in Pike # but kept for backwards compatibility. Remove them in Pike
# (oslo.context from Ocata release already issues deprecation warnings # (oslo.context from Ocata release already issues deprecation warnings
# for non-standard keys). # for non-standard keys).
values['user'] = self.user_id values['user_id'] = self.user_id
values['tenant'] = self.project_id values['project_id'] = self.project_id
values['domain'] = self.domain_id values['domain'] = self.domain_id
values['user_domain'] = self.user_domain_id values['user_domain'] = self.user_domain_id
values['project_domain'] = self.project_domain_id values['project_domain'] = self.project_domain_id

View File

@ -19,6 +19,7 @@ from oslo_config import fixture as config_fixture
from requests_mock.contrib import fixture as requests_mock_fixture from requests_mock.contrib import fixture as requests_mock_fixture
from tacker.tests import base from tacker.tests import base
from tacker.tests.unit import fixtures as tacker_fixtures
CONF = cfg.CONF CONF = cfg.CONF
@ -30,6 +31,9 @@ class TestCase(base.BaseTestCase):
self.config_fixture = self.useFixture(config_fixture.Config(CONF)) self.config_fixture = self.useFixture(config_fixture.Config(CONF))
CONF([], default_config_files=[]) CONF([], default_config_files=[])
# Limit the amount of DeprecationWarning messages in the unit test logs
self.useFixture(tacker_fixtures.WarningsFixture())
def _mock(self, target, new=mock.DEFAULT): def _mock(self, target, new=mock.DEFAULT):
patcher = mock.patch(target, new) patcher = mock.patch(target, new)
return patcher.start() return patcher.start()

View File

@ -0,0 +1,32 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Fixtures for Tacker unit tests."""
# NOTE(bhagyashris): This is needed for importing from fixtures.
from __future__ import absolute_import
import warnings
import fixtures as pyfixtures
class WarningsFixture(pyfixtures.Fixture):
"""Filters out warnings during test runs."""
def setUp(self):
super(WarningsFixture, self).setUp()
# NOTE(bhagyashris): user/tenant is deprecated in oslo.context
# so don't let anything new use it
warnings.filterwarnings(
'error', message="Property '.*' has moved to '.*'")
self.addCleanup(warnings.resetwarnings)

View File

@ -35,8 +35,8 @@ class TestTackerContext(base.BaseTestCase):
self.assertEqual('tenant_id', ctx.project_id) self.assertEqual('tenant_id', ctx.project_id)
self.assertEqual('tenant_id', ctx.tenant_id) self.assertEqual('tenant_id', ctx.tenant_id)
self.assertThat(ctx.request_id, matchers.StartsWith('req-')) self.assertThat(ctx.request_id, matchers.StartsWith('req-'))
self.assertEqual('user_id', ctx.user) self.assertEqual('user_id', ctx.user_id)
self.assertEqual('tenant_id', ctx.tenant) self.assertEqual('tenant_id', ctx.project_id)
self.assertIsNone(ctx.user_name) self.assertIsNone(ctx.user_name)
self.assertIsNone(ctx.tenant_name) self.assertIsNone(ctx.tenant_name)
@ -47,8 +47,8 @@ class TestTackerContext(base.BaseTestCase):
self.assertEqual('user_name', ctx.user_name) self.assertEqual('user_name', ctx.user_name)
self.assertEqual('tenant_name', ctx.tenant_name) self.assertEqual('tenant_name', ctx.tenant_name)
# Check user/tenant contains its ID even if user/tenant_name is passed # Check user/tenant contains its ID even if user/tenant_name is passed
self.assertEqual('user_id', ctx.user) self.assertEqual('user_id', ctx.user_id)
self.assertEqual('tenant_id', ctx.tenant) self.assertEqual('tenant_id', ctx.project_id)
def test_tacker_context_create_with_request_id(self): def test_tacker_context_create_with_request_id(self):
ctx = context.Context('user_id', 'tenant_id', request_id='req_id_xxx') ctx = context.Context('user_id', 'tenant_id', request_id='req_id_xxx')
@ -60,8 +60,8 @@ class TestTackerContext(base.BaseTestCase):
self.assertEqual('user_id', ctx_dict['user_id']) self.assertEqual('user_id', ctx_dict['user_id'])
self.assertEqual('tenant_id', ctx_dict['project_id']) self.assertEqual('tenant_id', ctx_dict['project_id'])
self.assertEqual(ctx.request_id, ctx_dict['request_id']) self.assertEqual(ctx.request_id, ctx_dict['request_id'])
self.assertEqual('user_id', ctx_dict['user']) self.assertEqual('user_id', ctx_dict['user_id'])
self.assertEqual('tenant_id', ctx_dict['tenant']) self.assertEqual('tenant_id', ctx_dict['project_id'])
self.assertIsNone(ctx_dict['user_name']) self.assertIsNone(ctx_dict['user_name'])
self.assertIsNone(ctx_dict['tenant_name']) self.assertIsNone(ctx_dict['tenant_name'])
self.assertIsNone(ctx_dict['project_name']) self.assertIsNone(ctx_dict['project_name'])