diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 2e83f07ae67d..a7ea7e23b74c 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2722,23 +2722,14 @@ class ComputeManager(manager.Manager): LOG.info(_LI("Rebuilding instance"), instance=instance) - # NOTE(gyee): there are three possible scenarios. - # - # 1. instance is being rebuilt on the same node. In this case, - # recreate should be False and scheduled_node should be None. - # 2. instance is being rebuilt on a node chosen by the - # scheduler (i.e. evacuate). In this case, scheduled_node should - # be specified and recreate should be True. - # 3. instance is being rebuilt on a node chosen by the user. (i.e. - # force evacuate). In this case, scheduled_node is not specified - # and recreate is set to True. - # - # For scenarios #2 and #3, we must do rebuild claim as server is - # being evacuated to a different node. - if recreate or scheduled_node is not None: + if recreate: + # This is an evacuation to a new host, so we need to perform a + # resource claim. rt = self._get_resource_tracker() rebuild_claim = rt.rebuild_claim else: + # This is a rebuild to the same host, so we don't need to make + # a claim since the instance is already on this host. rebuild_claim = claims.NopClaim image_meta = {} diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 394a1a462065..945b53c831d0 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -3022,7 +3022,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): ex = exception.InstanceNotFound(instance_id=instance.uuid) self._test_rebuild_ex(instance, ex) - def test_rebuild_node_not_updated_if_not_recreate(self): + # A rebuild to the same host should never attempt a rebuild claim. + @mock.patch('nova.compute.resource_tracker.ResourceTracker.rebuild_claim', + new_callable=mock.NonCallableMock) + def test_rebuild_node_not_updated_if_not_recreate(self, + mock_rebuild_claim): node = uuidutils.generate_uuid() # ironic node uuid instance = fake_instance.fake_instance_obj(self.context, node=node) instance.migration_context = None