Merge "Include project_id and user_id in AllocationList.get_all_by_consumer_id"

This commit is contained in:
Zuul 2017-11-21 02:29:37 +00:00 committed by Gerrit Code Review
commit 190deb3fd9
2 changed files with 23 additions and 2 deletions

View File

@ -1720,6 +1720,9 @@ def _get_allocations_by_provider_id(ctx, rp_id):
def _get_allocations_by_consumer_uuid(ctx, consumer_uuid):
allocs = sa.alias(_ALLOC_TBL, name="a")
rp = sa.alias(_RP_TBL, name="rp")
consumer = sa.alias(_CONSUMER_TBL, name="c")
project = sa.alias(_PROJECT_TBL, name="p")
user = sa.alias(_USER_TBL, name="u")
cols = [
allocs.c.resource_provider_id,
rp.c.name.label("resource_provider_name"),
@ -1728,9 +1731,19 @@ def _get_allocations_by_consumer_uuid(ctx, consumer_uuid):
allocs.c.resource_class_id,
allocs.c.consumer_id,
allocs.c.used,
project.c.external_id.label("project_id"),
user.c.external_id.label("user_id"),
]
join = sa.join(allocs, rp, allocs.c.resource_provider_id == rp.c.id)
sel = sa.select(cols).select_from(join)
# Build up the joins of the five tables we need to interact with.
rp_join = sa.join(allocs, rp, allocs.c.resource_provider_id == rp.c.id)
consumer_join = sa.outerjoin(rp_join, consumer,
allocs.c.consumer_id == consumer.c.uuid)
project_join = sa.outerjoin(consumer_join, project,
consumer.c.project_id == project.c.id)
user_join = sa.outerjoin(project_join, user,
consumer.c.user_id == user.c.id)
sel = sa.select(cols).select_from(user_join)
sel = sel.where(allocs.c.consumer_id == consumer_uuid)
return [dict(r) for r in ctx.session.execute(sel)]

View File

@ -1314,6 +1314,14 @@ class TestAllocationListCreateDelete(ResourceProviderBaseCase):
self.assertEqual(1, len(usage_list))
self.assertEqual(200, usage_list[0].usage)
# List allocations and confirm project and user
allocation_list = rp_obj.AllocationList.get_all_by_consumer_id(
self.ctx, other_consumer_uuid)
self.assertEqual(1, len(allocation_list))
allocation = allocation_list[0]
self.assertEqual(self.ctx.project_id, allocation.project_id)
self.assertEqual(uuidsentinel.other_user, allocation.user_id)
def test_create_and_clear(self):
"""Test that a used of 0 in an allocation wipes allocations."""
consumer_uuid = uuidsentinel.consumer