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
5 changes: 4 additions & 1 deletion mfd_hyperv/hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def create_vm(
self._connection.execute_powershell(command=command, custom_exception=HyperVExecutionException)

self.start_vm(vm_params.name)
mng_ip = self._wait_vm_mng_ips(vm_params.name)
try:
mng_ip = self._wait_vm_mng_ips(vm_params.name, timeout=180)
except HyperVException as e:
logger.error(f"Failed to get VM {vm_params.name} management IP: {e}")
Comment thread
KTokarze marked this conversation as resolved.
Resolved
if dynamic_mng_ip:
Comment thread
KTokarze marked this conversation as resolved.
Resolved
vm_params.mng_ip = mng_ip

Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_mfd_hyperv/test_hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ def test_create_vm(self, mocker, hypervisor):
hypervisor.create_vm(vm_params, dynamic_mng_ip=True)
assert len(hypervisor.vms) == 1

def test_create_vm_ip_not_found(self, mocker, hypervisor):
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 : {192.168.1.1, 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)
mocker.patch("mfd_hyperv.hypervisor.RPyCConnection", autospec=True)
mocker.patch("mfd_hyperv.hypervisor.VM", autospec=True)
mocker.patch.object(hypervisor, "_wait_vm_mng_ips", side_effect=HyperVException("No IP found"))

hypervisor.create_vm(vm_params, dynamic_mng_ip=False)
assert len(hypervisor.vms) == 1
assert vm_params.mng_ip == "1.1.1.1"

def test_remove_vm_all(self, hypervisor_with_2_vms):
hypervisor_with_2_vms._connection.execute_powershell.return_value = ConnectionCompletedProcess(
return_code=0, args="command", stdout="stdout", stderr="stderr"
Expand Down
Loading