Fix nova-status "_check_resource_providers" check

The way in which this check counted compute nodes was
broken because of an incorrect for/else condition. If
the check is run with a nova.conf like we have in
devstack, where the API database is configured but
the [database]/connection is pointing at cell0, where
there are no compute nodes, the check passes saying
there are no compute nodes even if the are compute
nodes found in the cell databases (in the for loop).
This is because the else executes because the for loop
doesn't break, and then _count_compute_nodes returns 0
for cell0 and overwrites the num_computes variable.

This fixes the issue by checking if we have cell mappings
before running the loop, else we hit the else block as
was originally intended.

Conflicts:
      nova/cmd/status.py

NOTE(mriedem): The conflict is due to not having change
I35206e665f2c81531a2269dd66f8c5c0df834245 in Ocata.

Change-Id: I1a706d028a9ca894348a19b7b3df1ea673e4ec90
Partial-Bug: #1790721
(cherry picked from commit dcd421ae9e)
(cherry picked from commit f588a0b6c3)
(cherry picked from commit 6a806de71b)
(cherry picked from commit 3f56222611)
This commit is contained in:
Matt Riedemann 2018-09-04 20:57:33 -04:00
parent 7c684d47ad
commit ff8cb33283
2 changed files with 15 additions and 3 deletions

View File

@ -287,9 +287,10 @@ class UpgradeCommands(object):
cell_mappings = self._get_non_cell0_mappings()
ctxt = nova_context.get_admin_context()
num_computes = 0
for cell_mapping in cell_mappings:
with nova_context.target_cell(ctxt, cell_mapping):
num_computes += self._count_compute_nodes(ctxt)
if cell_mappings:
for cell_mapping in cell_mappings:
with nova_context.target_cell(ctxt, cell_mapping):
num_computes += self._count_compute_nodes(ctxt)
else:
# There are no cell mappings, cells v2 was maybe not deployed in
# Newton, but placement might have been, so let's check the single

View File

@ -632,6 +632,17 @@ class TestUpgradeCheckResourceProviders(test.NoDBTestCase):
# create an externally shared IP allocation pool resource provider
self._create_resource_provider(FAKE_IP_POOL_INVENTORY)
# Stub out _count_compute_nodes to make sure we never call it without
# a cell-targeted context.
original_count_compute_nodes = (
status.UpgradeCommands._count_compute_nodes)
def stub_count_compute_nodes(_self, context=None):
self.assertIsNotNone(context.db_connection)
return original_count_compute_nodes(_self, context=context)
self.stub_out('nova.cmd.status.UpgradeCommands._count_compute_nodes',
stub_count_compute_nodes)
result = self.cmd._check_resource_providers()
self.assertEqual(status.UpgradeCheckCode.SUCCESS, result.code)
self.assertIsNone(result.details)