Skip to content

Commit 9fe5a17

Browse files
committed
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
1 parent 656f53e commit 9fe5a17

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

nova/scheduler/host_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,12 @@ def get_host_states_by_uuids(self, context, compute_uuids, spec_obj):
755755

756756
if not self.cells:
757757
LOG.warning("No cells were found")
758+
# Restrict to a single cell if and only if the request spec has a
759+
# requested cell and allow_cross_cell_move=False.
758760
if (spec_obj and 'requested_destination' in spec_obj and
759761
spec_obj.requested_destination and
760-
'cell' in spec_obj.requested_destination):
762+
'cell' in spec_obj.requested_destination and
763+
not spec_obj.requested_destination.allow_cross_cell_move):
761764
only_cell = spec_obj.requested_destination.cell
762765
else:
763766
only_cell = None

nova/tests/unit/scheduler/test_host_manager.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,29 @@ def test_get_host_states_by_uuids(self, mock_get_by_host, mock_get_all,
13191319
num_hosts2 = len(list(host_states2))
13201320
self.assertEqual(0, num_hosts2)
13211321

1322+
@mock.patch('nova.scheduler.host_manager.HostManager.'
1323+
'_get_computes_for_cells',
1324+
return_value=(mock.sentinel.compute_nodes,
1325+
mock.sentinel.services))
1326+
@mock.patch('nova.scheduler.host_manager.HostManager._get_host_states')
1327+
def test_get_host_states_by_uuids_allow_cross_cell_move(
1328+
self, mock_get_host_states, mock_get_computes):
1329+
"""Tests that get_host_states_by_uuids will not restrict to a given
1330+
cell if allow_cross_cell_move=True in the request spec.
1331+
"""
1332+
ctxt = nova_context.get_admin_context()
1333+
compute_uuids = [uuids.compute_node_uuid]
1334+
spec_obj = objects.RequestSpec(
1335+
requested_destination=objects.Destination(
1336+
cell=objects.CellMapping(uuid=uuids.cell1),
1337+
allow_cross_cell_move=True))
1338+
self.host_manager.get_host_states_by_uuids(
1339+
ctxt, compute_uuids, spec_obj)
1340+
mock_get_computes.assert_called_once_with(
1341+
ctxt, self.host_manager.enabled_cells, compute_uuids=compute_uuids)
1342+
mock_get_host_states.assert_called_once_with(
1343+
ctxt, mock.sentinel.compute_nodes, mock.sentinel.services)
1344+
13221345

13231346
class HostStateTestCase(test.NoDBTestCase):
13241347
"""Test case for HostState class."""

0 commit comments

Comments
 (0)