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
def _count_missing_consumers(self, ctxt):
# Count the total number of consumers.
num_consumers = ctxt.session.query(models.Consumer).count()
# Count the total number of unique consumers in the allocations table.
num_alloc_consumers = ctxt.session.query(
models.Allocation.consumer_id).group_by(
models.Allocation.consumer_id).count()
return num_alloc_consumers - num_consumers
allocation = models.Allocation.__table__
consumer = models.Consumer.__table__
return ctxt.session.execute(
sa.select([sa.func.count(
sa.distinct(allocation.c.consumer_id))])
.select_from(
allocation.outerjoin(
consumer,
allocation.c.consumer_id == consumer.c.uuid))
.where(consumer.c.id.is_(None))).fetchone()[0]
def _check_incomplete_consumers(self):
"""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
"""
@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
def _create_incomplete_allocations(self, ctx, num_of_consumer_allocs=1):
# Create some allocations with consumers that don't exist in the
# consumers table to represent old allocations that we expect to be
# "cleaned up" with consumers table records that point to the sentinel
# project/user records.
self._create_leftover_consumer(ctx)
c1_missing_uuid = uuids.c1_missing
c2_missing_uuid = uuids.c2_missing
c3_missing_uuid = uuids.c3_missing