5
5
import time
6
6
7
7
from avocado .utils import process
8
- from virttest import arch , error_context
8
+ from virttest import arch , error_context , env_process
9
9
from virttest import data_dir as virttest_data_dir
10
10
from virttest .utils_misc import get_linux_drive_path
11
11
@@ -27,12 +27,17 @@ def run(test, params, env):
27
27
:param env: Dictionary with test environment.
28
28
"""
29
29
30
- def _execute_io_in_guest ():
30
+ def _execute_io_in_guest (serial = None ):
31
31
devs = ""
32
- for serial in data_images :
32
+ if serial :
33
33
drive = get_linux_drive_path (session , serial )
34
34
if drive :
35
35
devs += drive .replace ("/dev/" , "" ) + " "
36
+ else :
37
+ for serial in data_images :
38
+ drive = get_linux_drive_path (session , serial )
39
+ if drive :
40
+ devs += drive .replace ("/dev/" , "" ) + " "
36
41
37
42
guest_io_cmd = params ["guest_io_cmd" ] % devs
38
43
host_script = params ["host_script" ]
@@ -43,40 +48,95 @@ def _execute_io_in_guest():
43
48
logger .info ("Execute io:%s" , guest_io_cmd )
44
49
session .sendline ("$SHELL " + guest_io_cmd )
45
50
51
+ def _get_scsi_debug_disk ():
52
+ output = process .system_output ("lsscsi -giss|grep scsi_debug" ,
53
+ shell = True ,
54
+ ignore_status = True ).decode ().strip ()
55
+ test .log .info ("Host cmd output '%s'" , output )
56
+ disk_info = []
57
+ if len (output ) < 10 :
58
+ test .log .warning ("Can not find scsi_debug disk" )
59
+ return
60
+
61
+ output = output .split ("\n " )
62
+ for disk in output :
63
+ info = disk .split ()
64
+ disk_dic = {"path" : info [5 ], "wwn" : info [6 ], "sg" : info [7 ],
65
+ "size" : info [8 ], "all" : disk }
66
+ disk_info .append (disk_dic )
67
+
68
+ test .log .info (disk_info )
69
+ return disk_info
70
+
46
71
if arch .ARCH in ("ppc64" , "ppc64le" ):
47
- output = process .system_output ("lscfg --list firmware -v" , shell = True ).decode ()
48
- ver = float (re .findall (r"\d\.\d" , output )[0 ])
72
+ out = process .system_output ("lscfg --list firmware -v" ,
73
+ shell = True ).decode ()
74
+ ver = float (re .findall (r"\d\.\d" , out )[0 ])
49
75
if ver >= 6.3 :
50
76
# bz2235228,cancel test due to known product bug.
51
77
test .cancel (
52
78
"Skip test for xive kvm interrupt guest due to"
53
79
" known host crash issue."
54
80
)
81
+
55
82
logger = test .log
56
- data_images = params ["data_images" ].split ()
57
- error_context .context ("Get the main VM" , logger .info )
58
- vm = env .get_vm (params ["main_vm" ])
59
- vm .verify_alive ()
60
-
61
- timeout = params .get_numeric ("login_timeout" , 360 )
62
- session = vm .wait_for_login (timeout = timeout )
63
- time .sleep (60 )
64
- logger .info ("Start to IO in guest" )
65
- _execute_io_in_guest ()
66
- logger .info ("Wait ..." )
67
- time .sleep (params .get_numeric ("io_timeout" , 300 ))
68
-
69
- logger .info ("Try to cancel IO." )
70
- session = vm .wait_for_login (timeout = timeout )
71
- session .cmd (params ["guest_cancel_io_cmd" ], timeout = timeout )
72
- logger .info ("Ready to destroy vm" )
73
- vm .destroy ()
74
- logger .info ("Ready to check vm..." )
75
- cp_cmd = "cp %s %s" % (params ["valgrind_log" ], test .logdir )
76
- process .system_output (cp_cmd , shell = True )
77
- check_cmd = params ["check_cmd" ]
78
- out = process .system_output (check_cmd , shell = True ).decode ()
79
- leak_threshold = params .get_numeric ("leak_threshold" )
80
- logger .info ("Find leak:%s,threshold: %d" , out , leak_threshold )
81
- if len (out ) and int (out ) > leak_threshold :
82
- test .fail ("Find memory leak %s,Please check valgrind.log" % out )
83
+
84
+ vm = None
85
+ disk_wwn = None
86
+ if params .get ("get_scsi_device" ) == "yes" :
87
+ scsi_debug_devs = _get_scsi_debug_disk ()
88
+ if scsi_debug_devs :
89
+ dev = scsi_debug_devs [0 ]
90
+ disk_wwn = dev ["wwn" ]
91
+ if params ["drive_format_stg1" ] == "scsi-generic" :
92
+ params ["image_name_stg1" ] = dev ["sg" ]
93
+ else :
94
+ params ["image_name_stg1" ] = dev ["path" ]
95
+ else :
96
+ test .fail ("Can not find scsi_debug devices" )
97
+ try :
98
+ if params .get ("not_preprocess" , "no" ) == "yes" :
99
+ logger .debug ("Ready boot VM : %s" , params ["images" ])
100
+ env_process .process (
101
+ test , params , env , env_process .preprocess_image ,
102
+ env_process .preprocess_vm
103
+ )
104
+
105
+ data_images = params ["data_images" ].split ()
106
+ error_context .context ("Get the main VM" , logger .info )
107
+ vm = env .get_vm (params ["main_vm" ])
108
+ vm .verify_alive ()
109
+
110
+ timeout = params .get_numeric ("login_timeout" , 360 )
111
+ session = vm .wait_for_login (timeout = timeout )
112
+ time .sleep (params .get_numeric ("vm_boot_timeout" , 60 ))
113
+ logger .info ("Start to IO in guest" )
114
+ _execute_io_in_guest (disk_wwn )
115
+ logger .info ("Wait ..." )
116
+ time .sleep (params .get_numeric ("io_timeout" , 300 ))
117
+
118
+ logger .info ("Try to cancel IO." )
119
+ session = vm .wait_for_login (timeout = timeout )
120
+ session .cmd (params ["guest_cancel_io_cmd" ], timeout = timeout )
121
+ logger .info ("Ready to destroy vm" )
122
+ vm .destroy ()
123
+ logger .info ("Ready to check vm..." )
124
+ cp_cmd = "cp %s %s" % (params ["valgrind_log" ], test .logdir )
125
+ process .system_output (cp_cmd , shell = True )
126
+ if params .get ("leak_check" , "yes" ) == "yes" :
127
+ check_cmd = params ["leak_check_cmd" ]
128
+ out = process .system_output (check_cmd , shell = True ).decode ()
129
+ leak_threshold = params .get_numeric ("leak_threshold" )
130
+ logger .info ("Find leak:%s,threshold: %d" , out , leak_threshold )
131
+ if len (out ) and int (out ) > leak_threshold :
132
+ test .fail ("Find memory leak %s,Please check valgrind.log" % out )
133
+
134
+ if params .get ("overflow_check" , "yes" ) == "yes" :
135
+ check_cmd = params ["overflow_check_cmd" ]
136
+ out = process .system_output (check_cmd , shell = True ,
137
+ ignore_status = True ).decode ()
138
+ if out and len (out ):
139
+ test .fail ("Find overflow %s,Please check valgrind.log" % out )
140
+ finally :
141
+ if vm and vm .is_alive ():
142
+ vm .destroy (gracefully = False )
0 commit comments