Rename context.tenant to context.project_id

During execution of the service we get deprecation warnings like

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

So, it's reasonable to rename it until it's too late.

Change-Id: I6030948c64d21d4799438c4c89e8ffbd999fcb94
This commit is contained in:
Mike Fedosin 2017-10-31 15:26:11 +03:00
parent b9652017ed
commit 6986efbd3e
7 changed files with 26 additions and 26 deletions

View File

@ -314,7 +314,7 @@ class ArtifactsController(api_versioning.VersionedResource):
:param values: dict with artifact fields :param values: dict with artifact fields
:return: definition of created artifact :return: definition of created artifact
""" """
if req.context.tenant is None or req.context.read_only: if req.context.project_id is None or req.context.read_only:
msg = _("It's forbidden to anonymous users to create artifacts.") msg = _("It's forbidden to anonymous users to create artifacts.")
raise exc.Forbidden(msg) raise exc.Forbidden(msg)
if not values.get('name'): if not values.get('name'):

View File

@ -386,11 +386,11 @@ def _apply_query_base_filters(query, context):
return query return query
# If anonymous user, return only public artifacts. # If anonymous user, return only public artifacts.
# However, if context.tenant has a value, return both # However, if context.project_id has a value, return both
# public and private artifacts of the owner. # public and private artifacts of the owner.
if context.tenant is not None: if context.project_id is not None:
query = query.filter( query = query.filter(
or_(models.Artifact.owner == context.tenant, or_(models.Artifact.owner == context.project_id,
models.Artifact.visibility == 'public')) models.Artifact.visibility == 'public'))
else: else:
query = query.filter( query = query.filter(
@ -592,7 +592,7 @@ def _do_blobs(artifact, new_blobs):
def count_artifact_number(context, session, type_name=None): def count_artifact_number(context, session, type_name=None):
"""Return a number of artifacts for tenant.""" """Return a number of artifacts for tenant."""
query = session.query(func.count(models.Artifact.id)).filter( query = session.query(func.count(models.Artifact.id)).filter(
models.Artifact.owner == context.tenant) models.Artifact.owner == context.project_id)
if type_name is not None: if type_name is not None:
query = query.filter(models.Artifact.type_name == type_name) query = query.filter(models.Artifact.type_name == type_name)
return query.order_by(None).scalar() or 0 return query.order_by(None).scalar() or 0
@ -603,7 +603,7 @@ def calculate_uploaded_data(context, session, type_name=None):
query = session.query( query = session.query(
func.sum(models.ArtifactBlob.size)).join( func.sum(models.ArtifactBlob.size)).join(
models.Artifact, aliased=True).filter( models.Artifact, aliased=True).filter(
models.Artifact.owner == context.tenant) models.Artifact.owner == context.project_id)
if type_name is not None: if type_name is not None:
query = query.filter(models.Artifact.type_name == type_name) query = query.filter(models.Artifact.type_name == type_name)
return query.order_by(None).scalar() or 0 return query.order_by(None).scalar() or 0

View File

@ -232,14 +232,14 @@ class Engine(object):
'id': uuidutils.generate_uuid(), 'id': uuidutils.generate_uuid(),
'name': values.pop('name'), 'name': values.pop('name'),
'version': version, 'version': version,
'owner': context.tenant, 'owner': context.project_id,
'created_at': timeutils.utcnow(), 'created_at': timeutils.utcnow(),
'updated_at': timeutils.utcnow() 'updated_at': timeutils.utcnow()
} }
af = artifact_type.init_artifact(context, init_values) af = artifact_type.init_artifact(context, init_values)
# acquire scoped lock and execute artifact create # acquire scoped lock and execute artifact create
with self._create_scoped_lock(context, type_name, af.name, with self._create_scoped_lock(context, type_name, af.name,
af.version, context.tenant): af.version, context.project_id):
quota.verify_artifact_count(context, type_name) quota.verify_artifact_count(context, type_name)
for field_name, value in values.items(): for field_name, value in values.items():
if af.is_blob(field_name) or af.is_blob_dict(field_name): if af.is_blob(field_name) or af.is_blob_dict(field_name):
@ -735,7 +735,7 @@ class Engine(object):
:param project_id: id of the project for which to show quotas :param project_id: id of the project for which to show quotas
:return: definition of requested quotas for the project :return: definition of requested quotas for the project
""" """
project_id = project_id or context.tenant project_id = project_id or context.project_id
action_name = "artifact:list_project_quotas" action_name = "artifact:list_project_quotas"
policy.authorize(action_name, {'project_id': project_id}, context) policy.authorize(action_name, {'project_id': project_id}, context)
qs = self.config_quotas.copy() qs = self.config_quotas.copy()

