From 7d9975b661e523c5f689b9f0780c8ac2b0da5719 Mon Sep 17 00:00:00 2001 From: Hubert Cymerys Date: Tue, 16 Sep 2025 13:12:12 +0200 Subject: [PATCH] fix: add wait time to APIs in hypervisor file Added an explicit wait (100ms) in the hypervisor file API calls before triggering VM operations. This change addresses race conditions observed during rapid, consecutive API invocations, as logs showed failures linked to missing initialization. With this update, startup/shutdown of VMs becomes more stable and consistent. Fixes #12. --- mfd_hyperv/hypervisor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mfd_hyperv/hypervisor.py b/mfd_hyperv/hypervisor.py index 98f0156..46d6dc8 100644 --- a/mfd_hyperv/hypervisor.py +++ b/mfd_hyperv/hypervisor.py @@ -86,6 +86,7 @@ def create_vm( hyperv: "HyperV" = None, connection_timeout: int = 3600, dynamic_mng_ip: bool = False, + wait_time: Optional[int] = None, ) -> VM: """Create a new VM using the specified vm_params. @@ -94,6 +95,7 @@ def create_vm( :param hyperv: Hyperv object that will be used by Vm instance :param connection_timeout: timeout of RPyCConnection to VM :param dynamic_mng_ip: To enable or disable dynamic mng ip allocation + :param wait_time: amount of time a program waits """ commands = [ f'New-VM "{vm_params.name}" -Generation {vm_params.generation} -Path {vm_params.vm_dir_path}', @@ -118,6 +120,9 @@ def create_vm( if dynamic_mng_ip: vm_params.mng_ip = mng_ip + if wait_time: + time.sleep(wait_time) + vm_connection = RPyCConnection(ip=vm_params.mng_ip, connection_timeout=connection_timeout) vm = VM(vm_connection, vm_params, owner, hyperv, connection_timeout)