Skip to content

Commit

Permalink
allow power-on to fail on finish_resize
Browse files Browse the repository at this point in the history
Power-on is the very last step of a resize/migration.
Failing at this point would leave a VM in a quite inconsistent
state in the DB and in the vCenter.
In case power-on fails, we log an error and let nova continue
putting the vm into VERIFY_RESIZE state. One can then manually
attempt to power-on the VM or revert the resize.

Change-Id: Ic979ce5d7eaf478e5130182a656996cc5f1af29a
  • Loading branch information
leust authored and joker-at-work committed Aug 8, 2023
1 parent 7517f80 commit fe8d4cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion nova/tests/unit/virt/vmwareapi/test_vmops.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ def test_clean_shutdown_no_vwaretools(self):

def _test_finish_migration(self, power_on=True,
resize_instance=False, migration=None,
no_nics=False, is_bigvm=False):
no_nics=False, is_bigvm=False,
power_on_err=None):
with test.nested(
mock.patch.object(self._vmops,
'_resize_create_ephemerals_and_swap'),
Expand Down Expand Up @@ -741,6 +742,9 @@ def _test_finish_migration(self, power_on=True,
self._instance.memory_mb = 2048 * 1024 # 2 TiB RAM
self._instance.flavor.memory_mb = 2048 * 1024 # 2 TiB RAM

if power_on_err:
fake_power_on.side_effect = power_on_err

self._vmops.finish_migration(context=self._context,
migration=migration,
instance=self._instance,
Expand Down Expand Up @@ -809,6 +813,12 @@ def _test_finish_migration(self, power_on=True,
def test_finish_migration_power_on(self):
self._test_finish_migration(power_on=True, resize_instance=False)

@mock.patch.object(vmops.LOG, 'exception')
def test_finish_migration_power_on_fails(self, log_mock):
power_on_err = vexc.VimException()
self._test_finish_migration(power_on=True, power_on_err=power_on_err)
log_mock.assert_called_once_with(mock.ANY, instance=self._instance)

def test_finish_migration_power_off(self):
self._test_finish_migration(power_on=False, resize_instance=False)

Expand Down
6 changes: 5 additions & 1 deletion nova/virt/vmwareapi/vmops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,11 @@ def finish_migration(self, context, migration, instance, disk_info,
total_steps=RESIZE_TOTAL_STEPS)

if power_on:
vm_util.power_on_instance(self._session, instance)
try:
vm_util.power_on_instance(self._session, instance)
except vexc.VimException:
LOG.exception("Failed to power on the VM.",
instance=instance)

def _get_vm_networking_spec(self, instance, network_info):
client_factory = self._session.vim.client.factory
Expand Down

0 comments on commit fe8d4cf

Please sign in to comment.