View File

@ -32,7 +32,7 @@ def verify_artifact_count(context, type_name):
CONF, 'artifact_type:' + type_name).max_artifact_number CONF, 'artifact_type:' + type_name).max_artifact_number
# update limits if they were reassigned for project # update limits if they were reassigned for project
project_id = context.tenant project_id = context.project_id
quotas = list_quotas(project_id).get(project_id, {}) quotas = list_quotas(project_id).get(project_id, {})
if 'max_artifact_number' in quotas: if 'max_artifact_number' in quotas:
global_limit = quotas['max_artifact_number'] global_limit = quotas['max_artifact_number']
@ -82,7 +82,7 @@ def verify_uploaded_data_amount(context, type_name, data_amount=None):
type_limit = getattr(CONF, 'artifact_type:' + type_name).max_uploaded_data type_limit = getattr(CONF, 'artifact_type:' + type_name).max_uploaded_data
# update limits if they were reassigned for project # update limits if they were reassigned for project
project_id = context.tenant project_id = context.project_id
quotas = list_quotas(project_id).get(project_id, {}) quotas = list_quotas(project_id).get(project_id, {})
if 'max_uploaded_data' in quotas: if 'max_uploaded_data' in quotas:
global_limit = quotas['max_uploaded_data'] global_limit = quotas['max_uploaded_data']

View File

@ -42,7 +42,7 @@ class TestContextMiddleware(base.BaseTestCase):
self._build_middleware().process_request(req) self._build_middleware().process_request(req)
self.assertEqual('token1', req.context.auth_token) self.assertEqual('token1', req.context.auth_token)
self.assertEqual('user1', req.context.user) self.assertEqual('user1', req.context.user)
self.assertEqual('tenant1', req.context.tenant) self.assertEqual('tenant1', req.context.project_id)
self.assertEqual(['role1', 'role2'], req.context.roles) self.assertEqual(['role1', 'role2'], req.context.roles)
def test_is_admin_flag(self): def test_is_admin_flag(self):
@ -88,7 +88,7 @@ class TestContextMiddleware(base.BaseTestCase):
middleware.process_request(req) middleware.process_request(req)
self.assertIsNone(req.context.auth_token) self.assertIsNone(req.context.auth_token)
self.assertIsNone(req.context.user) self.assertIsNone(req.context.user)
self.assertIsNone(req.context.tenant) self.assertIsNone(req.context.project_id)
self.assertEqual([], req.context.roles) self.assertEqual([], req.context.roles)
self.assertFalse(req.context.is_admin) self.assertFalse(req.context.is_admin)
self.assertTrue(req.context.read_only) self.assertTrue(req.context.read_only)

View File

@ -41,7 +41,7 @@ class TestTrustedAuthMiddleware(base.BaseTestCase):
self.assertEqual(token, req.context.auth_token) self.assertEqual(token, req.context.auth_token)
self.assertEqual('user1', req.context.user) self.assertEqual('user1', req.context.user)
self.assertEqual('tenant1', req.context.tenant) self.assertEqual('tenant1', req.context.project_id)
self.assertEqual(['role1', 'role2'], req.context.roles) self.assertEqual(['role1', 'role2'], req.context.roles)
self.assertIn('service_catalog', req.context.to_dict()) self.assertIn('service_catalog', req.context.to_dict())
@ -123,7 +123,7 @@ class TestTrustedAuthMiddleware(base.BaseTestCase):
middleware.process_request(req) middleware.process_request(req)
self.assertIsNone(req.context.auth_token) self.assertIsNone(req.context.auth_token)
self.assertIsNone(req.context.user) self.assertIsNone(req.context.user)
self.assertIsNone(req.context.tenant) self.assertIsNone(req.context.project_id)
self.assertEqual([], req.context.roles) self.assertEqual([], req.context.roles)
self.assertFalse(req.context.is_admin) self.assertFalse(req.context.is_admin)
self.assertTrue(req.context.read_only) self.assertTrue(req.context.read_only)

