Fix ProviderUsageBaseTestCase._run_periodics for multi-cell

The _run_periodics() method is using a non-targeted context
when running the update_available_resource method on all
computes created in the test. For tests that use multiple
cells where the compute services/nodes are created in multiple
cells, the periodic running on the non-cell1 services would
not find the ComputeNode because the context is not targeted.
By default, the CellDatabase fixture is targeted at cell1 in
the base TestCase._setup_cells() method, so when querying the
database without a targeted context, it will look in cell1
which could be wrong if you're trying to update resources in
cell2.

This fixes the issue by simply getting the CellMapping per host
and targeting the context before calling update_available_resource.

Change-Id: Ieeac3bdb82a23179ff6c652b2e9e05a3f6bc9032
This commit is contained in:
Matt Riedemann 2019-03-05 19:42:07 -05:00
parent fc3890667e
commit 4df3f17853
1 changed files with 7 additions and 4 deletions

View File

@ -768,10 +768,13 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
"""
ctx = context.get_admin_context()
for compute in self.computes.values():
LOG.info('Running periodic for compute (%s)',
compute.manager.host)
compute.manager.update_available_resource(ctx)
for host, compute in self.computes.items():
LOG.info('Running periodic for compute (%s)', host)
# Make sure the context is targeted to the proper cell database
# for multi-cell tests.
with context.target_cell(
ctx, self.host_mappings[host].cell_mapping) as cctxt:
compute.manager.update_available_resource(cctxt)
LOG.info('Finished with periodics')
def _move_and_check_allocations(self, server, request, old_flavor,