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."""