From 9740e18a31c0682d2852ac745242c69475d89113 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Fri, 11 Mar 2016 16:09:52 +0200 Subject: [PATCH] hyper-v: Copies back files on failed migration On cold migration, the contents of the instance folder are copied to the new host. The original folder cannot be removed because the VM configuration files cannot be deleted until the VM is destroyed. Because of this, when the migration fails to copy the files, it will try to revert this through folder renaming. Since the original folder still exists, an exception is raised. Change-Id: Ia42ed873924999d57336a105bcaa2b856f3a3a9d Closes-Bug: #1555699 --- nova/tests/unit/virt/hyperv/test_migrationops.py | 8 +++++--- nova/virt/hyperv/migrationops.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nova/tests/unit/virt/hyperv/test_migrationops.py b/nova/tests/unit/virt/hyperv/test_migrationops.py index 20a17a13d00b..e8a4edcce728 100644 --- a/nova/tests/unit/virt/hyperv/test_migrationops.py +++ b/nova/tests/unit/virt/hyperv/test_migrationops.py @@ -129,10 +129,12 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase): expected = [mock.call(mock.sentinel.dest_path), mock.call(mock.sentinel.revert_path)] self._migrationops._pathutils.exists.assert_has_calls(expected) - self._migrationops._pathutils.rmtree.assert_called_once_with( - mock.sentinel.dest_path) - self._migrationops._pathutils.rename.assert_called_once_with( + move_folder_files = self._migrationops._pathutils.move_folder_files + move_folder_files.assert_called_once_with( mock.sentinel.revert_path, mock.sentinel.instance_path) + self._migrationops._pathutils.rmtree.assert_has_calls([ + mock.call(mock.sentinel.dest_path), + mock.call(mock.sentinel.revert_path)]) def test_check_target_flavor(self): mock_instance = fake_instance.fake_instance_obj(self.context) diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py index db8526dad3b6..c1853301fbcb 100644 --- a/nova/virt/hyperv/migrationops.py +++ b/nova/virt/hyperv/migrationops.py @@ -94,7 +94,8 @@ class MigrationOps(object): if dest_path and self._pathutils.exists(dest_path): self._pathutils.rmtree(dest_path) if self._pathutils.exists(revert_path): - self._pathutils.rename(revert_path, instance_path) + self._pathutils.move_folder_files(revert_path, instance_path) + self._pathutils.rmtree(revert_path) except Exception as ex: # Log and ignore this exception LOG.exception(ex)