Merge "Reset instance to current vm_state if rolling back in resize_instance"

This commit is contained in:
Zuul
2019-11-26 12:04:58 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 1 deletions

View File

@@ -5097,7 +5097,12 @@ class ComputeManager(manager.Manager):
def _resize_instance(self, context, instance, image,
migration, instance_type, clean_shutdown,
request_spec):
with self._error_out_instance_on_exception(context, instance), \
# Pass instance_state=instance.vm_state because we can resize
# a STOPPED server and we don't want to set it back to ACTIVE
# in case migrate_disk_and_power_off raises InstanceFaultRollback.
instance_state = instance.vm_state
with self._error_out_instance_on_exception(
context, instance, instance_state=instance_state), \
errors_out_migration_ctxt(migration):
network_info = self.network_api.get_instance_nw_info(context,
instance)

View File

@@ -7871,6 +7871,28 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase,
# Assert that we set the migration to an error state
self.assertEqual("error", self.migration.status)
def test_resize_instance_fail_rollback_stays_stopped(self):
"""Tests that when the driver's migrate_disk_and_power_off method
raises InstanceFaultRollback that the instance vm_state is preserved
rather than reset to ACTIVE which would be wrong if resizing a STOPPED
server.
"""
with self._mock_resize_instance() as (
migrate_disk_and_power_off, notify):
migrate_disk_and_power_off.side_effect = \
exception.InstanceFaultRollback(
exception.ResizeError(reason='unable to resize disk down'))
self.instance.vm_state = vm_states.STOPPED
self.assertRaises(
exception.ResizeError, self.compute.resize_instance,
context=self.context, instance=self.instance, image=self.image,
migration=self.migration,
instance_type='type', clean_shutdown=True,
request_spec=objects.RequestSpec())
# Assert the instance vm_state was unchanged.
self.assertEqual(vm_states.STOPPED, self.instance.vm_state)
def test_resize_instance_notify_failure(self):
# Raise an exception sending the end notification, which is after we
# cast the migration to the destination host