Skip to content

Commit ea297d6

Browse files
committed
Drop source node allocations if finish_resize fails
By the time finish_resize runs on the dest host, the instance host/node values are already pointing at the dest (they are set by resize_instance on the source compute before casting to finish_resize on the dest). If finish_resize fails, the instance is essentially stuck on the dest host so rather than revert the allocations (which will drop the new flavor allocations against the dest host where the instance now lives) we should just drop the old flavor allocations on the source node resource provider, which is what this change does. The functional regression recreate test is updated to show this working. Change-Id: I52c8d038118c858004e17e71b2fba9e9e2714815 Closes-Bug: #1825537
1 parent f4bb672 commit ea297d6

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

nova/compute/manager.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4716,7 +4716,22 @@ def finish_resize(self, context, disk_info, image, instance,
47164716
migration)
47174717
except Exception:
47184718
with excutils.save_and_reraise_exception():
4719-
self._revert_allocation(context, instance, migration)
4719+
# At this point, resize_instance (which runs on the source) has
4720+
# already updated the instance host/node values to point to
4721+
# this (the dest) compute, so we need to leave the allocations
4722+
# against the dest node resource provider intact and drop the
4723+
# allocations against the source node resource provider. If the
4724+
# user tries to recover the server by hard rebooting it, it
4725+
# will happen on this host so that's where the allocations
4726+
# should go. Note that this is the same method called from
4727+
# confirm_resize to cleanup the source node allocations held
4728+
# by the migration record.
4729+
LOG.info('Deleting allocations for old flavor on source node '
4730+
'%s after finish_resize failure. You may be able to '
4731+
'recover the instance by hard rebooting it.',
4732+
migration.source_compute, instance=instance)
4733+
self._delete_allocation_after_move(
4734+
context, instance, migration)
47204735

47214736
def _finish_resize_helper(self, context, disk_info, image, instance,
47224737
migration):

nova/tests/functional/regressions/test_bug_1825537.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,9 @@ def test_finish_resize_fails_allocation_cleanup(self):
6666
# allocations should still exist with the new flavor.
6767
source_rp_uuid = self._get_provider_uuid_by_host('host1')
6868
dest_rp_uuid = self._get_provider_uuid_by_host('host2')
69-
# FIXME(mriedem): This is bug 1825537 where the allocations are
70-
# reverted when finish_resize fails so the dest node resource provider
71-
# does not have any allocations and the instance allocations are for
72-
# the old flavor on the source node resource provider even though the
73-
# instance is not running on the source host nor pointed at the source
74-
# host in the DB.
75-
# self.assertFlavorMatchesAllocation(
76-
# self.flavor2, server['id'], dest_rp_uuid)
77-
dest_rp_usages = self._get_provider_usages(dest_rp_uuid)
78-
no_usage = {'VCPU': 0, 'MEMORY_MB': 0, 'DISK_GB': 0}
79-
self.assertEqual(no_usage, dest_rp_usages)
8069
self.assertFlavorMatchesAllocation(
81-
self.flavor1, server['id'], source_rp_uuid)
70+
self.flavor2, server['id'], dest_rp_uuid)
71+
# And the source node provider should not have any usage.
72+
source_rp_usages = self._get_provider_usages(source_rp_uuid)
73+
no_usage = {'VCPU': 0, 'MEMORY_MB': 0, 'DISK_GB': 0}
74+
self.assertEqual(no_usage, source_rp_usages)

nova/tests/functional/test_servers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,10 +3670,13 @@ def fake_resize_method(*args, **kwargs):
36703670

36713671
# Ensure the allocation records still exist on the host.
36723672
source_rp_uuid = self._get_provider_uuid_by_host(hostname)
3673-
# FIXME(mriedem): This is wrong for the _finish_resize case.
3674-
# The new_flavor should have been subtracted from the doubled
3675-
# allocation which just leaves us with the original flavor.
3676-
self.assertFlavorMatchesUsage(source_rp_uuid, self.flavor1)
3673+
if failing_method == '_finish_resize':
3674+
# finish_resize will drop the old flavor allocations.
3675+
self.assertFlavorMatchesUsage(source_rp_uuid, self.flavor2)
3676+
else:
3677+
# The new_flavor should have been subtracted from the doubled
3678+
# allocation which just leaves us with the original flavor.
3679+
self.assertFlavorMatchesUsage(source_rp_uuid, self.flavor1)
36773680

36783681
def test_resize_to_same_host_prep_resize_fails(self):
36793682
self._test_resize_to_same_host_instance_fails(

0 commit comments

Comments
 (0)