Skip to content

Commit 1bf60ce

Browse files
committed
Balloon: Check WMI-Activity after restarting balloon service
Check for WMI-Activity Event ID 5858 since blnsvr.exe start. Filter by ClientProcessId. Use PS exit codes: 0=NONE, 1=HIT, 2=NO_PID. Command configured in cfg. id: 1315 Signed-off-by: Elizabeth Ashurov <eashurov@redhat.com>
1 parent 1339503 commit 1bf60ce

4 files changed

Lines changed: 102 additions & 1 deletion

File tree

deps/balloon/check_wmi_5858.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Check for WMI-Activity Event ID 5858 errors since blnsvr.exe started
2+
# Exit codes:
3+
# 0 - No WMI 5858 events found (NONE)
4+
# 1 - WMI 5858 event found (HIT)
5+
# 2 - Balloon service process not running (NO_PID)
6+
7+
$ErrorActionPreference = 'SilentlyContinue'
8+
$log = 'Microsoft-Windows-WMI-Activity/Operational'
9+
10+
# Get the balloon service process
11+
$p = Get-Process -Name blnsvr -ErrorAction SilentlyContinue | Select-Object -First 1
12+
if (-not $p) {
13+
Write-Output 'NO_PID'
14+
exit 2
15+
}
16+
17+
$blnPid = $p.Id
18+
$start = $p.StartTime.ToUniversalTime()
19+
20+
# Query for WMI 5858 events since the process started
21+
$events = Get-WinEvent -FilterHashtable @{
22+
LogName = $log
23+
Id = 5858
24+
StartTime = $start
25+
} -MaxEvents 50 -ErrorAction SilentlyContinue |
26+
Where-Object {
27+
$_.Level -eq 2 -and
28+
$_.Message -match ('ClientProcessId = ' + $blnPid)
29+
}
30+
31+
$e = $events | Select-Object -First 1
32+
33+
if ($null -ne $e) {
34+
Write-Output 'HIT'
35+
($e | Format-List -Property TimeCreated, Id, Message | Out-String).Trim() | Write-Output
36+
exit 1
37+
} else {
38+
Write-Output 'NONE'
39+
exit 0
40+
}
41+

qemu/tests/balloon_check.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import os
12
import random
23
import re
34
import time
45

56
from avocado.core import exceptions
67
from avocado.utils import process
7-
from virttest import error_context, qemu_monitor, utils_misc, utils_test
8+
from virttest import data_dir, error_context, qemu_monitor, utils_misc, utils_test
89
from virttest.utils_numeric import normalize_data_size
910
from virttest.utils_test.qemu import MemoryBaseTest
1011

@@ -501,6 +502,54 @@ def get_disk_vol(self, session):
501502
except Exception:
502503
self.test.error("Could not get virtio-win disk vol!")
503504

505+
def assert_no_wmi_error_5858(self, session):
506+
"""
507+
Ensure there are no WMI-Activity Event ID 5858 entries emitted by the
508+
balloon service since it started.
509+
This checks the 'Microsoft-Windows-WMI-Activity/Operational' log.
510+
"""
511+
if self.params.get("os_type") != "windows":
512+
return
513+
log_name = "Microsoft-Windows-WMI-Activity/Operational"
514+
error_context.context(
515+
"Verify no WMI 5858 events since blnsvr.exe start (log: %s)" % log_name,
516+
self.test.log.info,
517+
)
518+
519+
# Copy WMI 5858 check script from host to guest
520+
balloon_deps_dir = data_dir.get_deps_dir("balloon")
521+
wmi_script_name = self.params.get("wmi_check_script")
522+
wmi_script_host = os.path.join(balloon_deps_dir, wmi_script_name)
523+
wmi_script_guest_path = self.params.get("wmi_script_guest_path")
524+
self.vm.copy_files_to(wmi_script_host, wmi_script_guest_path)
525+
self.test.log.info("Copied WMI check script to guest: %s", wmi_script_guest_path)
526+
527+
# Execute the script
528+
ps_cmd = self.params.get("wmi_5858_check_cmd") % wmi_script_guest_path
529+
status, output = session.cmd_status_output(ps_cmd)
530+
self.test.log.info(
531+
"WMI 5858 check result: %s (status %s)",
532+
output.strip(),
533+
status,
534+
)
535+
if status == 0:
536+
self.test.log.info(
537+
"No WMI-Activity Event ID 5858 found since blnsvr.exe start."
538+
)
539+
elif status == 1:
540+
self.test.fail(
541+
"Detected WMI-Activity Event ID 5858 since blnsvr.exe start."
542+
)
543+
elif status == 2:
544+
self.test.log.info(
545+
"Balloon service process not running; skipping WMI 5858 check."
546+
)
547+
else:
548+
self.test.fail(
549+
"WMI 5858 check returned unexpected status %s. Output: %s"
550+
% (status, output)
551+
)
552+
504553
@error_context.context_aware
505554
def operate_balloon_service(self, session, operation):
506555
"""

qemu/tests/balloon_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ def balloon_memory(vm, mem_check, min_sz, max_sz):
8989
mem_stat_working = False
9090
for bln_oper in blnsrv_operation:
9191
error_context.context("%s balloon service" % bln_oper, test.log.info)
92+
windows_run = params.get("os_type") == "windows" and bln_oper == "run"
9293
balloon_test.operate_balloon_service(session, bln_oper)
9394

9495
error_context.context(
9596
"Balloon vm memory after %s balloon service" % bln_oper, test.log.info
9697
)
9798
balloon_memory(vm, mem_check, min_sz, max_sz)
99+
if windows_run:
100+
error_context.context(
101+
"Check Windows Event Log for WMI 5858 after service restart",
102+
test.log.info,
103+
)
104+
balloon_test.assert_no_wmi_error_5858(session)
98105
mem_stat_working = True
99106
# for windows guest, disable/uninstall driver to get memory leak based on
100107
# driver verifier is enabled

qemu/tests/cfg/balloon_service.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
only Windows
7070
repeat_times = 1
7171
blnsrv_operation = "stop run"
72+
# WMI 5858 check script (copied from deps/balloon/)
73+
wmi_check_script = "check_wmi_5858.ps1"
74+
wmi_script_guest_path = "C:\check_wmi_5858.ps1"
75+
wmi_5858_check_cmd = "powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File %s"
7276
- sc_interrogate:
7377
type = balloon_sc_interrogate
7478
only Windows

0 commit comments

Comments
 (0)