Skip to content

Commit 504b0e9

Browse files
authored
Merge pull request #658 from xcp-ng/dnt/winpv
Update Windows guest tools tests
2 parents dada3a6 + afd5d97 commit 504b0e9

3 files changed

Lines changed: 79 additions & 76 deletions

File tree

lib/vif.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def plug(self) -> None:
6161
logging.info("Plugging VIF %s on VM %s", self.param_get('device'), self.vm.uuid)
6262
self.vm.host.xe('vif-plug', {'uuid': self.uuid})
6363

64-
def unplug(self) -> None:
64+
def unplug(self, force: bool = False) -> None:
6565
logging.info("Unplugging VIF %s on VM %s", self.param_get('device'), self.vm.uuid)
66-
self.vm.host.xe('vif-unplug', {'uuid': self.uuid})
66+
self.vm.host.xe('vif-unplug', {'uuid': self.uuid, 'force': force})
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pytest
2+
3+
import logging
4+
5+
from lib.commands import SSHCommandFailed
6+
from lib.vm import VM
7+
from lib.windows import (
8+
PowerAction,
9+
check_vm_dns,
10+
set_vm_dns,
11+
vm_shutdown_without_tools,
12+
wait_for_vm_running_and_ssh_up_without_tools,
13+
)
14+
from lib.windows.guest_tools import ERROR_INSTALL_FAILURE, install_guest_tools, uninstall_guest_tools
15+
16+
from typing import Any, Tuple
17+
18+
# Requirements:
19+
# - Same as TestGuestToolsWindowsNondestructive.
20+
21+
22+
@pytest.mark.multi_vms
23+
@pytest.mark.usefixtures("windows_vm")
24+
class TestGuestToolsWindowsDestructive:
25+
def test_uninstall_tools(self, vm_install_test_tools_no_reboot: VM) -> None:
26+
vm = vm_install_test_tools_no_reboot
27+
vm_shutdown_without_tools(vm)
28+
vm.start()
29+
wait_for_vm_running_and_ssh_up_without_tools(vm)
30+
31+
set_vm_dns(vm)
32+
logging.info("Uninstall Windows PV drivers")
33+
uninstall_guest_tools(vm, action=PowerAction.Reboot)
34+
logging.info("Check tools uninstalled")
35+
assert vm.are_windows_tools_uninstalled()
36+
check_vm_dns(vm)
37+
38+
def test_uninstall_tools_early(self, vm_install_test_tools_no_reboot: VM) -> None:
39+
vm = vm_install_test_tools_no_reboot
40+
logging.info("Uninstall Windows PV drivers before rebooting")
41+
uninstall_guest_tools(vm, action=PowerAction.Reboot)
42+
assert vm.are_windows_tools_uninstalled()
43+
44+
def test_install_with_other_tools(
45+
self, vm_install_other_drivers: Tuple[VM, dict[str, Any]], guest_tools_iso: dict[str, Any]
46+
) -> None:
47+
vm, param = vm_install_other_drivers
48+
if param["upgradable"]:
49+
install_guest_tools(vm, guest_tools_iso, PowerAction.Reboot, check=False)
50+
assert vm.are_windows_tools_working()
51+
else:
52+
exitcode = install_guest_tools(vm, guest_tools_iso, PowerAction.Nothing, check=False)
53+
assert exitcode == ERROR_INSTALL_FAILURE
54+
55+
@pytest.mark.usefixtures("uefi_vm")
56+
def test_uefi_vm_suspend_refused_without_tools(self, running_unsealed_windows_vm: VM) -> None:
57+
vm = running_unsealed_windows_vm
58+
with pytest.raises(SSHCommandFailed, match="lacks the feature"):
59+
vm.suspend()
60+
wait_for_vm_running_and_ssh_up_without_tools(vm)
61+
62+
# Test of the unplug rework, where the driver must remain activated even if the device ID changes.
63+
# Also serves as a "close-enough" test of vendor device toggling.
64+
def test_toggle_device_id(self, running_unsealed_windows_vm: VM, guest_tools_iso: dict[str, Any]) -> None:
65+
vm = running_unsealed_windows_vm
66+
assert vm.param_get("platform", "device_id") == "0002"
67+
install_guest_tools(vm, guest_tools_iso, PowerAction.Shutdown, check=False)
68+
vm.param_set("platform", "0001", "device_id")
69+
vm.start()
70+
vm.wait_for_vm_running_and_ssh_up()

tests/guest_tools/win/test_guest_tools_win.py renamed to tests/guest_tools/win/test_nondestructive.py

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,15 @@
33
import pytest
44

55
import logging
6-
import time
76

8-
from lib.commands import SSHCommandFailed
97
from lib.common import strtobool, wait_for
108
from lib.vm import VM
119
from lib.windows import (
12-
PowerAction,
1310
check_vm_clipboard,
1411
check_vm_distro,
15-
check_vm_dns,
16-
set_vm_dns,
1712
vif_has_rss,
18-
vm_shutdown_without_tools,
1913
wait_for_vm_running_and_ssh_up_without_tools,
2014
)
21-
from lib.windows.guest_tools import (
22-
ERROR_INSTALL_FAILURE,
23-
install_guest_tools,
24-
uninstall_guest_tools,
25-
)
26-
27-
from typing import Any, Tuple
2815

