diff options
author | Zuul <zuul@review.openstack.org> | 2017-11-16 06:42:02 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-11-16 06:42:03 +0000 |
commit | 091f886b0fb5d57e7ab66313dcab08f3e139c287 (patch) | |
tree | 1d8ea548785609fb9bc97f40ce920294fe370383 | |
parent | fc4defd83860d1e55e15648caa9850f0b942e86d (diff) | |
parent | 6ce8bcab7cd73e27adfd26fceee7ec7c397bfa9b (diff) | |
download | nova-091f886b0fb5d57e7ab66313dcab08f3e139c287.tar.gz |
Merge "Pass requested_destination in filter_properties" into stable/newton
-rw-r--r-- | nova/objects/request_spec.py | 7 | ||||
-rw-r--r-- | nova/tests/functional/regressions/test_bug_1702454.py | 4 | ||||
-rw-r--r-- | nova/tests/unit/objects/test_request_spec.py | 19 |
3 files changed, 25 insertions, 5 deletions
diff --git a/nova/objects/request_spec.py b/nova/objects/request_spec.py index 3c9c9441fa..99fcea6a3b 100644 --- a/nova/objects/request_spec.py +++ b/nova/objects/request_spec.py @@ -247,6 +247,8 @@ class RequestSpec(base.NovaObject): spec._populate_group_info(filter_properties) scheduler_hints = filter_properties.get('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 # original contract @@ -355,6 +357,9 @@ class RequestSpec(base.NovaObject): # we had to hydrate the field by putting a single item into a list. filt_props['scheduler_hints'] = {hint: self.get_scheduler_hint( 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 @classmethod @@ -396,6 +401,8 @@ class RequestSpec(base.NovaObject): spec_obj._from_limits(filter_properties.get('limits', {})) spec_obj._from_hints(filter_properties.get('scheduler_hints', {})) spec_obj.availability_zone = availability_zone + spec_obj.requested_destination = filter_properties.get( + 'requested_destination') # NOTE(sbauza): Default the other fields that are not part of the # original contract diff --git a/nova/tests/functional/regressions/test_bug_1702454.py b/nova/tests/functional/regressions/test_bug_1702454.py index 4216c0c643..c7307f0131 100644 --- a/nova/tests/functional/regressions/test_bug_1702454.py +++ b/nova/tests/functional/regressions/test_bug_1702454.py @@ -151,5 +151,5 @@ class SchedulerOnlyChecksTargetTest(test.TestCase, self._wait_for_state_change(self.api, server, 'ACTIVE') server = self.admin_api.get_server(server_id) - # Unfortunately, the requested host isn't respected. - self.assertEqual('host3', server['OS-EXT-SRV-ATTR:host']) + # Yeepee, that works! + self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host']) diff --git a/nova/tests/unit/objects/test_request_spec.py b/nova/tests/unit/objects/test_request_spec.py index 8e6c819831..040bcce764 100644 --- a/nova/tests/unit/objects/test_request_spec.py +++ b/nova/tests/unit/objects/test_request_spec.py @@ -298,13 +298,22 @@ class _TestRequestSpecObject(object): # just making sure that the context is set by the method 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): ctxt = context.RequestContext('fake-user', 'fake-project') + destination = objects.Destination(host='foo') instance = fake_instance.fake_instance_obj(ctxt) image = {'id': uuids.image_id, 'properties': {'mappings': []}, 'status': 'fake-status', 'location': 'far-away'} flavor = fake_flavor.fake_flavor_obj(ctxt) - filter_properties = {} + filter_properties = {'requested_destination': destination} instance_group = None spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image, @@ -316,6 +325,7 @@ class _TestRequestSpecObject(object): 'Field: %s is not set' % field) # just making sure that the context is set by the method self.assertEqual(ctxt, spec._context) + self.assertEqual(destination, spec.requested_destination) @mock.patch('nova.objects.RequestSpec._populate_group_info') def test_from_components_with_instance_group(self, mock_pgi): @@ -417,6 +427,7 @@ class _TestRequestSpecObject(object): fake_computes_obj = objects.ComputeNodeList( objects=[objects.ComputeNode(host='fake1', hypervisor_hostname='node1')]) + fake_dest = objects.Destination(host='fakehost') spec = objects.RequestSpec( ignore_hosts=['ignoredhost'], force_hosts=['fakehost'], @@ -430,7 +441,8 @@ class _TestRequestSpecObject(object): instance_group=objects.InstanceGroup(hosts=['fake1'], policies=['affinity'], members=['inst1', 'inst2']), - scheduler_hints={'foo': ['bar']}) + scheduler_hints={'foo': ['bar']}, + requested_destination=fake_dest) expected = {'ignore_hosts': ['ignoredhost'], 'force_hosts': ['fakehost'], 'force_nodes': ['fakenode'], @@ -444,7 +456,8 @@ class _TestRequestSpecObject(object): 'group_hosts': set(['fake1']), 'group_policies': set(['affinity']), '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()) def test_to_legacy_filter_properties_dict_with_nullable_values(self): |