Retry on vmware create_vm when it fails

In some cases the logical switch is not ready when the VM is booted,
so retry can help avoid the error.

Closes-Bug: #1908408
Change-Id: Id6e2be2b407eb08e269c35e0f89d235c67a1ab99
This commit is contained in:
asarfaty
2020-11-29 12:27:46 +02:00
committed by Adit Sarfaty
parent ab07507e5c
commit 9f260f1e6e
2 changed files with 7 additions and 1 deletions

View File

@@ -15,6 +15,7 @@
# under the License.
import collections
import fixtures
import mock
from oslo_utils import units
@@ -1043,7 +1044,8 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
vm_util.ExtraSpecs(),
os_type='invalid_os_type')
self.assertRaises(vexc.VMwareDriverException,
# Because of retries timeout will be raised
self.assertRaises(fixtures.TimeoutException,
vm_util.create_vm, session, self._instance,
'folder', config_spec, 'res-pool')
self.assertTrue(found[0])

View File

@@ -23,6 +23,7 @@ import copy
import functools
from oslo_log import log as logging
from oslo_service import loopingcall
from oslo_utils import excutils
from oslo_utils import units
from oslo_vmware import exceptions as vexc
@@ -1348,6 +1349,9 @@ def get_vmdk_adapter_type(adapter_type):
return vmdk_adapter_type
@loopingcall.RetryDecorator(
max_retry_count=20, inc_sleep_time=2, max_sleep_time=20,
exceptions=(vexc.VimFaultException,))
def create_vm(session, instance, vm_folder, config_spec, res_pool_ref):
"""Create VM on ESX host."""
LOG.debug("Creating VM on the ESX host", instance=instance)