Skip to content

Commit 362534d

Browse files
committed
guest-tools/win: Work around vanishing CD drive
Signed-off-by: Tu Dinh <[email protected]>
1 parent f82af42 commit 362534d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

tests/guest-tools/win/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import enum
22
import logging
33
import re
4+
import time
45
from typing import Any
56

67
from data import ISO_DOWNLOAD_URL
8+
from lib.commands import SSHCommandFailed
79
from lib.common import wait_for
810
from lib.host import Host
911
from lib.sr import SR
@@ -77,10 +79,21 @@ def insert_cd_safe(vm: VM, vdi_name: str, cd_path="D:/", retries=2):
7779
If this happens, reboot the VM in hopes that it will be detected.
7880
"""
7981
for _attempt in range(retries):
82+
# Eject the existing CD just in case.
83+
try:
84+
vm.eject_cd()
85+
# Leave some time for the guest to realize its CD got ejected.
86+
time.sleep(5)
87+
except SSHCommandFailed:
88+
pass
89+
8090
vm.insert_cd(vdi_name)
91+
if not vm.is_running():
92+
vm.start()
8193
# wait_for(vm.file_exists) doesn't handle SSHCommandFailed;
8294
# we need to check for it via wait_for(vm.is_ssh_up).
8395
wait_for_vm_running_and_ssh_up_without_tools(vm)
96+
8497
try:
8598
wait_for(lambda: vm.file_exists(cd_path, regular_file=False), timeout_secs=60)
8699
return
@@ -89,7 +102,5 @@ def insert_cd_safe(vm: VM, vdi_name: str, cd_path="D:/", retries=2):
89102
# There might be no VM tools so use SSH instead.
90103
vm.ssh(WINDOWS_SHUTDOWN_COMMAND)
91104
wait_for(vm.is_halted, "Wait for VM halted")
92-
vm.eject_cd()
93-
vm.start()
94-
wait_for_vm_running_and_ssh_up_without_tools(vm)
105+
95106
raise TimeoutError(f"Waiting for CD at {cd_path} failed")

tests/guest-tools/win/guest_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def install_guest_tools(vm: VM, guest_tools_iso: dict[str, Any], action: PowerAc
2929
rootcert = PureWindowsPath("D:\\") / guest_tools_iso["testsign_cert"]
3030
enable_testsign(vm, rootcert)
3131

32+
# HACK: Sometimes after rebooting the CD drive just vanishes. Check for it again and
33+
# reboot/reinsert CD if needed.
34+
if not vm.file_exists("D:/", regular_file=False):
35+
logging.warning("CD drive not detected, retrying")
36+
insert_cd_safe(vm, guest_tools_iso["name"])
37+
3238
logging.info("Copy Windows PV drivers to VM")
3339
package_path = PureWindowsPath("D:\\") / guest_tools_iso["package"]
3440
vm.execute_powershell_script(f"Copy-Item -Force '{package_path}' '{GUEST_TOOLS_COPY_PATH}'")

tests/guest-tools/win/other_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def install_other_drivers(vm: VM, other_tools_iso_name: str, param: dict[str, An
2424
rootcert = PureWindowsPath("D:\\") / param["path"] / param["testsign_cert"]
2525
enable_testsign(vm, rootcert)
2626

27+
# HACK: Sometimes after rebooting the CD drive just vanishes. Check for it again and
28+
# reboot/reinsert CD if needed.
29+
if not vm.file_exists("D:/", regular_file=False):
30+
logging.warning("CD drive not detected, retrying")
31+
insert_cd_safe(vm, other_tools_iso_name)
32+
2733
package_path = PureWindowsPath("D:\\") / param["path"] / param["package"]
2834
install_cmd = "D:\\install-drivers.ps1 "
2935
if driver_type == "msi":

0 commit comments

Comments
 (0)