Skip to content

Commit

Permalink
win_guest_debugging_tool: Support new feature
Browse files Browse the repository at this point in the history
win_guest_debugging_tool is a new feature for windows guest to
gather a wide range of information. including system configuration
 event logs, drivers, registry settings, update logs, services,
uptime, processes, installed applications,network configuration
 installed KBs (knowledge base articleand optionally, memory dumps
It's a powershell script is designed for comprehensive system
diagnostics.

Signed-off-by: Dehan Meng <[email protected]>
  • Loading branch information
6-dehan committed Dec 12, 2024
1 parent d516da1 commit c9bf00e
Show file tree
Hide file tree
Showing 2 changed files with 255 additions and 0 deletions.
27 changes: 27 additions & 0 deletions qemu/tests/cfg/win_guest_debugging_tool.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- win_guest_debugging_tool: install setup image_copy unattended_install.cdrom
only Windows
type = win_guest_debugging_tool
tmp_dir = %TEMP%
runtimeout = 360
shutdown_command = "shutdown -s -t 0"
reboot_command = "shutdown -r -t 0"
cmd_unrestrict_policy = 'Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force'
variants:
- check_script_execution:
windegtool_check_type = script_execution
- check_zip_package:
windegtool_check_type = zip_package
- check_run_tools_multi_times:
windegtool_check_type = run_tools_multi_times
- check_user_friendliness:
windegtool_check_type = user_friendliness
- check_disk_registry_collection:
windegtool_check_type = disk_registry_collection
- check_includeSensitiveData_collection:
windegtool_check_type = includeSensitiveData_collection
- check_trigger_driver_collection:
windegtool_check_type = trigger_driver_collection
- check_networkadapter_collection:
windegtool_check_type = networkadapter_collection
- check_documentation:
windegtool_check_type = documentation
228 changes: 228 additions & 0 deletions qemu/tests/win_guest_debugging_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import logging
import time
import os
import re
import base64
import random
import string
import json

import aexpect

from avocado.utils import genio
from avocado.utils import path as avo_path
from avocado.utils import process
from avocado.core import exceptions
from aexpect.exceptions import ShellTimeoutError

from virttest import error_context
from virttest import guest_agent
from virttest import utils_misc
from virttest import utils_disk
from virttest import env_process
from virttest import utils_net
from virttest import data_dir
from virttest import storage
from virttest import qemu_migration
from virttest.utils_version import VersionInterval

from virttest.utils_windows import virtio_win
from provider.win_driver_installer_test import (uninstall_gagent,
run_installer_with_interaction)

LOG_JOB = logging.getLogger('avocado.test')


class BaseVirtTest(object):

def __init__(self, test, params, env):
self.test = test
self.params = params
self.env = env

def initialize(self, test, params, env):
if test:
self.test = test
if params:
self.params = params
if env:
self.env = env
start_vm = self.params["start_vm"]
self.start_vm = start_vm
if self.start_vm == "yes":
vm = self.env.get_vm(params["main_vm"])
vm.verify_alive()
self.vm = vm

def setup(self, test, params, env):
if test:
self.test = test
if params:
self.params = params
if env:
self.env = env

def run_once(self, test, params, env):
if test:
self.test = test
if params:
self.params = params
if env:
self.env = env

def before_run_once(self, test, params, env):
pass

def after_run_once(self, test, params, env):
pass

def cleanup(self, test, params, env):
pass

def execute(self, test, params, env):
self.initialize(test, params, env)
self.setup(test, params, env)
try:
self.before_run_once(test, params, env)
self.run_once(test, params, env)
self.after_run_once(test, params, env)
finally:
self.cleanup(test, params, env)


class WinDebugToolTest(BaseVirtTest):
def __init__(self, test, params, env):
super().__init__(test, params, env)
self._open_session_list = []
self.vm = None
self.script_name = "CollectSystemInfo.ps1" # Assuming script is named CollectSystemInfo.ps1

def _get_session(self, params, vm):
if not vm:
vm = self.vm
vm.verify_alive()
timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=timeout)
return session

