From 9fe5a17730fb0c8a96d77a7528b05b77944dcb1c Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 29 Oct 2018 17:36:54 -0400 Subject: [PATCH] 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 --- nova/scheduler/host_manager.py | 5 +++- .../tests/unit/scheduler/test_host_manager.py | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 3a2ad22e3ee9..6fce36d7486b 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -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 diff --git a/nova/tests/unit/scheduler/test_host_manager.py b/nova/tests/unit/scheduler/test_host_manager.py index 950c563fef9e..c6d333bd40ec 100644 --- a/nova/tests/unit/scheduler/test_host_manager.py +++ b/nova/tests/unit/scheduler/test_host_manager.py @@ -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."""