Merge "Fix race condition in retrying migrations"

This commit is contained in:
Zuul 2018-01-09 16:29:12 +00:00 committed by Gerrit Code Review
commit ac4e15c4c9
2 changed files with 19 additions and 30 deletions

View File

@ -4075,36 +4075,32 @@ class ComputeManager(manager.Manager):
current_period=True)
self._notify_about_instance_usage(
context, instance, "resize.prep.start")
failed = False
try:
self._prep_resize(context, image, instance,
instance_type, filter_properties,
node, migration, clean_shutdown)
except Exception:
failed = True
# Since we hit a failure, we're either rescheduling or dead
# and either way we need to cleanup any allocations created
# by the scheduler for the destination node.
if migration and not self._revert_allocation(
context, instance, migration):
# We did not do a migration-based
# allocation. Note that for a resize to the
# same host, the scheduler will merge the
# flavors, so here we'd be subtracting the new
# flavor from the allocated resources on this
# node.
# FIXME(danms): Remove this in Rocky
rt = self._get_resource_tracker()
rt.delete_allocation_for_failed_resize(
instance, node, instance_type)
# try to re-schedule the resize elsewhere:
exc_info = sys.exc_info()
self._reschedule_resize_or_reraise(context, image, instance,
exc_info, instance_type, request_spec,
filter_properties)
finally:
if failed:
# Since we hit a failure, we're either rescheduling or dead
# and either way we need to cleanup any allocations created
# by the scheduler for the destination node.
if migration and not self._revert_allocation(
context, instance, migration):
# We did not do a migration-based
# allocation. Note that for a resize to the
# same host, the scheduler will merge the
# flavors, so here we'd be subtracting the new
# flavor from the allocated resources on this
# node.
# FIXME(danms): Remove this in Rocky
rt = self._get_resource_tracker()
rt.delete_allocation_for_failed_resize(
instance, node, instance_type)
extra_usage_info = dict(
new_instance_type=instance_type.name,
new_instance_type_id=instance_type.id)

View File

@ -74,14 +74,7 @@ class TestServerResizeReschedule(ProviderUsageBaseTestCase):
data = {"resize": {"flavorRef": self.flavor2['id']}}
self.api.post_server_action(server_uuid, data)
# TODO(edleafe): Remove this when the bug is fixed, and uncomment the
# block below that relies on the fix.
self.assertRaises(AssertionError, self._wait_for_state_change,
self.api, created_server, 'VERIFY_RESIZE')
# Un-comment this when the bug is fixed.
# server = self._wait_for_state_change(self.api, created_server,
# 'VERIFY_RESIZE')
# ctxt = context.get_admin_context()
# instance = objects.Instance.get_by_uuid(ctxt, server["id"])
# self.assertEqual(int(self.flavor2["id"]), instance.flavor.id)
server = self._wait_for_state_change(self.api, created_server,
'VERIFY_RESIZE')
self.assertEqual(self.flavor2['name'],
server['flavor']['original_name'])