Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion mfd_hyperv/hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def create_vm(
owner: Optional[NetworkAdapterOwner] = None,
hyperv: "HyperV" = None,
connection_timeout: int = 3600,
retry_timeout: int = 60,
retry_time: int = 5,
dynamic_mng_ip: bool = False,
) -> VM:
"""Create a new VM using the specified vm_params.
Expand All @@ -93,6 +95,8 @@ def create_vm(
:param owner: SUT host that will host new Vm
:param hyperv: Hyperv object that will be used by Vm instance
:param connection_timeout: timeout of RPyCConnection to VM
:param retry_timeout: total seconds RPyCConnection will retry on failure
:param retry_time: seconds between each RPyCConnection retry attempt
:param dynamic_mng_ip: To enable or disable dynamic mng ip allocation
"""
commands = [
Expand Down Expand Up @@ -121,7 +125,12 @@ def create_vm(
if dynamic_mng_ip:
vm_params.mng_ip = mng_ip

vm_connection = RPyCConnection(ip=vm_params.mng_ip, connection_timeout=connection_timeout)
vm_connection = RPyCConnection(
ip=vm_params.mng_ip,
connection_timeout=connection_timeout,
retry_timeout=retry_timeout,
retry_time=retry_time,
)
vm = VM(vm_connection, vm_params, owner, hyperv, connection_timeout)

self.vms.append(vm)
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test_mfd_hyperv/test_hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,3 +853,39 @@ def testget_file_size(self, hypervisor, mocker):
hypervisor._connection.execute_powershell.assert_called_once_with(
f"(Get-Item -Path {path}).Length", custom_exception=HyperVExecutionException
)

def test_create_vm_custom_retry_params(self, mocker, hypervisor):
"""Custom retry_timeout and retry_time are forwarded to RPyCConnection."""
vm_params = VMParams(
name="vm_name",
cpu_count=4,
hw_threads_per_core=0,
memory=4096,
generation=2,
vm_dir_path="path",
diff_disk_path="diff_disk_path",
mng_interface_name="mng",
mng_mac_address=MACAddress("00:00:00:00:00:00"),
mng_ip="1.1.1.1",
vswitch_name="vswitch",
)
output = """
VMName : Base_W19_VM001
IPAddresses : {10.91.218.16, fe80::6994:9bd4:d0aa:ff4d}
MacAddress : 525A005BDA10
"""
hypervisor._connection.execute_powershell.return_value = ConnectionCompletedProcess(
return_code=0, args="command", stdout=output, stderr="stderr"
)
mocker.patch("mfd_hyperv.hypervisor.HypervHypervisor.start_vm", return_value=None)
mock_rpyc = mocker.patch("mfd_hyperv.hypervisor.RPyCConnection", autospec=True)
mocker.patch("mfd_hyperv.hypervisor.VM", autospec=True)

hypervisor.create_vm(vm_params, retry_timeout=120, retry_time=10)

mock_rpyc.assert_called_once_with(
ip=vm_params.mng_ip,
connection_timeout=3600,
retry_timeout=120,
retry_time=10,
)
Loading