Skip to content

Commit 656f53e

Browse files
committed
Add Destination.allow_cross_cell_move field
This adds a new boolean field, allow_cross_cell_move, to the Destination object used within a RequestSpec. This will be used during a cross-cell resize when asking the scheduler for a target host whether or not that host should be restricted to the current cell or if the host can come from another cell. Furthermore, it will be used in a scheduler weigher which will prefer candidate target hosts in the current cell rather than a different cell. Part of blueprint cross-cell-resize Change-Id: I6e226321348f5d64d16b0bae26ad31c52debf0bc
1 parent a958dc5 commit 656f53e

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

nova/objects/request_spec.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ class Destination(base.NovaObject):
878878
# Version 1.0: Initial version
879879
# Version 1.1: Add cell field
880880
# Version 1.2: Add aggregates field
881-
VERSION = '1.2'
881+
# Version 1.3: Add allow_cross_cell_move field.
882+
VERSION = '1.3'
882883

883884
fields = {
884885
'host': fields.StringField(),
@@ -892,11 +893,17 @@ class Destination(base.NovaObject):
892893
# are passed to placement. See require_aggregates() below.
893894
'aggregates': fields.ListOfStringsField(nullable=True,
894895
default=None),
896+
# NOTE(mriedem): allow_cross_cell_move defaults to False so that the
897+
# scheduler by default selects hosts from the cell specified in the
898+
# cell field.
899+
'allow_cross_cell_move': fields.BooleanField(default=False),
895900
}
896901

897902
def obj_make_compatible(self, primitive, target_version):
898903
super(Destination, self).obj_make_compatible(primitive, target_version)
899904
target_version = versionutils.convert_version_to_tuple(target_version)
905+
if target_version < (1, 3) and 'allow_cross_cell_move' in primitive:
906+
del primitive['allow_cross_cell_move']
900907
if target_version < (1, 2):
901908
if 'aggregates' in primitive:
902909
del primitive['aggregates']

nova/tests/unit/objects/test_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def obj_name(cls):
10491049
'CpuDiagnostics': '1.0-d256f2e442d1b837735fd17dfe8e3d47',
10501050
'DNSDomain': '1.0-7b0b2dab778454b6a7b6c66afe163a1a',
10511051
'DNSDomainList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
1052-
'Destination': '1.2-74854e8cfe7fe616294d93a5d189d885',
1052+
'Destination': '1.3-07240d223a95c8b9399f7af21091ccfd',
10531053
'DeviceBus': '1.0-77509ea1ea0dd750d5864b9bd87d3f9d',
10541054
'DeviceMetadata': '1.0-04eb8fd218a49cbc3b1e54b774d179f7',
10551055
'Diagnostics': '1.0-38ad3e9b1a59306253fc03f97936db95',

nova/tests/unit/objects/test_request_spec.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def test_from_primitives_with_requested_destination(self):
325325
def test_from_components(self):
326326
ctxt = context.RequestContext('fake-user', 'fake-project')
327327
destination = objects.Destination(host='foo')
328+
self.assertFalse(destination.allow_cross_cell_move)
328329
instance = fake_instance.fake_instance_obj(ctxt)
329330
image = {'id': uuids.image_id, 'properties': {'mappings': []},
330331
'status': 'fake-status', 'location': 'far-away'}
@@ -344,6 +345,7 @@ def test_from_components(self):
344345
# just making sure that the context is set by the method
345346
self.assertEqual(ctxt, spec._context)
346347
self.assertEqual(destination, spec.requested_destination)
348+
self.assertFalse(spec.requested_destination.allow_cross_cell_move)
347349

348350
@mock.patch('nova.objects.RequestSpec._populate_group_info')
349351
def test_from_components_with_instance_group(self, mock_pgi):
@@ -896,10 +898,18 @@ def test_destination_require_aggregates(self):
896898
destination.require_aggregates(['baz'])
897899
self.assertEqual(['foo,bar', 'baz'], destination.aggregates)
898900

899-
def test_destination_1dotoh(self):
900-
destination = objects.Destination(aggregates=['foo'])
901-
primitive = destination.obj_to_primitive(target_version='1.0')
902-
self.assertNotIn('aggregates', primitive['nova_object.data'])
901+
def test_destination_obj_make_compatible(self):
902+
destination = objects.Destination(
903+
aggregates=['foo'], host='fake-host', allow_cross_cell_move=False)
904+
primitive = destination.obj_to_primitive(
905+
target_version='1.2')['nova_object.data']
906+
self.assertIn('aggregates', primitive)
907+
self.assertNotIn('allow_cross_cell_move', primitive)
908+
909+
primitive = destination.obj_to_primitive(
910+
target_version='1.0')['nova_object.data']
911+
self.assertNotIn('aggregates', primitive)
912+
self.assertEqual('fake-host', primitive['host'])
903913

904914
def test_create_raises_on_unchanged_object(self):
905915
ctxt = context.RequestContext(uuids.user_id, uuids.project_id)

0 commit comments

Comments
 (0)