2916
# Requirements:
3017
# - XCP-ng >= 8.2.
@@ -71,21 +58,18 @@
7158

7259
@pytest.mark.multi_vms
7360
@pytest.mark.usefixtures("windows_vm")
74-
class TestGuestToolsWindows:
61+
class TestGuestToolsWindowsNondestructive:
7562
def test_drivers_detected(self, vm_install_test_tools_per_test_class: VM) -> None:
7663
pass
7764

78-
def test_vif_replug(self, vm_install_test_tools_per_test_class: VM) -> None:
65+
@pytest.mark.parametrize("force", (False, True))
66+
def test_vif_replug(self, vm_install_test_tools_per_test_class: VM, force: bool) -> None:
7967
vm = vm_install_test_tools_per_test_class
8068
for _iter in range(3):
8169
vifs = vm.vifs()
8270
for vif in vifs:
8371
assert strtobool(vif.param_get("currently-attached"))
84-
vif.unplug()
85-
# HACK: Allow some time for the unplug to settle. If not, Windows guests have a tendency to explode.
86-
# TODO reference: XCPNG-1395
87-
assert not strtobool(vif.param_get("currently-attached"))
88-
time.sleep(5)
72+
vif.unplug(force=force)
8973
vif.plug()
9074
wait_for(vm.is_ssh_up, "Wait for SSH up")
9175

@@ -111,11 +95,11 @@ def test_reporting_after_xeniface_disable(self, vm_install_test_tools_per_test_c
11195
check_vm_distro(vm)
11296
check_vm_clipboard(vm)
11397

114-
def test_reporting_after_suspend(self, vm_install_test_tools_per_test_class: VM) -> None:
98+
def test_reporting_after_migration(self, vm_install_test_tools_per_test_class: VM) -> None:
11599
vm = vm_install_test_tools_per_test_class
100+
residence = vm.get_residence_host()
116101
for _iter in range(3):
117-
vm.suspend(verify=True)
118-
vm.resume()
102+
vm.migrate(residence)
119103
wait_for_vm_running_and_ssh_up_without_tools(vm)
120104
check_vm_distro(vm)
121105
check_vm_clipboard(vm)
@@ -141,54 +125,3 @@ def test_xenvbd_ssd(self, vm_install_test_tools_per_test_class: VM) -> None:
141125
)
142126
)
143127
assert is_ssd
144-
145-
146-
@pytest.mark.multi_vms
147-
@pytest.mark.usefixtures("windows_vm")
148-
class TestGuestToolsWindowsDestructive:
149-
def test_uninstall_tools(self, vm_install_test_tools_no_reboot: VM) -> None:
150-
vm = vm_install_test_tools_no_reboot
151-
vm_shutdown_without_tools(vm)
152-
vm.start()
153-
wait_for_vm_running_and_ssh_up_without_tools(vm)
154-
155-
set_vm_dns(vm)
156-
logging.info("Uninstall Windows PV drivers")
157-
uninstall_guest_tools(vm, action=PowerAction.Reboot)
158-
logging.info("Check tools uninstalled")
159-
assert vm.are_windows_tools_uninstalled()
160-
check_vm_dns(vm)
161-
162-
def test_uninstall_tools_early(self, vm_install_test_tools_no_reboot: VM) -> None:
163-
vm = vm_install_test_tools_no_reboot
164-
logging.info("Uninstall Windows PV drivers before rebooting")
165-
uninstall_guest_tools(vm, action=PowerAction.Reboot)
166-
assert vm.are_windows_tools_uninstalled()
167-
168-
def test_install_with_other_tools(
169-
self, vm_install_other_drivers: Tuple[VM, dict[str, Any]], guest_tools_iso: dict[str, Any]
170-
) -> None:
171-
vm, param = vm_install_other_drivers
172-
if param["upgradable"]:
173-
install_guest_tools(vm, guest_tools_iso, PowerAction.Reboot, check=False)
174-
assert vm.are_windows_tools_working()
175-
else:
176-
exitcode = install_guest_tools(vm, guest_tools_iso, PowerAction.Nothing, check=False)
177-
assert exitcode == ERROR_INSTALL_FAILURE
178-
179-
@pytest.mark.usefixtures("uefi_vm")
180-
def test_uefi_vm_suspend_refused_without_tools(self, running_unsealed_windows_vm: VM) -> None:
181-
vm = running_unsealed_windows_vm
182-
with pytest.raises(SSHCommandFailed, match="lacks the feature"):
183-
vm.suspend()
184-
wait_for_vm_running_and_ssh_up_without_tools(vm)
185-
186-
# Test of the unplug rework, where the driver must remain activated even if the device ID changes.
187-
# Also serves as a "close-enough" test of vendor device toggling.
188-
def test_toggle_device_id(self, running_unsealed_windows_vm: VM, guest_tools_iso: dict[str, Any]) -> None:
189-
vm = running_unsealed_windows_vm
190-
assert vm.param_get("platform", "device_id") == "0002"
191-
install_guest_tools(vm, guest_tools_iso, PowerAction.Shutdown, check=False)
192-
vm.param_set("platform", "0001", "device_id")
193-
vm.start()
194-
vm.wait_for_vm_running_and_ssh_up()

0 commit comments

Comments
 (0)