From c4c65971d366deb31d5ef716e28a8b0e580014b7 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 8 Feb 2018 17:12:46 +0200 Subject: [PATCH] Fix instance dir check when spawning When spawning instances, we're checking if the instance dir already exists, in which case we're logging a message, stating that existing instance files will be reused. Well, at least that's what we thought we were doing. Actually, we're always logging this message as the check is wrong. This change fixes this issue. Change-Id: I6cf52ae23d90e687103e8bea0b6c4f9eaba6d36c Closes-Bug: #1747961 --- compute_hyperv/nova/vmops.py | 2 +- compute_hyperv/tests/unit/test_vmops.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compute_hyperv/nova/vmops.py b/compute_hyperv/nova/vmops.py index c988a2bc..486e5d31 100644 --- a/compute_hyperv/nova/vmops.py +++ b/compute_hyperv/nova/vmops.py @@ -310,7 +310,7 @@ class VMOps(object): instance_dir = self._pathutils.get_instance_dir(instance.name, create_dir=False) - if instance_dir: + if os.path.exists(instance_dir): LOG.info("Instance directory already exists." "Reusing existing files.") diff --git a/compute_hyperv/tests/unit/test_vmops.py b/compute_hyperv/tests/unit/test_vmops.py index 1933405d..5305d4a2 100644 --- a/compute_hyperv/tests/unit/test_vmops.py +++ b/compute_hyperv/tests/unit/test_vmops.py @@ -510,6 +510,8 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): fake_config_drive_path = mock_create_config_drive.return_value block_device_info = {'ephemerals': [], 'root_disk': root_device_info} + self._vmops._pathutils.get_instance_dir.return_value = ( + 'fake-instance-dir') self._vmops._vmutils.vm_exists.return_value = exists mock_configdrive_required.return_value = configdrive_required mock_create_instance.side_effect = fail @@ -532,6 +534,8 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): mock.sentinel.network_info, block_device_info) self._vmops._vmutils.vm_exists.assert_called_once_with( mock_instance.name) + self._vmops._pathutils.get_instance_dir.assert_called_once_with( + mock_instance.name, create_dir=False) mock_validate_and_update_bdi = ( self._vmops._block_dev_man.validate_and_update_bdi) mock_validate_and_update_bdi.assert_called_once_with(