Identify stacks using tenant UUIDs

Tenant names may come and go, but UUIDs are universally unique. Therefore,
ownership of the stack should be keyed on the tenant_id, not the tenant
name.

Change-Id: I7ec410aeaeceb6319299935b5f34d7c4e9c63d67
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2012-10-19 16:15:13 +02:00
parent debeccde8f
commit 6ea813be33
7 changed files with 16 additions and 12 deletions

View File

@ -142,7 +142,7 @@ class InstantiationData(object):
def tenant_local(handler):
@wraps(handler)
def handle_stack_method(controller, req, tenant_id, **kwargs):
req.context.tenant = tenant_id
req.context.tenant_id = tenant_id
return handler(controller, req, **kwargs)
return handle_stack_method
@ -152,7 +152,7 @@ def identified_stack(handler):
@tenant_local
@wraps(handler)
def handle_stack_method(controller, req, stack_name, stack_id, **kwargs):
stack_identity = identifier.HeatIdentifier(req.context.tenant,
stack_identity = identifier.HeatIdentifier(req.context.tenant_id,
stack_name,
stack_id)
return handler(controller, req, dict(stack_identity), **kwargs)

View File

@ -80,7 +80,7 @@ def resource_get_by_physical_resource_id(context, physical_resource_id):
.filter_by(nova_instance=physical_resource_id)
.first())
if (result is not None and context is not None and
result.stack.tenant != context.tenant):
result.stack.tenant != context.tenant_id):
return None
return result
@ -120,7 +120,7 @@ def stack_get_by_name(context, stack_name, owner_id=None):
result = model_query(context, models.Stack).\
filter_by(name=stack_name).first()
if (result is not None and context is not None and
result.tenant != context.tenant):
result.tenant != context.tenant_id):
return None
return result
@ -129,7 +129,7 @@ def stack_get(context, stack_id):
result = model_query(context, models.Stack).get(stack_id)
if (result is not None and context is not None and
result.tenant != context.tenant):
result.tenant != context.tenant_id):
return None
return result
@ -144,7 +144,7 @@ def stack_get_all(context):
def stack_get_by_tenant(context):
results = model_query(context, models.Stack).\
filter_by(owner_id=None).\
filter_by(tenant=context.tenant).all()
filter_by(tenant=context.tenant_id).all()
return results
@ -235,7 +235,7 @@ def event_get_all(context):
def event_get_all_by_tenant(context):
stacks = model_query(context, models.Stack).\
filter_by(tenant=context.tenant).all()
filter_by(tenant=context.tenant_id).all()
results = []
for stack in stacks:
results.extend(model_query(context, models.Event).

View File

@ -78,7 +78,7 @@ class EngineManager(manager.Manager):
def _get_stack(self, context, stack_identity):
identity = identifier.HeatIdentifier(**stack_identity)
if identity.tenant != context.tenant:
if identity.tenant != context.tenant_id:
raise AttributeError('Invalid tenant')
s = db_api.stack_get(context, identity.stack_id)

View File

@ -309,7 +309,7 @@ class Stack(object):
'owner_id': owner and owner.id,
'user_creds_id': new_creds.id,
'username': self.context.username,
'tenant': self.context.tenant,
'tenant': self.context.tenant_id,
'status': self.state,
'status_reason': self.state_description,
'timeout': self.timeout_mins,
@ -326,7 +326,7 @@ class Stack(object):
'''
Return an identifier for this stack.
'''
return identifier.HeatIdentifier(self.context.tenant,
return identifier.HeatIdentifier(self.context.tenant_id,
self.name, self.id)
def __iter__(self):

View File

@ -49,6 +49,8 @@ class StackControllerTest(unittest.TestCase):
ctx = context.get_admin_context()
self.m.StubOutWithMock(ctx, 'username')
ctx.username = user
self.m.StubOutWithMock(ctx, 'tenant_id')
ctx.tenant_id = 't'
self.m.StubOutWithMock(auth, 'authenticate')
return ctx

View File

@ -161,6 +161,8 @@ class StackControllerTest(unittest.TestCase):
ctx = context.get_admin_context()
self.m.StubOutWithMock(ctx, 'username')
ctx.username = user
self.m.StubOutWithMock(ctx, 'tenant_id')
ctx.tenant_id = self.tenant
self.m.StubOutWithMock(auth, 'authenticate')
return ctx

View File

@ -45,9 +45,9 @@ def create_context(mocks, user='stacks_test_user',
tenant='test_admin', ctx=None):
ctx = ctx or context.get_admin_context()
mocks.StubOutWithMock(ctx, 'username')
mocks.StubOutWithMock(ctx, 'tenant')
mocks.StubOutWithMock(ctx, 'tenant_id')
ctx.username = user
ctx.tenant = tenant
ctx.tenant_id = tenant
return ctx