Merge "Only attempt a rebuild claim for an evacuation to a new host" into stable/ocata

This commit is contained in:
Zuul 2018-04-19 14:32:42 +00:00 committed by Gerrit Code Review
commit 7bfe54480a
2 changed files with 10 additions and 15 deletions

View File

@ -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 = {}

View File

@ -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