Skip to content

Commit

Permalink
guest-tools/win: Work around vanishing CD drive
Browse files Browse the repository at this point in the history
Signed-off-by: Tu Dinh <[email protected]>
  • Loading branch information
Tu Dinh committed Jan 23, 2025
1 parent f82af42 commit a5e870e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/guest-tools/win/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import enum
import logging
import re
import time
from typing import Any

from data import ISO_DOWNLOAD_URL
from lib.commands import SSHCommandFailed
from lib.common import wait_for
from lib.host import Host
from lib.sr import SR
Expand Down Expand Up @@ -77,10 +79,21 @@ def insert_cd_safe(vm: VM, vdi_name: str, cd_path="D:/", retries=2):
If this happens, reboot the VM in hopes that it will be detected.
"""
for _attempt in range(retries):
# Eject the existing CD just in case.
try:
vm.eject_cd()
# Leave some time for the guest to realize its CD got ejected.
time.sleep(5)
except SSHCommandFailed:
pass

vm.insert_cd(vdi_name)
if not vm.is_running():
vm.start()
# wait_for(vm.file_exists) doesn't handle SSHCommandFailed;
# we need to check for it via wait_for(vm.is_ssh_up).
wait_for_vm_running_and_ssh_up_without_tools(vm)

try:
wait_for(lambda: vm.file_exists(cd_path, regular_file=False), timeout_secs=60)
return
Expand All @@ -89,7 +102,5 @@ def insert_cd_safe(vm: VM, vdi_name: str, cd_path="D:/", retries=2):
# There might be no VM tools so use SSH instead.
vm.ssh(WINDOWS_SHUTDOWN_COMMAND)
wait_for(vm.is_halted, "Wait for VM halted")
vm.eject_cd()
vm.start()
wait_for_vm_running_and_ssh_up_without_tools(vm)

raise TimeoutError(f"Waiting for CD at {cd_path} failed")
2 changes: 2 additions & 0 deletions tests/guest-tools/win/guest_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def install_guest_tools(vm: VM, guest_tools_iso: dict[str, Any], action: PowerAc
enable_testsign(vm, rootcert)

logging.info("Copy Windows PV drivers to VM")
# HACK: Sometimes after rebooting the CD drive just vanishes. Check for it again.
insert_cd_safe(vm, guest_tools_iso["name"])
package_path = PureWindowsPath("D:\\") / guest_tools_iso["package"]
vm.execute_powershell_script(f"Copy-Item -Force '{package_path}' '{GUEST_TOOLS_COPY_PATH}'")

Expand Down

0 comments on commit a5e870e

Please sign in to comment.