View File

@ -427,13 +427,13 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
0, len(self.controller.list(user2_req, 'all')['artifacts'])) 0, len(self.controller.list(user2_req, 'all')['artifacts']))
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_artifact_number:images": 3, "max_artifact_number:images": 3,
"max_artifact_number:heat_templates": 15, "max_artifact_number:heat_templates": 15,
"max_artifact_number:murano_packages": 10, "max_artifact_number:murano_packages": 10,
"max_artifact_number": 10 "max_artifact_number": 10
}, },
user2_req.context.tenant: { user2_req.context.project_id: {
"max_artifact_number": 10 "max_artifact_number": 10
} }
} }
@ -475,7 +475,7 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
# disable global limit for user1 and try to create 15 heat templates # disable global limit for user1 and try to create 15 heat templates
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_artifact_number:images": 3, "max_artifact_number:images": 3,
"max_artifact_number:heat_templates": 15, "max_artifact_number:heat_templates": 15,
"max_artifact_number:murano_packages": 10, "max_artifact_number:murano_packages": 10,
@ -494,7 +494,7 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
# disable type limit for heat templates and create 1 heat templates # disable type limit for heat templates and create 1 heat templates
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_artifact_number:images": 3, "max_artifact_number:images": 3,
"max_artifact_number:heat_templates": -1, "max_artifact_number:heat_templates": -1,
"max_artifact_number:murano_packages": 10, "max_artifact_number:murano_packages": 10,
@ -517,13 +517,13 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
0, len(self.controller.list(user2_req, 'all')['artifacts'])) 0, len(self.controller.list(user2_req, 'all')['artifacts']))
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_uploaded_data:images": 1500, "max_uploaded_data:images": 1500,
"max_uploaded_data:sample_artifact": 300, "max_uploaded_data:sample_artifact": 300,
"max_uploaded_data:murano_packages": 1000, "max_uploaded_data:murano_packages": 1000,
"max_uploaded_data": 1000 "max_uploaded_data": 1000
}, },
user2_req.context.tenant: { user2_req.context.project_id: {
"max_uploaded_data": 1000 "max_uploaded_data": 1000
} }
} }
@ -602,7 +602,7 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
# disable global limit and try upload data from user1 again # disable global limit and try upload data from user1 again
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_uploaded_data:images": 1500, "max_uploaded_data:images": 1500,
"max_uploaded_data:sample_artifact": 300, "max_uploaded_data:sample_artifact": 300,
"max_uploaded_data:murano_packages": 1000, "max_uploaded_data:murano_packages": 1000,
@ -623,7 +623,7 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
# disable type limit and try upload data from user1 again # disable type limit and try upload data from user1 again
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_uploaded_data:images": -1, "max_uploaded_data:images": -1,
"max_uploaded_data:sample_artifact": 300, "max_uploaded_data:sample_artifact": 300,
"max_uploaded_data:murano_packages": 1000, "max_uploaded_data:murano_packages": 1000,
@ -641,15 +641,15 @@ class TestDynamicQuotas(base.BaseTestArtifactAPI):
admin_req = self.get_fake_request(self.users['admin']) admin_req = self.get_fake_request(self.users['admin'])
values = { values = {
user1_req.context.tenant: { user1_req.context.project_id: {
"max_uploaded_data:sample_artifact": 20, "max_uploaded_data:sample_artifact": 20,
"max_uploaded_data": 5 "max_uploaded_data": 5
}, },
user2_req.context.tenant: { user2_req.context.project_id: {
"max_uploaded_data:sample_artifact": 7, "max_uploaded_data:sample_artifact": 7,
"max_uploaded_data": -1 "max_uploaded_data": -1
}, },
admin_req.context.tenant: { admin_req.context.project_id: {
"max_uploaded_data:sample_artifact": -1, "max_uploaded_data:sample_artifact": -1,
"max_uploaded_data": -1 "max_uploaded_data": -1
} }