Skip to content

Commit 7b98058

Browse files
authored
Merge pull request #432 from xcp-ng/dnt/win-145
Add more fixes and hacks for Windows tests with 9.1.145
2 parents d3d1b55 + 466bb8e commit 7b98058

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

lib/windows/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,24 @@ def vif_set_dns(vif: VIF, nameservers: List[str]):
147147
)
148148

149149

150+
def is_vm_offboarded_xenvif(vm: VM):
151+
try:
152+
val = vm.execute_powershell_script(
153+
r'$null -eq (Get-ScheduledTask "Copy-XenVifSettings" -ErrorAction SilentlyContinue)', simple_output=True
154+
)
155+
# Sometimes, we may get an error like "invalid truth value 'mux_client_request_session: read from master failed:
156+
# broken pipe'". If so, just retry.
157+
if "broken pipe" in val.lower():
158+
return False
159+
return strtobool(val)
160+
except SSHCommandFailed:
161+
# This check itself can fail when Copy-XenVifSettings runs, so we have to tolerate its failure.
162+
return False
163+
164+
150165
def wait_for_vm_xenvif_offboard(vm: VM):
151166
# Xenvif offboard will reset the NIC, so need to wait for it to disappear first
152-
wait_for(
153-
lambda: strtobool(
154-
vm.execute_powershell_script(
155-
r'$null -eq (Get-ScheduledTask "Copy-XenVifSettings" -ErrorAction SilentlyContinue)', simple_output=True
156-
)
157-
),
158-
timeout_secs=300,
159-
retry_delay_secs=30,
160-
)
167+
wait_for(lambda: is_vm_offboarded_xenvif(vm), timeout_secs=180, retry_delay_secs=15)
161168

162169

163170
def set_vm_dns(vm: VM):

lib/windows/other_tools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23
from pathlib import PureWindowsPath
34

45
from lib.common import strtobool, wait_for
@@ -50,3 +51,9 @@ def install_other_drivers(vm: VM, other_tools_iso_name: str, param: Dict[str, An
5051
vm.eject_cd()
5152
vm.start()
5253
wait_for_vm_running_and_ssh_up_without_tools(vm)
54+
# HACK: For some reason, the XenServer 9.4.2 package causes a network blip after bootup. This could exhibit as
55+
# random disconnections, SSH command failure, etc. The reason is not yet clear, but retry confirmation of the
56+
# network link as a workaround.
57+
# TODO: XCPNG-3038
58+
time.sleep(30)
59+
wait_for_vm_running_and_ssh_up_without_tools(vm)

tests/guest_tools/win/test_guest_tools_win.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ def test_xenvbd_ssd(self, vm_install_test_tools_per_test_class: VM):
131131
"""Xenvbd must always advertise as SSD to avoid unnecessary defragging by Windows."""
132132
vm = vm_install_test_tools_per_test_class
133133
is_ssd = strtobool(
134+
# We have to filter Get-PhysicalDisk instead of piping directly from Get-Disk since direct Get-PhysicalDisk
135+
# by ID doesn't work on Server 2016.
134136
vm.execute_powershell_script(
135-
r'''(Get-PhysicalDisk -DeviceNumber (Get-Partition -DriveLetter C).DiskNumber).MediaType -eq "SSD"'''
137+
r'''$disk = Get-Partition -DriveLetter ($Env:SystemDrive[0]) | Get-Disk;
138+
(Get-PhysicalDisk | Where-Object UniqueId -eq $disk.UniqueId).MediaType -eq "SSD"'''
136139
)
137140
)
138141
assert is_ssd

tests/guest_tools/win/test_xenclean.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def run_xenclean(vm: VM, guest_tools_iso: Dict[str, Any]):
2424

2525
logging.info("Run XenClean")
2626
xenclean_path = PureWindowsPath("D:\\") / guest_tools_iso["xenclean_path"]
27-
xenclean_cmd = f"Set-Location C:\\; {xenclean_path} -NoReboot -Confirm:$false; {WINDOWS_SHUTDOWN_COMMAND}"
27+
if guest_tools_iso["xenclean_path"].lower().endswith(".ps1"):
28+
xenclean_cmd = f"Set-Location C:\\; {xenclean_path} -NoReboot -Confirm:$false; {WINDOWS_SHUTDOWN_COMMAND}"
29+
else:
30+
xenclean_cmd = f"Set-Location C:\\; {xenclean_path} -noReboot -noConfirm; {WINDOWS_SHUTDOWN_COMMAND}"
2831
vm.start_background_powershell(xenclean_cmd)
2932

3033
# XenClean sometimes takes a bit long due to all the calls to the uninstallers. We need an extended timeout.

0 commit comments

Comments
 (0)