From 625469d692f0561cffb5cf1b5c1a0e67f221e9f1 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Wed, 1 Sep 2021 18:33:33 +0200 Subject: [PATCH] Avoid excessive sleep in vmware unit test The patch Id6e2be2b407eb08e269c35e0f89d235c67a1ab99 added a retry decorator on create_vm in vmware driver. Such decorator makes the negative unit test do excessive sleeps and retries. The test eventually stopped by the test executor with a Timeout exception but the test was modified to assert that as a success. This makes the test pass after 160 seconds. This patch mocks the sleep behind the retry decorator to make the test fast and reverts the assert in the test. Change-Id: I7c7e698bf559b69a2f09402c265e6e387c3b077a Related-Bug: #1908408 --- nova/tests/unit/virt/vmwareapi/test_vm_util.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nova/tests/unit/virt/vmwareapi/test_vm_util.py b/nova/tests/unit/virt/vmwareapi/test_vm_util.py index d83a41d7fd7f..ea30895a4df4 100644 --- a/nova/tests/unit/virt/vmwareapi/test_vm_util.py +++ b/nova/tests/unit/virt/vmwareapi/test_vm_util.py @@ -15,9 +15,9 @@ # under the License. import collections -import fixtures import mock +from oslo_service import fixture as oslo_svc_fixture from oslo_utils import units from oslo_utils import uuidutils from oslo_vmware import exceptions as vexc @@ -1024,6 +1024,8 @@ class VMwareVMUtilTestCase(test.NoDBTestCase): """Ensure we warn when create_vm() fails after we passed an unrecognised guestId """ + # avoid real sleeps during test due to te retry decorator on create_vm + self.useFixture(oslo_svc_fixture.SleepFixture()) found = [False] @@ -1042,8 +1044,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase): vm_util.ExtraSpecs(), os_type='invalid_os_type') - # Because of retries timeout will be raised - self.assertRaises(fixtures.TimeoutException, + self.assertRaises(vexc.VMwareDriverException, vm_util.create_vm, session, self._instance, 'folder', config_spec, 'res-pool') self.assertTrue(found[0])