1
+ import logging
2
+ import time
3
+ import os
4
+ import re
5
+ import base64
6
+ import random
7
+ import string
8
+ import json
9
+
10
+ import aexpect
11
+
12
+ from avocado .utils import genio
13
+ from avocado .utils import path as avo_path
14
+ from avocado .utils import process
15
+ from avocado .core import exceptions
16
+ from aexpect .exceptions import ShellTimeoutError
17
+
18
+ from virttest import error_context
19
+ from virttest import guest_agent
20
+ from virttest import utils_misc
21
+ from virttest import utils_disk
22
+ from virttest import env_process
23
+ from virttest import utils_net
24
+ from virttest import data_dir
25
+ from virttest import storage
26
+ from virttest import qemu_migration
27
+ from virttest .utils_version import VersionInterval
28
+
29
+ from virttest .utils_windows import virtio_win
30
+ from provider .win_driver_installer_test import (uninstall_gagent ,
31
+ run_installer_with_interaction )
32
+
33
+ LOG_JOB = logging .getLogger ('avocado.test' )
34
+
35
+
36
+ class BaseVirtTest (object ):
37
+
38
+ def __init__ (self , test , params , env ):
39
+ self .test = test
40
+ self .params = params
41
+ self .env = env
42
+
43
+ def initialize (self , test , params , env ):
44
+ if test :
45
+ self .test = test
46
+ if params :
47
+ self .params = params
48
+ if env :
49
+ self .env = env
50
+ start_vm = self .params ["start_vm" ]
51
+ self .start_vm = start_vm
52
+ if self .start_vm == "yes" :
53
+ vm = self .env .get_vm (params ["main_vm" ])
54
+ vm .verify_alive ()
55
+ self .vm = vm
56
+
57
+ def setup (self , test , params , env ):
58
+ if test :
59
+ self .test = test
60
+ if params :
61
+ self .params = params
62
+ if env :
63
+ self .env = env
64
+
65
+ def run_once (self , test , params , env ):
66
+ if test :
67
+ self .test = test
68
+ if params :
69
+ self .params = params
70
+ if env :
71
+ self .env = env
72
+
73
+ def before_run_once (self , test , params , env ):
74
+ pass
75
+
76
+ def after_run_once (self , test , params , env ):
77
+ pass
78
+
79
+ def cleanup (self , test , params , env ):
80
+ pass
81
+
82
+ def execute (self , test , params , env ):
83
+ self .initialize (test , params , env )
84
+ self .setup (test , params , env )
85
+ try :
86
+ self .before_run_once (test , params , env )
87
+ self .run_once (test , params , env )
88
+ self .after_run_once (test , params , env )
89
+ finally :
90
+ self .cleanup (test , params , env )
91
+
92
+
93
+ class WinDebugToolTest (BaseVirtTest ):
94
+ def __init__ (self , test , params , env ):
95
+ super ().__init__ (test , params , env )
96
+ self ._open_session_list = []
97
+ self .vm = None
98
+ self .script_name = "CollectSystemInfo.ps1" # Assuming script is named CollectSystemInfo.ps1
99
+
100
+ def _get_session (self , params , vm ):
101
+ if not vm :
102
+ vm = self .vm
103
+ vm .verify_alive ()
104
+ timeout = int (params .get ("login_timeout" , 360 ))
105
+ session = vm .wait_for_login (timeout = timeout )
106
+ return session
107
+
108
+ def _cleanup_open_session (self ):
109
+ try :
110
+ for s in self ._open_session_list :
111
+ if s :
112
+ s .close ()
113
+ except Exception :
114
+ pass
115
+
116
+ def run_once (self , test , params , env ):
117
+ BaseVirtTest .run_once (self , test , params , env )
118
+ if self .start_vm == "yes" :
119
+ pass
120
+
121
+ def cleanup (self , test , params , env ):
122
+ self ._cleanup_open_session ()
123
+
124
+ def _check_tool_exist (self , test , params , session ):
125
+
126
+ error_context .context ("Check whether debug tool exists." , LOG_JOB .info )
127
+ cmd_check_dir = params ['cmd_check_dir' % debug_tool_path ]
128
+ file_check_list = params ['file_check_list' ]
129
+ s , o = session .cmd_status_output (cmd_check_dir )
130
+ if s == 0 and o :
131
+ for file in file_check_list :
132
+ if file in o :
133
+ test .error ('File %s should exist under %s' % (file , debug_tool_path ))
134
+ else :
135
+ test .error ('The debug tool path doesn not exist. Please contact with vendor.' )
136
+ return s == 1
137
+ self .script_path = script_path
138
+ return s == 0
139
+
140
+ def _check_file_zip (self , test , params , env ):
141
+ # Check the folder and zip package
142
+ pass
143
+
144
+ def _cleanup_files (self , log_folder , dump_folder , log_zip , dump_zip ):
145
+ # This function can be customized to clean up or archive files after test
146
+ cmd_clean_logfoler (self .params [cmd_clean_files ] % log_folder )
147
+ cmd_clean_dumpfolder (self .params [cmd_clean_files ] % dump_folder )
148
+ cmd_clean_logzip (self .params [cmd_clean_files ] % log_zip )
149
+ cmd_clean_dumpzip (self .params [cmd_clean_files ] % dump_zip )
150
+ session .cmd (cmd_clean_logfolder )
151
+ if dump_folder :
152
+ session .cmd (cmd_clean_dumpfolder )
153
+ session .cmd (cmd_clean_logzip )
154
+ if dump_zip :
155
+ session .cmd (cmd_clean_dumpzip )
156
+
157
+
158
+ class WinDebugToolTestBasicCheck (WinDebugToolTest ):
159
+
160
+ def windegtool_check_script_execution (self , test , params , env ):
161
+ if not self .vm :
162
+ self .vm = env .get_vm (params ["main_vm" ])
163
+ self .vm .verify_alive ()
164
+
165
+ session = self ._get_session (params , self .vm )
166
+ self ._open_session_list .append (session )
167
+ # Running the PowerShell script on the VM
168
+ include_sensitive_data = self .params .get ("include_sensitive_data" , False )
169
+ sensitive_data_flag = "-IncludeSensitiveData" if include_sensitive_data else ""
170
+
171
+ # Ensure the script runs with an unrestricted execution policy
172
+ cmd_unrestrict_policy = self .params ['cmd_unrestrict_policy' ]
173
+ session .cmd (cmd_unrestrict_policy )
174
+
175
+ # Execute the command on the VM
176
+ cmd_run_deg_tool = f"powershell { self .script_path } { sensitive_data_flag } "
177
+ session .cmd_status_output (cmd_run_deg_tool , timeout = 300 )
178
+ pass
179
+
180
+ def windegtool_check_zip_package (self , test , params , env ):
181
+ pass
182
+
183
+ def windegtool_check_run_tools_multi_times (self , test , params , env ):
184
+ pass
185
+
186
+ def windegtool_check_user_friendliness (self , test , params , env ):
187
+ pass
188
+
189
+ def windegtool_check_disk_registry_collection (self , test , param , env ):
190
+ pass
191
+
192
+ def windegtool_check_includeSensitiveData_collection (self , test , param , env ):
193
+ pass
194
+
195
+ def windegtool_check_trigger_driver_collection (self , test , param , env ):
196
+ pass
197
+
198
+ def windegtool_check_networkadapter_collection (self , test , param , env ):
199
+ pass
200
+
201
+ def windegtool_check_documentation (self , test , param , env ):
202
+ pass
203
+
204
+ def run_once (self , test , params , env ):
205
+ WinDebugToolTest .run_once (self , test , params , env )
206
+
207
+ windegtool_check_type = self .params ["windegtool_check_type" ]
208
+ chk_type = "windegtool_check_%s" % windegtool_check_type
209
+ if hasattr (self , chk_type ):
210
+ func = getattr (self , chk_type )
211
+ func (test , params , env )
212
+ else :
213
+ test .error ("Could not find matching test, check your config file" )
214
+
215
+
216
+ def run (test , params , env ):
217
+ """
218
+ Test CollectSystemInfo.ps1 tool, this case will:
219
+ 1) Start VM with virtio-win rpm package.
220
+ 2) Execute CollectSystemInfo.ps1 with&without param
221
+ '-IncludeSensitiveData'.
222
+ 3) Run some basic test for CollectSystemInfo.ps1.
223
+
224
+ :param test: kvm test object
225
+ :param params: Dictionary with the test parameters
226
+ :param env: Dictionary with test environmen.
227
+ """
228
+
229
+ collectinfotool_test = WinDebugToolTestBasicCheck (test , params , env )
230
+ collectinfotool_test .execute (test , params , env )
0 commit comments