diff --git a/nova/tests/unit/virt/vmwareapi/test_vmops.py b/nova/tests/unit/virt/vmwareapi/test_vmops.py index 15ce73763d3..bf974df62fa 100644 --- a/nova/tests/unit/virt/vmwareapi/test_vmops.py +++ b/nova/tests/unit/virt/vmwareapi/test_vmops.py @@ -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'), @@ -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, @@ -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) diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index bcfe312d676..0a43449f5fa 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -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