summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kajinami <tkajinam@redhat.com>2022-03-01 16:45:03 +0900
committerTakashi Kajinami <tkajinam@redhat.com>2022-03-01 18:40:34 +0900
commit968969b99cf9c1cfcde4f5c5345f7bcbd4e8db08 (patch)
treecd9b380095de6050db0a4df21da1bbf962f09fee
parentb1fe9752b0e03a6036e7fde8312a8e0e80e297f9 (diff)
downloadheat-968969b99cf9c1cfcde4f5c5345f7bcbd4e8db08.tar.gz
Fix compatibility with oslo.context >= 4.0.018.0.0.0rc118.0.0
The tenant argument of RequestContext is longer available since oslo.context 4.0.0. This change removes usage of the deprecated argument in unit tests to prepare for version bump. Change-Id: I0493b5fbe09d183e57a207c1dda0b2ee7a4e1b34
-rw-r--r--heat/common/auth_password.py8
-rw-r--r--heat/common/context.py4
-rw-r--r--heat/tests/api/openstack_v1/test_util.py4
-rw-r--r--heat/tests/clients/test_swift_client.py2
-rw-r--r--heat/tests/db/test_sqlalchemy_api.py46
-rw-r--r--heat/tests/test_common_context.py4
-rw-r--r--heat/tests/test_signal.py2
-rw-r--r--heat/tests/test_stack.py6
8 files changed, 38 insertions, 38 deletions
diff --git a/heat/common/auth_password.py b/heat/common/auth_password.py
index e977d85a1..8bfe2be83 100644
--- a/heat/common/auth_password.py
+++ b/heat/common/auth_password.py
@@ -40,16 +40,16 @@ class KeystonePasswordAuthProtocol(object):
"""Authenticate incoming request."""
username = env.get('HTTP_X_AUTH_USER')
password = env.get('HTTP_X_AUTH_KEY')
- # Determine tenant id from path.
- tenant = env.get('PATH_INFO').split('/')[1]
+ # Determine project id from path.
+ project_id = env.get('PATH_INFO').split('/')[1]
auth_url = env.get('HTTP_X_AUTH_URL')
user_domain_id = env.get('HTTP_X_USER_DOMAIN_ID')
- if not tenant:
+ if not project_id:
return self._reject_request(env, start_response, auth_url)
try:
ctx = context.RequestContext(username=username,
password=password,
- tenant=tenant,
+ project_id=project_id,
auth_url=auth_url,
user_domain_id=user_domain_id,
is_admin=False)
diff --git a/heat/common/context.py b/heat/common/context.py
index a30b1e26b..c72c8367b 100644
--- a/heat/common/context.py
+++ b/heat/common/context.py
@@ -155,8 +155,8 @@ class RequestContext(context.RequestContext):
return self._clients
def to_dict(self):
- user_idt = u'{user} {tenant}'.format(user=self.user_id or '-',
- tenant=self.project_id or '-')
+ user_idt = u'{user} {project}'.format(user=self.user_id or '-',
+ project=self.project_id or '-')
return {'auth_token': self.auth_token,
'username': self.username,
diff --git a/heat/tests/api/openstack_v1/test_util.py b/heat/tests/api/openstack_v1/test_util.py
index 93930eccc..ec0ae5e8b 100644
--- a/heat/tests/api/openstack_v1/test_util.py
+++ b/heat/tests/api/openstack_v1/test_util.py
@@ -88,7 +88,7 @@ class TestPolicyEnforce(common.HeatTestCase):
def setUp(self):
super(TestPolicyEnforce, self).setUp()
self.req = wsgi.Request({})
- self.req.context = context.RequestContext(tenant='foo',
+ self.req.context = context.RequestContext(project_id='foo',
is_admin=False)
class DummyController(object):
@@ -113,7 +113,7 @@ class TestPolicyEnforce(common.HeatTestCase):
@mock.patch.object(policy.Enforcer, 'enforce')
def test_policy_enforce_tenant_mismatch_is_admin(self, mock_enforce):
- self.req.context = context.RequestContext(tenant='foo',
+ self.req.context = context.RequestContext(project_id='foo',
is_admin=True)
mock_enforce.return_value = True
diff --git a/heat/tests/clients/test_swift_client.py b/heat/tests/clients/test_swift_client.py
index 90272b6df..eb3146d98 100644
--- a/heat/tests/clients/test_swift_client.py
+++ b/heat/tests/clients/test_swift_client.py
@@ -27,7 +27,7 @@ class SwiftClientPluginTestCase(common.HeatTestCase):
super(SwiftClientPluginTestCase, self).setUp()
self.swift_client = mock.Mock()
self.context = utils.dummy_context()
- self.context.tenant = "demo"
+ self.context.project_id = "demo"
c = self.context.clients
self.swift_plugin = c.client_plugin('swift')
self.swift_plugin.client = lambda: self.swift_client
diff --git a/heat/tests/db/test_sqlalchemy_api.py b/heat/tests/db/test_sqlalchemy_api.py
index eef95d53c..07a1c2670 100644
--- a/heat/tests/db/test_sqlalchemy_api.py
+++ b/heat/tests/db/test_sqlalchemy_api.py
@@ -342,11 +342,11 @@ class SqlAlchemyTest(common.HeatTestCase):
st = db_api.stack_get_by_name(self.ctx, name)
self.assertEqual(UUID1, st.id)
- self.ctx.tenant = UUID3
+ self.ctx.project_id = UUID3
st = db_api.stack_get_by_name(self.ctx, name)
self.assertIsNone(st)
- self.ctx.tenant = UUID2
+ self.ctx.project_id = UUID2
st = db_api.stack_get_by_name(self.ctx, name)
self.assertEqual(UUID1, st.id)
@@ -399,12 +399,12 @@ class SqlAlchemyTest(common.HeatTestCase):
self.assertEqual(UUID2, result.id)
- self.ctx.tenant = str(uuid.uuid4())
+ self.ctx.project_id = str(uuid.uuid4())
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
None)
self.assertIsNone(result)
- self.ctx.tenant = UUID3
+ self.ctx.project_id = UUID3
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
stack1.id)
@@ -1020,7 +1020,7 @@ class SqlAlchemyTest(common.HeatTestCase):
self.ctx.password = None
self.ctx.trust_id = 'atrust123'
self.ctx.trustor_user_id = 'atrustor123'
- self.ctx.tenant = 'atenant123'
+ self.ctx.project_id = 'atenant123'
self.ctx.project_name = 'atenant'
self.ctx.auth_url = 'anauthurl'
self.ctx.region_name = 'aregion'
@@ -1088,7 +1088,7 @@ class SqlAlchemyTest(common.HeatTestCase):
self.assertEqual(tenant_id, config.tenant)
self.assertEqual('Heat::Shell', config.group)
self.assertEqual(conf, config.config['config'])
- self.ctx.tenant = None
+ self.ctx.project_id = None
self.assertRaises(
exception.NotFound,
db_api.software_config_get,
@@ -1213,7 +1213,7 @@ class SqlAlchemyTest(common.HeatTestCase):
values['stack_user_project_id'], deployment.stack_user_project_id)
# assert not found with invalid context tenant
- self.ctx.tenant = str(uuid.uuid4())
+ self.ctx.project_id = str(uuid.uuid4())
self.assertRaises(
exception.NotFound,
db_api.software_deployment_get,
@@ -1221,7 +1221,7 @@ class SqlAlchemyTest(common.HeatTestCase):
deployment_id)
# assert found with stack_user_project_id context tenant
- self.ctx.tenant = deployment.stack_user_project_id
+ self.ctx.project_id = deployment.stack_user_project_id
deployment = db_api.software_deployment_get(self.ctx, deployment_id)
self.assertIsNotNone(deployment)
self.assertEqual(values['tenant'], deployment.tenant)
@@ -1370,7 +1370,7 @@ class SqlAlchemyTest(common.HeatTestCase):
values = {'tenant': self.ctx.tenant_id, 'status': 'IN_PROGRESS',
'stack_id': stack.id}
snapshot = db_api.snapshot_create(self.ctx, values)
- self.ctx.tenant = str(uuid.uuid4())
+ self.ctx.project_id = str(uuid.uuid4())
self.assertRaises(
exception.NotFound,
db_api.snapshot_get,
@@ -1465,7 +1465,7 @@ def create_stack(ctx, template, user_creds, **kwargs):
'name': short_id.generate_id(),
'raw_template_id': template.id,
'username': ctx.username,
- 'tenant': ctx.tenant_id,
+ 'tenant': ctx.project_id,
'action': 'create',
'status': 'complete',
'status_reason': 'create_complete',
@@ -1480,7 +1480,7 @@ def create_stack(ctx, template, user_creds, **kwargs):
}
values.update(kwargs)
if 'tenant' in kwargs:
- ctx.tenant_id = kwargs['tenant']
+ ctx.project_id = kwargs['tenant']
return db_api.stack_create(ctx, values)
@@ -1902,14 +1902,14 @@ class DBAPIStackTest(common.HeatTestCase):
def test_stack_get_returns_none_if_tenant_id_does_not_match(self):
stack = create_stack(self.ctx, self.template, self.user_creds)
- self.ctx.tenant = 'abc'
+ self.ctx.project_id = 'abc'
stack = db_api.stack_get(self.ctx, UUID1, show_deleted=False)
self.assertIsNone(stack)
def test_stack_get_tenant_is_stack_user_project_id(self):
stack = create_stack(self.ctx, self.template, self.user_creds,
stack_user_project_id='astackuserproject')
- self.ctx.tenant = 'astackuserproject'
+ self.ctx.project_id = 'astackuserproject'
ret_stack = db_api.stack_get(self.ctx, stack.id, show_deleted=False)
self.assertIsNotNone(ret_stack)
self.assertEqual(stack.id, ret_stack.id)
@@ -1936,7 +1936,7 @@ class DBAPIStackTest(common.HeatTestCase):
self.assertIsNone(db_api.stack_get_by_name(self.ctx, 'abc'))
- self.ctx.tenant = 'abc'
+ self.ctx.project_id = 'abc'
self.assertIsNone(db_api.stack_get_by_name(self.ctx, 'abc'))
def test_stack_get_all(self):
@@ -2014,15 +2014,15 @@ class DBAPIStackTest(common.HeatTestCase):
[create_stack(self.ctx, self.template, self.user_creds,
**val) for val in values]
- self.ctx.tenant = UUID1
+ self.ctx.project_id = UUID1
stacks = db_api.stack_get_all(self.ctx)
self.assertEqual(2, len(stacks))
- self.ctx.tenant = UUID2
+ self.ctx.project_id = UUID2
stacks = db_api.stack_get_all(self.ctx)
self.assertEqual(3, len(stacks))
- self.ctx.tenant = UUID3
+ self.ctx.project_id = UUID3
self.assertEqual([], db_api.stack_get_all(self.ctx))
def test_stack_get_all_with_admin_context(self):
@@ -2054,10 +2054,10 @@ class DBAPIStackTest(common.HeatTestCase):
[create_stack(self.ctx, self.template, self.user_creds,
**val) for val in values]
- self.ctx.tenant = UUID1
+ self.ctx.project_id = UUID1
self.assertEqual(2, db_api.stack_count_all(self.ctx))
- self.ctx.tenant = UUID2
+ self.ctx.project_id = UUID2
self.assertEqual(3, db_api.stack_count_all(self.ctx))
def test_stack_count_all_with_admin_context(self):
@@ -2948,7 +2948,7 @@ class DBAPIEventTest(common.HeatTestCase):
]
[create_event(self.ctx, **val) for val in values]
- self.ctx.tenant = 'tenant1'
+ self.ctx.project_id = 'tenant1'
events = db_api.event_get_all_by_tenant(self.ctx)
self.assertEqual(2, len(events))
marker = events[0].uuid
@@ -2972,7 +2972,7 @@ class DBAPIEventTest(common.HeatTestCase):
sort_keys=sort_keys)
self.assertEqual(2, len(events))
- self.ctx.tenant = 'tenant2'
+ self.ctx.project_id = 'tenant2'
events = db_api.event_get_all_by_tenant(self.ctx)
self.assertEqual(1, len(events))
@@ -2986,11 +2986,11 @@ class DBAPIEventTest(common.HeatTestCase):
]
[create_event(self.ctx, **val) for val in values]
- self.ctx.tenant = 'tenant1'
+ self.ctx.project_id = 'tenant1'
events = db_api.event_get_all_by_stack(self.ctx, self.stack1.id)
self.assertEqual(2, len(events))
- self.ctx.tenant = 'tenant2'
+ self.ctx.project_id = 'tenant2'
events = db_api.event_get_all_by_stack(self.ctx, self.stack2.id)
self.assertEqual(1, len(events))
diff --git a/heat/tests/test_common_context.py b/heat/tests/test_common_context.py
index a9e392605..95a08ec96 100644
--- a/heat/tests/test_common_context.py
+++ b/heat/tests/test_common_context.py
@@ -63,7 +63,7 @@ class TestRequestContext(common.HeatTestCase):
password=self.ctx.get('password'),
aws_creds=self.ctx.get('aws_creds'),
project_name=self.ctx.get('tenant'),
- tenant=self.ctx.get('tenant_id'),
+ project_id=self.ctx.get('tenant_id'),
user=self.ctx.get('user_id'),
auth_url=self.ctx.get('auth_url'),
roles=self.ctx.get('roles'),
@@ -112,7 +112,7 @@ class TestRequestContext(common.HeatTestCase):
password=ctx_origin.get('password'),
aws_creds=ctx_origin.get('aws_creds'),
project_name=ctx_origin.get('tenant'),
- tenant=ctx_origin.get('tenant_id'),
+ project_id=ctx_origin.get('tenant_id'),
user=ctx_origin.get('user_id'),
auth_url=ctx_origin.get('auth_url'),
roles=ctx_origin.get('roles'),
diff --git a/heat/tests/test_signal.py b/heat/tests/test_signal.py
index e47705ea1..bb0b8313b 100644
--- a/heat/tests/test_signal.py
+++ b/heat/tests/test_signal.py
@@ -96,7 +96,7 @@ class SignalTest(common.HeatTestCase):
tpl = template.Template(template_format.parse(template_string))
ctx = utils.dummy_context()
- ctx.tenant = 'test_tenant'
+ ctx.project_id = 'test_tenant'
stack = stk.Stack(ctx, stack_name, tpl, disable_rollback=True)
with utils.UUIDStub(stack_id):
stack.store()
diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py
index 790d0f4ca..35374190c 100644
--- a/heat/tests/test_stack.py
+++ b/heat/tests/test_stack.py
@@ -70,7 +70,7 @@ class StackTest(common.HeatTestCase):
self.assertEqual('bar', self.stack.tenant_id)
def test_stack_reads_tenant_from_context_if_empty(self):
- self.ctx.tenant = 'foo'
+ self.ctx.project_id = 'foo'
self.stack = stack.Stack(self.ctx, 'test_stack', self.tmpl,
tenant_id=None)
self.assertEqual('foo', self.stack.tenant_id)
@@ -580,11 +580,11 @@ class StackTest(common.HeatTestCase):
self.assertEqual(identifier.arn(), newstack.parameters['AWS::StackId'])
def test_load_reads_tenant_id(self):
- self.ctx.tenant = 'foobar'
+ self.ctx.project_id = 'foobar'
self.stack = stack.Stack(self.ctx, 'stack_name', self.tmpl)
self.stack.store()
stack_id = self.stack.id
- self.ctx.tenant = None
+ self.ctx.project_id = None
self.stack = stack.Stack.load(self.ctx, stack_id=stack_id)
self.assertEqual('foobar', self.stack.tenant_id)