Only attempt a rebuild claim for an evacuation to a new host

Change I11746d1ea996a0f18b7c54b4c9c21df58cc4714b changed the
behavior of the API and conductor when rebuilding an instance
with a new image such that the image is run through the scheduler
filters again to see if it will work on the existing host that
the instance is running on.

As a result, conductor started passing 'scheduled_node' to the
compute which was using it for logic to tell if a claim should be
attempted. We don't need to do a claim for a rebuild since we're
on the same host.

This removes the scheduled_node logic from the claim code, as we
should only ever attempt a claim if we're evacuating, which we
can determine based on the 'recreate' parameter.

Conflicts:
      nova/compute/manager.py

NOTE(mriedem): The conflict is due to change
I0883c2ba1989c5d5a46e23bcbcda53598707bcbc in Queens.

Change-Id: I7fde8ce9dea16679e76b0cb2db1427aeeec0c222
Closes-Bug: #1750618
(cherry picked from commit a39029076c)
(cherry picked from commit 3c5e519a88)
This commit is contained in:
Matt Riedemann 2018-02-20 13:48:12 -05:00
parent 6557395982
commit 9890f3f696
2 changed files with 9 additions and 15 deletions

View File

@ -2793,23 +2793,14 @@ class ComputeManager(manager.Manager):
LOG.info("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 = {}

View File

@ -1159,7 +1159,10 @@ class ServerRebuildTestCase(integrated_helpers._IntegratedTestBase,
'/servers/%s/action' % server['id'], rebuild_req_body)
self.assertIn('NoValidHost', six.text_type(ex))
def test_rebuild_with_new_image(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_with_new_image(self, mock_rebuild_claim):
"""Rebuilds a server with a different image which will run it through
the scheduler to validate the image is still OK with the compute host
that the instance is running on.