def _cleanup_open_session(self):
try:
for s in self._open_session_list:
if s:
s.close()
except Exception:
pass

def run_once(self, test, params, env):
BaseVirtTest.run_once(self, test, params, env)
if self.start_vm == "yes":
pass

def cleanup(self, test, params, env):
self._cleanup_open_session()

def _check_tool_exist(self, test, params, session):

error_context.context("Check whether debug tool exists.", LOG_JOB.info)
cmd_check_dir = params['cmd_check_dir' % debug_tool_path]
file_check_list = params['file_check_list']
s, o = session.cmd_status_output(cmd_check_dir)
if s == 0 and o:
for file in file_check_list:
if file in o:
test.error('File %s should exist under %s' % (file, debug_tool_path))
else:
test.error('The debug tool path doesn not exist. Please contact with vendor.')
return s == 1
self.script_path = script_path
return s == 0

def _check_file_zip(self, test, params, env):
# Check the folder and zip package
pass

def _cleanup_files(self, log_folder, dump_folder, log_zip, dump_zip):
# This function can be customized to clean up or archive files after test
cmd_clean_logfoler(self.params[cmd_clean_files] % log_folder)
cmd_clean_dumpfolder(self.params[cmd_clean_files] % dump_folder)
cmd_clean_logzip(self.params[cmd_clean_files] % log_zip)
cmd_clean_dumpzip(self.params[cmd_clean_files] % dump_zip)
session.cmd(cmd_clean_logfolder)
if dump_folder:
session.cmd(cmd_clean_dumpfolder)
session.cmd(cmd_clean_logzip)
if dump_zip:
session.cmd(cmd_clean_dumpzip)


class WinDebugToolTestBasicCheck(WinDebugToolTest):

def windegtool_check_script_execution(self, test, params, env):
# Running the PowerShell script on the VM
include_sensitive_data = self.params.get("include_sensitive_data", False)
sensitive_data_flag = "-IncludeSensitiveData" if include_sensitive_data else ""

# Ensure the script runs with an unrestricted execution policy
cmd_unrestrict_policy = self.params['cmd_unrestrict_policy']
session.cmd(cmd_unrestrict_policy)

# Execute the command on the VM
cmd_run_deg_tool = f"powershell {self.script_path} {sensitive_data_flag}"
session.cmd_status_output(cmd_run_deg_tool)
pass

def windegtool_check_zip_package(self, test, params, env):
pass

def windegtool_check_run_tools_multi_times(self, test, params, env):
pass

def windegtool_check_user_friendliness(self, test, params, env):
pass

def windegtool_check_disk_registry_collection(self, test, param, env):
pass

def windegtool_check_includeSensitiveData_collection(self, test, param, env):
pass

def windegtool_check_trigger_driver_collection(self, test, param, env):
pass

def windegtool_check_networkadapter_collection(self, test, param, env):
pass

def windegtool_check_documentation(self, test, param, env):
pass

def run_once(self, test, params, env):
WinDebugToolTest.run_once(self, test, params, env)

windegtool_check_type = self.params["windegtool_check_type"]
chk_type = "windegtool_check_%s" % windegtool_check_type
if hasattr(self, chk_type):
func = getattr(self, chk_type)
func(test, params, env)
else:
test.error("Could not find matching test, check your config file")



def run(test, params, env):
"""
Test CollectSystemInfo.ps1 tool, this case will:
1) Start VM with virtio-win rpm package.
2) Execute CollectSystemInfo.ps1 with&without param
'-IncludeSensitiveData'.
3) Run some basic test for CollectSystemInfo.ps1.
:param test: kvm test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environmen.
"""
if params["os_type"] == "windows":
collectinfotool_test = WinDebugToolTestBasicCheck(test, params, env)
else:
pass

gagent_test.execute(test, params, env)

0 comments on commit c9bf00e

Please sign in to comment.