nova-status - don't count deleted compute_nodes

When counting rows in the compute_nodes table to compare against
resource records, those which have been marked as deleted should
not be counted, otherwise the result is artificially high.

Change-Id: Ia3fbb9c46c15826fc363286ce48984f59cbe1e62
Closes-Bug: #1757207
(cherry picked from commit 3e902313e9)
This commit is contained in:
imacdonn 2018-09-22 00:55:36 +00:00 committed by Vlad Gusev
parent 8157b16a65
commit 72d2e82e12
2 changed files with 18 additions and 1 deletions

View File

@ -120,7 +120,8 @@ class UpgradeCommands(object):
# released.
meta = MetaData(bind=db_session.get_engine(context=context))
compute_nodes = Table('compute_nodes', meta, autoload=True)
return select([sqlfunc.count()]).select_from(compute_nodes).scalar()
return select([sqlfunc.count()]).select_from(compute_nodes).where(
compute_nodes.c.deleted == 0).scalar()
def _check_cellsv2(self):
"""Checks to see if cells v2 has been setup.

View File

@ -648,6 +648,22 @@ class TestUpgradeCheckResourceProviders(test.NoDBTestCase):
cpu_info='{"arch": "x86_64"}')
cn.create()
# create a deleted compute node record (shouldn't count)
cn2 = objects.ComputeNode(
context=ctxt,
deleted=1,
host='fakehost',
vcpus=4,
memory_mb=8 * 1024,
local_gb=40,
vcpus_used=2,
memory_mb_used=2 * 1024,
local_gb_used=10,
hypervisor_type='fake',
hypervisor_version=1,
cpu_info='{"arch": "x86_64"}')
cn2.create()
# create a single resource provider with some VCPU inventory
self._create_resource_provider(FAKE_VCPU_INVENTORY)
# create an externally shared IP allocation pool resource provider