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
This commit is contained in:
Balazs Gibizer 2021-09-01 18:33:33 +02:00
parent 7c1ca501ee
commit 625469d692
1 changed files with 4 additions and 3 deletions

View File

@ -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])