Merge "Pass requested_destination in filter_properties"
This commit is contained in:
@@ -264,6 +264,8 @@ class RequestSpec(base.NovaObject):
|
|||||||
spec._populate_group_info(filter_properties)
|
spec._populate_group_info(filter_properties)
|
||||||
scheduler_hints = filter_properties.get('scheduler_hints', {})
|
scheduler_hints = filter_properties.get('scheduler_hints', {})
|
||||||
spec._from_hints(scheduler_hints)
|
spec._from_hints(scheduler_hints)
|
||||||
|
spec.requested_destination = filter_properties.get(
|
||||||
|
'requested_destination')
|
||||||
|
|
||||||
# NOTE(sbauza): Default the other fields that are not part of the
|
# NOTE(sbauza): Default the other fields that are not part of the
|
||||||
# original contract
|
# original contract
|
||||||
@@ -372,6 +374,9 @@ class RequestSpec(base.NovaObject):
|
|||||||
# we had to hydrate the field by putting a single item into a list.
|
# we had to hydrate the field by putting a single item into a list.
|
||||||
filt_props['scheduler_hints'] = {hint: self.get_scheduler_hint(
|
filt_props['scheduler_hints'] = {hint: self.get_scheduler_hint(
|
||||||
hint) for hint in self.scheduler_hints}
|
hint) for hint in self.scheduler_hints}
|
||||||
|
if self.obj_attr_is_set('requested_destination'
|
||||||
|
) and self.requested_destination:
|
||||||
|
filt_props['requested_destination'] = self.requested_destination
|
||||||
return filt_props
|
return filt_props
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -417,6 +422,8 @@ class RequestSpec(base.NovaObject):
|
|||||||
spec_obj.availability_zone = availability_zone
|
spec_obj.availability_zone = availability_zone
|
||||||
if security_groups is not None:
|
if security_groups is not None:
|
||||||
spec_obj.security_groups = security_groups
|
spec_obj.security_groups = security_groups
|
||||||
|
spec_obj.requested_destination = filter_properties.get(
|
||||||
|
'requested_destination')
|
||||||
|
|
||||||
# NOTE(sbauza): Default the other fields that are not part of the
|
# NOTE(sbauza): Default the other fields that are not part of the
|
||||||
# original contract
|
# original contract
|
||||||
|
@@ -299,13 +299,22 @@ class _TestRequestSpecObject(object):
|
|||||||
# just making sure that the context is set by the method
|
# just making sure that the context is set by the method
|
||||||
self.assertEqual(ctxt, spec._context)
|
self.assertEqual(ctxt, spec._context)
|
||||||
|
|
||||||
|
def test_from_primitives_with_requested_destination(self):
|
||||||
|
destination = objects.Destination(host='foo')
|
||||||
|
spec_dict = {}
|
||||||
|
filt_props = {'requested_destination': destination}
|
||||||
|
ctxt = context.RequestContext('fake', 'fake')
|
||||||
|
spec = objects.RequestSpec.from_primitives(ctxt, spec_dict, filt_props)
|
||||||
|
self.assertEqual(destination, spec.requested_destination)
|
||||||
|
|
||||||
def test_from_components(self):
|
def test_from_components(self):
|
||||||
ctxt = context.RequestContext('fake-user', 'fake-project')
|
ctxt = context.RequestContext('fake-user', 'fake-project')
|
||||||
|
destination = objects.Destination(host='foo')
|
||||||
instance = fake_instance.fake_instance_obj(ctxt)
|
instance = fake_instance.fake_instance_obj(ctxt)
|
||||||
image = {'id': uuids.image_id, 'properties': {'mappings': []},
|
image = {'id': uuids.image_id, 'properties': {'mappings': []},
|
||||||
'status': 'fake-status', 'location': 'far-away'}
|
'status': 'fake-status', 'location': 'far-away'}
|
||||||
flavor = fake_flavor.fake_flavor_obj(ctxt)
|
flavor = fake_flavor.fake_flavor_obj(ctxt)
|
||||||
filter_properties = {}
|
filter_properties = {'requested_destination': destination}
|
||||||
instance_group = None
|
instance_group = None
|
||||||
|
|
||||||
spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
|
spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
|
||||||
@@ -318,6 +327,7 @@ class _TestRequestSpecObject(object):
|
|||||||
'Field: %s is not set' % field)
|
'Field: %s is not set' % field)
|
||||||
# just making sure that the context is set by the method
|
# just making sure that the context is set by the method
|
||||||
self.assertEqual(ctxt, spec._context)
|
self.assertEqual(ctxt, spec._context)
|
||||||
|
self.assertEqual(destination, spec.requested_destination)
|
||||||
|
|
||||||
@mock.patch('nova.objects.RequestSpec._populate_group_info')
|
@mock.patch('nova.objects.RequestSpec._populate_group_info')
|
||||||
def test_from_components_with_instance_group(self, mock_pgi):
|
def test_from_components_with_instance_group(self, mock_pgi):
|
||||||
@@ -436,6 +446,7 @@ class _TestRequestSpecObject(object):
|
|||||||
fake_computes_obj = objects.ComputeNodeList(
|
fake_computes_obj = objects.ComputeNodeList(
|
||||||
objects=[objects.ComputeNode(host='fake1',
|
objects=[objects.ComputeNode(host='fake1',
|
||||||
hypervisor_hostname='node1')])
|
hypervisor_hostname='node1')])
|
||||||
|
fake_dest = objects.Destination(host='fakehost')
|
||||||
spec = objects.RequestSpec(
|
spec = objects.RequestSpec(
|
||||||
ignore_hosts=['ignoredhost'],
|
ignore_hosts=['ignoredhost'],
|
||||||
force_hosts=['fakehost'],
|
force_hosts=['fakehost'],
|
||||||
@@ -449,7 +460,8 @@ class _TestRequestSpecObject(object):
|
|||||||
instance_group=objects.InstanceGroup(hosts=['fake1'],
|
instance_group=objects.InstanceGroup(hosts=['fake1'],
|
||||||
policies=['affinity'],
|
policies=['affinity'],
|
||||||
members=['inst1', 'inst2']),
|
members=['inst1', 'inst2']),
|
||||||
scheduler_hints={'foo': ['bar']})
|
scheduler_hints={'foo': ['bar']},
|
||||||
|
requested_destination=fake_dest)
|
||||||
expected = {'ignore_hosts': ['ignoredhost'],
|
expected = {'ignore_hosts': ['ignoredhost'],
|
||||||
'force_hosts': ['fakehost'],
|
'force_hosts': ['fakehost'],
|
||||||
'force_nodes': ['fakenode'],
|
'force_nodes': ['fakenode'],
|
||||||
@@ -463,7 +475,8 @@ class _TestRequestSpecObject(object):
|
|||||||
'group_hosts': set(['fake1']),
|
'group_hosts': set(['fake1']),
|
||||||
'group_policies': set(['affinity']),
|
'group_policies': set(['affinity']),
|
||||||
'group_members': set(['inst1', 'inst2']),
|
'group_members': set(['inst1', 'inst2']),
|
||||||
'scheduler_hints': {'foo': 'bar'}}
|
'scheduler_hints': {'foo': 'bar'},
|
||||||
|
'requested_destination': fake_dest}
|
||||||
self.assertEqual(expected, spec.to_legacy_filter_properties_dict())
|
self.assertEqual(expected, spec.to_legacy_filter_properties_dict())
|
||||||
|
|
||||||
def test_to_legacy_filter_properties_dict_with_nullable_values(self):
|
def test_to_legacy_filter_properties_dict_with_nullable_values(self):
|
||||||
|
Reference in New Issue
Block a user