Change HostManager to allow scheduling to other cells

As part of the cross-cell resize work, we need to be able
to tell the scheduler that it's OK to select destinations
from cells in which the instance does not currently live.
This happens via the "allow_cross_cell_move" flag in the
RequestSpec.requested_destination field, which is not set
at this time (this is just plumbing which will be used later)
and defaults to False for backward compatibility.

Part of blueprint cross-cell-resize

Change-Id: Ib29a17f7fcc3280871d5c9ba31e1374eff98cf82
This commit is contained in:
Matt Riedemann 2018-10-29 17:36:54 -04:00
parent 656f53edc1
commit 9fe5a17730
2 changed files with 27 additions and 1 deletions

View File

@ -755,9 +755,12 @@ class HostManager(object):
if not self.cells:
LOG.warning("No cells were found")
# Restrict to a single cell if and only if the request spec has a
# requested cell and allow_cross_cell_move=False.
if (spec_obj and 'requested_destination' in spec_obj and
spec_obj.requested_destination and
'cell' in spec_obj.requested_destination):
'cell' in spec_obj.requested_destination and
not spec_obj.requested_destination.allow_cross_cell_move):
only_cell = spec_obj.requested_destination.cell
else:
only_cell = None

View File

@ -1319,6 +1319,29 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
num_hosts2 = len(list(host_states2))
self.assertEqual(0, num_hosts2)
@mock.patch('nova.scheduler.host_manager.HostManager.'
'_get_computes_for_cells',
return_value=(mock.sentinel.compute_nodes,
mock.sentinel.services))
@mock.patch('nova.scheduler.host_manager.HostManager._get_host_states')
def test_get_host_states_by_uuids_allow_cross_cell_move(
self, mock_get_host_states, mock_get_computes):
"""Tests that get_host_states_by_uuids will not restrict to a given
cell if allow_cross_cell_move=True in the request spec.
"""
ctxt = nova_context.get_admin_context()
compute_uuids = [uuids.compute_node_uuid]
spec_obj = objects.RequestSpec(
requested_destination=objects.Destination(
cell=objects.CellMapping(uuid=uuids.cell1),
allow_cross_cell_move=True))
self.host_manager.get_host_states_by_uuids(
ctxt, compute_uuids, spec_obj)
mock_get_computes.assert_called_once_with(
ctxt, self.host_manager.enabled_cells, compute_uuids=compute_uuids)
mock_get_host_states.assert_called_once_with(
ctxt, mock.sentinel.compute_nodes, mock.sentinel.services)
class HostStateTestCase(test.NoDBTestCase):
"""Test case for HostState class."""