Merge "placement-status: check only consumers in allocation table"

This commit is contained in:
Zuul 2021-07-30 19:48:50 +00:00 committed by Gerrit Code Review
commit 36aba336b1
2 changed files with 19 additions and 7 deletions

View File

@ -59,13 +59,16 @@ class Checks(upgradecheck.UpgradeCommands):
@db_api.placement_context_manager.reader @db_api.placement_context_manager.reader
def _count_missing_consumers(self, ctxt): def _count_missing_consumers(self, ctxt):
# Count the total number of consumers. allocation = models.Allocation.__table__
num_consumers = ctxt.session.query(models.Consumer).count() consumer = models.Consumer.__table__
# Count the total number of unique consumers in the allocations table. return ctxt.session.execute(
num_alloc_consumers = ctxt.session.query( sa.select([sa.func.count(
models.Allocation.consumer_id).group_by( sa.distinct(allocation.c.consumer_id))])
models.Allocation.consumer_id).count() .select_from(
return num_alloc_consumers - num_consumers allocation.outerjoin(
consumer,
allocation.c.consumer_id == consumer.c.uuid))
.where(consumer.c.id.is_(None))).fetchone()[0]
def _check_incomplete_consumers(self): def _check_incomplete_consumers(self):
"""Allocations created with microversion<1.8 prior to Rocky will not """Allocations created with microversion<1.8 prior to Rocky will not

View File

@ -99,12 +99,21 @@ class CreateIncompleteAllocationsMixin(object):
"""Mixin for test setup to create some allocations with missing consumers """Mixin for test setup to create some allocations with missing consumers
""" """
@db_api.placement_context_manager.writer
def _create_leftover_consumer(self, ctx):
ins_stmt = CONSUMER_TBL.insert().values(
uuid=uuids.unknown_consumer,
project_id=999,
user_id=999)
ctx.session.execute(ins_stmt)
@db_api.placement_context_manager.writer @db_api.placement_context_manager.writer
def _create_incomplete_allocations(self, ctx, num_of_consumer_allocs=1): def _create_incomplete_allocations(self, ctx, num_of_consumer_allocs=1):
# Create some allocations with consumers that don't exist in the # Create some allocations with consumers that don't exist in the
# consumers table to represent old allocations that we expect to be # consumers table to represent old allocations that we expect to be
# "cleaned up" with consumers table records that point to the sentinel # "cleaned up" with consumers table records that point to the sentinel
# project/user records. # project/user records.
self._create_leftover_consumer(ctx)
c1_missing_uuid = uuids.c1_missing c1_missing_uuid = uuids.c1_missing
c2_missing_uuid = uuids.c2_missing c2_missing_uuid = uuids.c2_missing
c3_missing_uuid = uuids.c3_missing c3_missing_uuid = uuids.c3_missing