-
Notifications
You must be signed in to change notification settings - Fork 68
[VIRT] Add Windows crash detection test with hyperv panic device #4425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dshchedr
merged 4 commits into
RedHatQE:main
from
dshchedr:test/windows-crash-detection
Apr 26, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b2d476f
[VIRT] Add Windows crash detection test with hyperv panic device
dshchedr a2a1648
Add STD docstrings to Windows crash detection test
dshchedr 9fec666
Use vm.vmi.events() directly without TimeoutSampler wrapper
dshchedr 1ea7cfa
Add pytest marks
dshchedr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
tests/virt/node/hyperv_support/test_windows_crash_detection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import logging | ||
|
|
||
| import pytest | ||
| from pyhelper_utils.shell import run_ssh_commands | ||
| from timeout_sampler import TimeoutExpiredError, TimeoutSampler | ||
|
|
||
| from tests.os_params import WINDOWS_LATEST, WINDOWS_LATEST_LABELS | ||
| from utilities.constants import TIMEOUT_3MIN, TIMEOUT_5SEC, TIMEOUT_10SEC | ||
| from utilities.data_collector import collect_vnc_screenshot_for_vms | ||
| from utilities.virt import running_vm, vm_instance_from_template | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
| BSOD_COMMAND = ( | ||
| "$e=$false; $r=0; " | ||
| "Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; " | ||
| 'public class C { [DllImport("ntdll.dll")] public static extern uint NtRaiseHardError' | ||
| "(uint a,uint b,uint c,IntPtr d,uint e,out uint f); " | ||
| '[DllImport("ntdll.dll")] public static extern uint RtlAdjustPrivilege' | ||
| "(int a,bool b,bool c,out bool d);}'; " | ||
| "[C]::RtlAdjustPrivilege(19,$true,$false,[ref]$e) | Out-Null; " | ||
| "[C]::NtRaiseHardError([uint32]3221226528,0,0,[IntPtr]::Zero,6,[ref]$r)" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def windows_crashed(windows_vm_with_panic_device): | ||
| LOGGER.info(f"Triggering BSOD on VM {windows_vm_with_panic_device.name} via NtRaiseHardError") | ||
| try: | ||
| run_ssh_commands( | ||
| host=windows_vm_with_panic_device.ssh_exec, | ||
| commands=["powershell", "-c", BSOD_COMMAND], | ||
| timeout=TIMEOUT_10SEC, | ||
| ) | ||
| except TimeoutError: | ||
| LOGGER.info("SSH timeout as expected - VM has crashed") | ||
|
|
||
|
|
||
| def wait_for_guest_panicked_event(vm): | ||
| LOGGER.info(f"Waiting for GuestPanicked event for VM {vm.name}") | ||
| try: | ||
| for sample in TimeoutSampler( | ||
| wait_timeout=TIMEOUT_3MIN, | ||
| sleep=TIMEOUT_5SEC, | ||
| func=lambda: list(vm.vmi.events(timeout=TIMEOUT_5SEC, field_selector="reason==GuestPanicked")), | ||
| ): | ||
| if sample: | ||
| LOGGER.info("GuestPanicked event found") | ||
| return | ||
| except TimeoutExpiredError: | ||
| LOGGER.error(f"GuestPanicked event not found for VM {vm.name}") | ||
| collect_vnc_screenshot_for_vms(vm=vm) | ||
| raise | ||
|
dshchedr marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def windows_vm_with_panic_device( | ||
| request, | ||
| unprivileged_client, | ||
| namespace, | ||
| golden_image_data_volume_template_for_test_scope_function, | ||
| ): | ||
| vm_dict = {"spec": {"template": {"spec": {"domain": {"devices": {"panicDevices": [{"model": "hyperv"}]}}}}}} | ||
| request.param["vm_dict"] = vm_dict | ||
|
dshchedr marked this conversation as resolved.
|
||
|
|
||
| with vm_instance_from_template( | ||
| request=request, | ||
| unprivileged_client=unprivileged_client, | ||
| namespace=namespace, | ||
| data_volume_template=golden_image_data_volume_template_for_test_scope_function, | ||
| ) as vm: | ||
| running_vm(vm=vm) | ||
| yield vm | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ( | ||
| "enabled_featuregate_scope_function, " | ||
| "golden_image_data_source_for_test_scope_function, " | ||
| "windows_vm_with_panic_device" | ||
| ), | ||
| [ | ||
| pytest.param( | ||
| "PanicDevices", | ||
| {"os_dict": WINDOWS_LATEST}, | ||
| { | ||
| "vm_name": "windows-crash-detection-vm", | ||
| "template_labels": WINDOWS_LATEST_LABELS, | ||
| }, | ||
| marks=pytest.mark.polarion("CNV-15265"), | ||
| ), | ||
| ], | ||
| indirect=True, | ||
| ) | ||
| @pytest.mark.special_infra | ||
| @pytest.mark.high_resource_vm | ||
| def test_windows_crash_detection_with_hyperv_panic( | ||
| enabled_featuregate_scope_function, | ||
| windows_vm_with_panic_device, | ||
| windows_crashed, | ||
| ): | ||
| wait_for_guest_panicked_event(vm=windows_vm_with_panic_device) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.