From 2dd231cff199bd75bcd3d1031a9ff0a1a82ec1cb Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Fri, 2 Sep 2016 13:39:29 +0300 Subject: [PATCH] HyperV: ensure config drives are copied as well during resizes During cold migration, vhd config drive images are not copied over, on the wrong assumption that the instance is already configured and does not need the config drive. For this reason, migrating instances using vhd config drives will fail, as there is a check ensuring that the config drive is present, if required. This change addresses the issue, removing the check that was preventing the config drive from being copied. Change-Id: I8cd42bed4515f4f75c92e595c4d8b847b16058dd Closes-Bug: #1619602 --- nova/tests/unit/virt/hyperv/test_migrationops.py | 14 +++++++++++--- nova/virt/hyperv/migrationops.py | 10 ++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/nova/tests/unit/virt/hyperv/test_migrationops.py b/nova/tests/unit/virt/hyperv/test_migrationops.py index 7b1302ba16d9..ca90879b9f75 100644 --- a/nova/tests/unit/virt/hyperv/test_migrationops.py +++ b/nova/tests/unit/virt/hyperv/test_migrationops.py @@ -61,6 +61,11 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase): check_shared_storage.return_value = shared_storage self._migrationops._pathutils.exists.return_value = True + fake_disk_files = [os.path.join(instance_path, disk_name) + for disk_name in + ['root.vhd', 'configdrive.vhd', 'configdrive.iso', + 'eph0.vhd', 'eph1.vhdx']] + expected_get_dir = [mock.call(mock.sentinel.instance_name), mock.call(mock.sentinel.instance_name, mock.sentinel.dest_path)] @@ -69,7 +74,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase): self._migrationops._migrate_disk_files( instance_name=mock.sentinel.instance_name, - disk_files=[self._FAKE_DISK], + disk_files=fake_disk_files, dest=mock.sentinel.dest_path) self._migrationops._pathutils.exists.assert_called_once_with( @@ -94,8 +99,11 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase): self._migrationops._pathutils.get_instance_dir.assert_has_calls( expected_get_dir) - self._migrationops._pathutils.copy.assert_called_once_with( - self._FAKE_DISK, fake_dest_path) + self._migrationops._pathutils.copy.assert_has_calls( + mock.call(fake_disk_file, fake_dest_path) + for fake_disk_file in fake_disk_files) + self.assertEqual(len(fake_disk_files), + self._migrationops._pathutils.copy.call_count) self._migrationops._pathutils.move_folder_files.assert_has_calls( expected_move_calls) diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py index 282ef4bcd1be..50fcca828b0a 100644 --- a/nova/virt/hyperv/migrationops.py +++ b/nova/virt/hyperv/migrationops.py @@ -72,12 +72,10 @@ class MigrationOps(object): self._pathutils.makedirs(dest_path) for disk_file in disk_files: - # Skip the config drive as the instance is already configured - if os.path.basename(disk_file).lower() != 'configdrive.vhd': - LOG.debug('Copying disk "%(disk_file)s" to ' - '"%(dest_path)s"', - {'disk_file': disk_file, 'dest_path': dest_path}) - self._pathutils.copy(disk_file, dest_path) + LOG.debug('Copying disk "%(disk_file)s" to ' + '"%(dest_path)s"', + {'disk_file': disk_file, 'dest_path': dest_path}) + self._pathutils.copy(disk_file, dest_path) self._pathutils.move_folder_files(instance_path, revert_path)