Fix compatibility with oslo.context >= 4.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
This commit is contained in:
parent
b1fe9752b0
commit
968969b99c
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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'),
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user