From 7813fdbf4b5dc3e384a4d03be7b37d91d3d49f49 Mon Sep 17 00:00:00 2001 From: Sylvain Bauza Date: Thu, 16 Feb 2017 00:02:37 +0100 Subject: [PATCH] Rebuild should verify the host Since rebuild accepts a new image, we should always verify that image by calling the scheduler even if we keep the same compute node. Change-Id: I018e87f3894b4232a9d3500f91384f7e9bb5d2d4 Closes-Bug: #1664931 --- nova/compute/api.py | 14 +++++++++++++- nova/tests/unit/compute/test_compute_api.py | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 3a665d3..1187ac5 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -3008,11 +3008,23 @@ class API(base.Base): # to them, we need to support the old way request_spec = None + if request_spec: + # TODO(sbauza): Hydrate a fake spec for old instances not yet + # having a request spec attached to them (particularly true for + # cells v1). For the moment, let's keep the same behaviour for + # all the instances but provide the destination only if a spec + # is found. + destination = objects.Destination( + host=instance.host, + node=instance.node + ) + request_spec.requested_destination = destination + self.compute_task_api.rebuild_instance(context, instance=instance, new_pass=admin_password, injected_files=files_to_inject, image_ref=image_href, orig_image_ref=orig_image_ref, orig_sys_metadata=orig_sys_metadata, bdms=bdms, - preserve_ephemeral=preserve_ephemeral, host=instance.host, + preserve_ephemeral=preserve_ephemeral, host=None, request_spec=request_spec, kwargs=kwargs) diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index f3c4fc7..76385c4 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -3036,9 +3036,12 @@ class _ComputeAPIUnitTestMixIn(object): injected_files=files_to_inject, image_ref=image_href, orig_image_ref=image_href, orig_sys_metadata=orig_system_metadata, bdms=bdms, - preserve_ephemeral=False, host=instance.host, + preserve_ephemeral=False, host=None, request_spec=fake_spec, kwargs={}) + self.assertTrue(obj_base.obj_equal_prims( + objects.Destination(host=instance.host, node=instance.node), + fake_spec.requested_destination)) _check_auto_disk_config.assert_called_once_with(image=image) _checks_for_create_and_rebuild.assert_called_once_with(self.context, None, image, flavor, {}, [], None) @@ -3102,7 +3105,7 @@ class _ComputeAPIUnitTestMixIn(object): injected_files=files_to_inject, image_ref=new_image_href, orig_image_ref=orig_image_href, orig_sys_metadata=orig_system_metadata, bdms=bdms, - preserve_ephemeral=False, host=instance.host, + preserve_ephemeral=False, host=None, request_spec=fake_spec, kwargs={}) _check_auto_disk_config.assert_called_once_with(image=new_image) -- 2.5.0