diff --git a/tacker/context.py b/tacker/context.py index e6078b736..f24de4b27 100644 --- a/tacker/context.py +++ b/tacker/context.py @@ -60,17 +60,13 @@ class ContextBase(oslo_context.RequestContext): if self.is_admin is None: self.is_admin = policy.check_is_admin(self) - @property - def project_id(self): - return self.tenant - @property def tenant_id(self): - return self.tenant + return self.project_id @tenant_id.setter def tenant_id(self, tenant_id): - self.tenant = tenant_id + self.project_id = tenant_id @property def tenant_name(self): @@ -80,14 +76,6 @@ class ContextBase(oslo_context.RequestContext): def tenant_name(self, 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): context = super(ContextBase, self).to_dict() context.update({ @@ -103,7 +91,7 @@ class ContextBase(oslo_context.RequestContext): @classmethod 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')), is_admin=values.get('is_admin'), roles=values.get('roles'), @@ -122,8 +110,8 @@ class ContextBase(oslo_context.RequestContext): # but kept for backwards compatibility. Remove them in Pike # (oslo.context from Ocata release already issues deprecation warnings # for non-standard keys). - values['user'] = self.user_id - values['tenant'] = self.project_id + values['user_id'] = self.user_id + values['project_id'] = self.project_id values['domain'] = self.domain_id values['user_domain'] = self.user_domain_id values['project_domain'] = self.project_domain_id diff --git a/tacker/tests/unit/base.py b/tacker/tests/unit/base.py index 263f13fff..34839750c 100644 --- a/tacker/tests/unit/base.py +++ b/tacker/tests/unit/base.py @@ -19,6 +19,7 @@ from oslo_config import fixture as config_fixture from requests_mock.contrib import fixture as requests_mock_fixture from tacker.tests import base +from tacker.tests.unit import fixtures as tacker_fixtures CONF = cfg.CONF @@ -30,6 +31,9 @@ class TestCase(base.BaseTestCase): self.config_fixture = self.useFixture(config_fixture.Config(CONF)) 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): patcher = mock.patch(target, new) return patcher.start() diff --git a/tacker/tests/unit/fixtures.py b/tacker/tests/unit/fixtures.py new file mode 100644 index 000000000..c0d4f9274 --- /dev/null +++ b/tacker/tests/unit/fixtures.py @@ -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) diff --git a/tacker/tests/unit/test_context.py b/tacker/tests/unit/test_context.py index 77523fd67..7dc9c324e 100644 --- a/tacker/tests/unit/test_context.py +++ b/tacker/tests/unit/test_context.py @@ -35,8 +35,8 @@ class TestTackerContext(base.BaseTestCase): self.assertEqual('tenant_id', ctx.project_id) self.assertEqual('tenant_id', ctx.tenant_id) self.assertThat(ctx.request_id, matchers.StartsWith('req-')) - self.assertEqual('user_id', ctx.user) - self.assertEqual('tenant_id', ctx.tenant) + self.assertEqual('user_id', ctx.user_id) + self.assertEqual('tenant_id', ctx.project_id) self.assertIsNone(ctx.user_name) self.assertIsNone(ctx.tenant_name) @@ -47,8 +47,8 @@ class TestTackerContext(base.BaseTestCase): self.assertEqual('user_name', ctx.user_name) self.assertEqual('tenant_name', ctx.tenant_name) # Check user/tenant contains its ID even if user/tenant_name is passed - self.assertEqual('user_id', ctx.user) - self.assertEqual('tenant_id', ctx.tenant) + self.assertEqual('user_id', ctx.user_id) + self.assertEqual('tenant_id', ctx.project_id) def test_tacker_context_create_with_request_id(self): 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('tenant_id', ctx_dict['project_id']) self.assertEqual(ctx.request_id, ctx_dict['request_id']) - self.assertEqual('user_id', ctx_dict['user']) - self.assertEqual('tenant_id', ctx_dict['tenant']) + self.assertEqual('user_id', ctx_dict['user_id']) + self.assertEqual('tenant_id', ctx_dict['project_id']) self.assertIsNone(ctx_dict['user_name']) self.assertIsNone(ctx_dict['tenant_name']) self.assertIsNone(ctx_dict['project_name'])