OLD | NEW |
1 import sys, os, time, commands, re, logging, signal, glob, threading, shutil | 1 import os, time, commands, re, logging, glob, threading, shutil |
2 from autotest_lib.client.bin import test, utils | 2 from autotest_lib.client.bin import utils |
3 from autotest_lib.client.common_lib import error | 3 from autotest_lib.client.common_lib import error |
4 import kvm_vm, kvm_utils, kvm_subprocess, kvm_monitor, ppm_utils | 4 import kvm_vm, kvm_utils, kvm_subprocess, kvm_monitor, ppm_utils, test_setup |
5 try: | 5 try: |
6 import PIL.Image | 6 import PIL.Image |
7 except ImportError: | 7 except ImportError: |
8 logging.warning('No python imaging library installed. PPM image ' | 8 logging.warning('No python imaging library installed. PPM image ' |
9 'conversion to JPEG disabled. In order to enable it, ' | 9 'conversion to JPEG disabled. In order to enable it, ' |
10 'please install python-imaging or the equivalent for your ' | 10 'please install python-imaging or the equivalent for your ' |
11 'distro.') | 11 'distro.') |
12 | 12 |
13 | 13 |
14 _screendump_thread = None | 14 _screendump_thread = None |
(...skipping 28 matching lines...) Expand all Loading... |
43 """ | 43 """ |
44 Preprocess a single VM object according to the instructions in params. | 44 Preprocess a single VM object according to the instructions in params. |
45 Start the VM if requested and get a screendump. | 45 Start the VM if requested and get a screendump. |
46 | 46 |
47 @param test: An Autotest test object. | 47 @param test: An Autotest test object. |
48 @param params: A dict containing VM preprocessing parameters. | 48 @param params: A dict containing VM preprocessing parameters. |
49 @param env: The environment (a dict-like object). | 49 @param env: The environment (a dict-like object). |
50 @param name: The name of the VM object. | 50 @param name: The name of the VM object. |
51 """ | 51 """ |
52 logging.debug("Preprocessing VM '%s'..." % name) | 52 logging.debug("Preprocessing VM '%s'..." % name) |
53 vm = kvm_utils.env_get_vm(env, name) | 53 vm = env.get_vm(name) |
54 if vm: | 54 if not vm: |
55 logging.debug("VM object found in environment") | |
56 else: | |
57 logging.debug("VM object does not exist; creating it") | 55 logging.debug("VM object does not exist; creating it") |
58 vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) | 56 vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) |
59 kvm_utils.env_register_vm(env, name, vm) | 57 env.register_vm(name, vm) |
60 | 58 |
61 start_vm = False | 59 start_vm = False |
62 | 60 |
63 if params.get("restart_vm") == "yes": | 61 if params.get("restart_vm") == "yes": |
64 logging.debug("'restart_vm' specified; (re)starting VM...") | 62 logging.debug("'restart_vm' specified; (re)starting VM...") |
65 start_vm = True | 63 start_vm = True |
| 64 elif params.get("migration_mode"): |
| 65 logging.debug("Starting VM in incoming migration mode...") |
| 66 start_vm = True |
66 elif params.get("start_vm") == "yes": | 67 elif params.get("start_vm") == "yes": |
67 if not vm.is_alive(): | 68 if not vm.is_alive(): |
68 logging.debug("VM is not alive; starting it...") | 69 logging.debug("VM is not alive; starting it...") |
69 start_vm = True | 70 start_vm = True |
70 elif vm.make_qemu_command() != vm.make_qemu_command(name, params, | 71 elif vm.make_qemu_command() != vm.make_qemu_command(name, params, |
71 test.bindir): | 72 test.bindir): |
72 logging.debug("VM's qemu command differs from requested one; " | 73 logging.debug("VM's qemu command differs from requested one; " |
73 "restarting it...") | 74 "restarting it...") |
74 start_vm = True | 75 start_vm = True |
75 | 76 |
76 if start_vm: | 77 if start_vm: |
77 # Start the VM (or restart it if it's already up) | 78 # Start the VM (or restart it if it's already up) |
78 if not vm.create(name, params, test.bindir): | 79 vm.create(name, params, test.bindir, |
79 raise error.TestError("Could not start VM") | 80 migration_mode=params.get("migration_mode")) |
80 else: | 81 else: |
81 # Don't start the VM, just update its params | 82 # Don't start the VM, just update its params |
82 vm.params = params | 83 vm.params = params |
83 | 84 |
84 scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name) | 85 scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name) |
85 try: | 86 try: |
86 if vm.monitor: | 87 if vm.monitor: |
87 vm.monitor.screendump(scrdump_filename) | 88 vm.monitor.screendump(scrdump_filename) |
88 except kvm_monitor.MonitorError, e: | 89 except kvm_monitor.MonitorError, e: |
89 logging.warn(e) | 90 logging.warn(e) |
90 | 91 |
91 | 92 |
92 def postprocess_image(test, params): | 93 def postprocess_image(test, params): |
93 """ | 94 """ |
94 Postprocess a single QEMU image according to the instructions in params. | 95 Postprocess a single QEMU image according to the instructions in params. |
95 Currently this function just removes an image if requested. | |
96 | 96 |
97 @param test: An Autotest test object. | 97 @param test: An Autotest test object. |
98 @param params: A dict containing image postprocessing parameters. | 98 @param params: A dict containing image postprocessing parameters. |
99 """ | 99 """ |
| 100 if params.get("check_image") == "yes": |
| 101 kvm_vm.check_image(params, test.bindir) |
100 if params.get("remove_image") == "yes": | 102 if params.get("remove_image") == "yes": |
101 kvm_vm.remove_image(params, test.bindir) | 103 kvm_vm.remove_image(params, test.bindir) |
102 | 104 |
103 | 105 |
104 def postprocess_vm(test, params, env, name): | 106 def postprocess_vm(test, params, env, name): |
105 """ | 107 """ |
106 Postprocess a single VM object according to the instructions in params. | 108 Postprocess a single VM object according to the instructions in params. |
107 Kill the VM if requested and get a screendump. | 109 Kill the VM if requested and get a screendump. |
108 | 110 |
109 @param test: An Autotest test object. | 111 @param test: An Autotest test object. |
110 @param params: A dict containing VM postprocessing parameters. | 112 @param params: A dict containing VM postprocessing parameters. |
111 @param env: The environment (a dict-like object). | 113 @param env: The environment (a dict-like object). |
112 @param name: The name of the VM object. | 114 @param name: The name of the VM object. |
113 """ | 115 """ |
114 logging.debug("Postprocessing VM '%s'..." % name) | 116 logging.debug("Postprocessing VM '%s'..." % name) |
115 vm = kvm_utils.env_get_vm(env, name) | 117 vm = env.get_vm(name) |
116 if vm: | 118 if not vm: |
117 logging.debug("VM object found in environment") | |
118 else: | |
119 logging.debug("VM object does not exist in environment") | |
120 return | 119 return |
121 | 120 |
122 scrdump_filename = os.path.join(test.debugdir, "post_%s.ppm" % name) | 121 scrdump_filename = os.path.join(test.debugdir, "post_%s.ppm" % name) |
123 try: | 122 try: |
124 if vm.monitor: | 123 if vm.monitor: |
125 vm.monitor.screendump(scrdump_filename) | 124 vm.monitor.screendump(scrdump_filename) |
126 except kvm_monitor.MonitorError, e: | 125 except kvm_monitor.MonitorError, e: |
127 logging.warn(e) | 126 logging.warn(e) |
128 | 127 |
129 if params.get("kill_vm") == "yes": | 128 if params.get("kill_vm") == "yes": |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 Pre- or post-process VMs and images according to the instructions in params. | 165 Pre- or post-process VMs and images according to the instructions in params. |
167 Call image_func for each image listed in params and vm_func for each VM. | 166 Call image_func for each image listed in params and vm_func for each VM. |
168 | 167 |
169 @param test: An Autotest test object. | 168 @param test: An Autotest test object. |
170 @param params: A dict containing all VM and image parameters. | 169 @param params: A dict containing all VM and image parameters. |
171 @param env: The environment (a dict-like object). | 170 @param env: The environment (a dict-like object). |
172 @param image_func: A function to call for each image. | 171 @param image_func: A function to call for each image. |
173 @param vm_func: A function to call for each VM. | 172 @param vm_func: A function to call for each VM. |
174 """ | 173 """ |
175 # Get list of VMs specified for this test | 174 # Get list of VMs specified for this test |
176 vm_names = kvm_utils.get_sub_dict_names(params, "vms") | 175 for vm_name in params.objects("vms"): |
177 for vm_name in vm_names: | 176 vm_params = params.object_params(vm_name) |
178 vm_params = kvm_utils.get_sub_dict(params, vm_name) | |
179 # Get list of images specified for this VM | 177 # Get list of images specified for this VM |
180 image_names = kvm_utils.get_sub_dict_names(vm_params, "images") | 178 for image_name in vm_params.objects("images"): |
181 for image_name in image_names: | 179 image_params = vm_params.object_params(image_name) |
182 image_params = kvm_utils.get_sub_dict(vm_params, image_name) | |
183 # Call image_func for each image | 180 # Call image_func for each image |
184 image_func(test, image_params) | 181 image_func(test, image_params) |
185 # Call vm_func for each vm | 182 # Call vm_func for each vm |
186 vm_func(test, vm_params, env, vm_name) | 183 vm_func(test, vm_params, env, vm_name) |
187 | 184 |
188 | 185 |
| 186 @error.context_aware |
189 def preprocess(test, params, env): | 187 def preprocess(test, params, env): |
190 """ | 188 """ |
191 Preprocess all VMs and images according to the instructions in params. | 189 Preprocess all VMs and images according to the instructions in params. |
192 Also, collect some host information, such as the KVM version. | 190 Also, collect some host information, such as the KVM version. |
193 | 191 |
194 @param test: An Autotest test object. | 192 @param test: An Autotest test object. |
195 @param params: A dict containing all VM and image parameters. | 193 @param params: A dict containing all VM and image parameters. |
196 @param env: The environment (a dict-like object). | 194 @param env: The environment (a dict-like object). |
197 """ | 195 """ |
| 196 error.context("preprocessing") |
| 197 |
198 # Start tcpdump if it isn't already running | 198 # Start tcpdump if it isn't already running |
199 if "address_cache" not in env: | 199 if "address_cache" not in env: |
200 env["address_cache"] = {} | 200 env["address_cache"] = {} |
201 if "tcpdump" in env and not env["tcpdump"].is_alive(): | 201 if "tcpdump" in env and not env["tcpdump"].is_alive(): |
202 env["tcpdump"].close() | 202 env["tcpdump"].close() |
203 del env["tcpdump"] | 203 del env["tcpdump"] |
204 if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes": | 204 if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes": |
205 cmd = "%s -npvi any 'dst port 68'" % kvm_utils.find_command("tcpdump") | 205 cmd = "%s -npvi any 'dst port 68'" % kvm_utils.find_command("tcpdump") |
206 logging.debug("Starting tcpdump (%s)...", cmd) | 206 logging.debug("Starting tcpdump (%s)...", cmd) |
207 env["tcpdump"] = kvm_subprocess.kvm_tail( | 207 env["tcpdump"] = kvm_subprocess.Tail( |
208 command=cmd, | 208 command=cmd, |
209 output_func=_update_address_cache, | 209 output_func=_update_address_cache, |
210 output_params=(env["address_cache"],)) | 210 output_params=(env["address_cache"],)) |
211 if kvm_utils.wait_for(lambda: not env["tcpdump"].is_alive(), | 211 if kvm_utils.wait_for(lambda: not env["tcpdump"].is_alive(), |
212 0.1, 0.1, 1.0): | 212 0.1, 0.1, 1.0): |
213 logging.warn("Could not start tcpdump") | 213 logging.warn("Could not start tcpdump") |
214 logging.warn("Status: %s" % env["tcpdump"].get_status()) | 214 logging.warn("Status: %s" % env["tcpdump"].get_status()) |
215 logging.warn("Output:" + kvm_utils.format_str_for_message( | 215 logging.warn("Output:" + kvm_utils.format_str_for_message( |
216 env["tcpdump"].get_output())) | 216 env["tcpdump"].get_output())) |
217 | 217 |
218 # Destroy and remove VMs that are no longer needed in the environment | 218 # Destroy and remove VMs that are no longer needed in the environment |
219 requested_vms = kvm_utils.get_sub_dict_names(params, "vms") | 219 requested_vms = params.objects("vms") |
220 for key in env.keys(): | 220 for key in env.keys(): |
221 vm = env[key] | 221 vm = env[key] |
222 if not kvm_utils.is_vm(vm): | 222 if not kvm_utils.is_vm(vm): |
223 continue | 223 continue |
224 if not vm.name in requested_vms: | 224 if not vm.name in requested_vms: |
225 logging.debug("VM '%s' found in environment but not required for " | 225 logging.debug("VM '%s' found in environment but not required for " |
226 "test; removing it..." % vm.name) | 226 "test; removing it..." % vm.name) |
227 vm.destroy() | 227 vm.destroy() |
228 del env[key] | 228 del env[key] |
229 | 229 |
(...skipping 17 matching lines...) Expand all Loading... |
247 version_line = commands.getoutput("%s -help | head -n 1" % qemu_path) | 247 version_line = commands.getoutput("%s -help | head -n 1" % qemu_path) |
248 matches = re.findall("[Vv]ersion .*?,", version_line) | 248 matches = re.findall("[Vv]ersion .*?,", version_line) |
249 if matches: | 249 if matches: |
250 kvm_userspace_version = " ".join(matches[0].split()[1:]).strip(",") | 250 kvm_userspace_version = " ".join(matches[0].split()[1:]).strip(",") |
251 else: | 251 else: |
252 kvm_userspace_version = "Unknown" | 252 kvm_userspace_version = "Unknown" |
253 logging.debug("Could not fetch KVM userspace version") | 253 logging.debug("Could not fetch KVM userspace version") |
254 logging.debug("KVM userspace version: %s" % kvm_userspace_version) | 254 logging.debug("KVM userspace version: %s" % kvm_userspace_version) |
255 test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) | 255 test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) |
256 | 256 |
| 257 if params.get("setup_hugepages") == "yes": |
| 258 h = test_setup.HugePageConfig(params) |
| 259 h.setup() |
| 260 |
| 261 if params.get("type") == "unattended_install": |
| 262 u = test_setup.UnattendedInstallConfig(test, params) |
| 263 u.setup() |
| 264 |
| 265 if params.get("type") == "enospc": |
| 266 e = test_setup.EnospcConfig(test, params) |
| 267 e.setup() |
| 268 |
257 # Execute any pre_commands | 269 # Execute any pre_commands |
258 if params.get("pre_command"): | 270 if params.get("pre_command"): |
259 process_command(test, params, env, params.get("pre_command"), | 271 process_command(test, params, env, params.get("pre_command"), |
260 int(params.get("pre_command_timeout", "600")), | 272 int(params.get("pre_command_timeout", "600")), |
261 params.get("pre_command_noncritical") == "yes") | 273 params.get("pre_command_noncritical") == "yes") |
262 | 274 |
263 # Preprocess all VMs and images | 275 # Preprocess all VMs and images |
264 process(test, params, env, preprocess_image, preprocess_vm) | 276 process(test, params, env, preprocess_image, preprocess_vm) |
265 | 277 |
266 # Start the screendump thread | 278 # Start the screendump thread |
267 if params.get("take_regular_screendumps") == "yes": | 279 if params.get("take_regular_screendumps") == "yes": |
268 logging.debug("Starting screendump thread") | 280 logging.debug("Starting screendump thread") |
269 global _screendump_thread, _screendump_thread_termination_event | 281 global _screendump_thread, _screendump_thread_termination_event |
270 _screendump_thread_termination_event = threading.Event() | 282 _screendump_thread_termination_event = threading.Event() |
271 _screendump_thread = threading.Thread(target=_take_screendumps, | 283 _screendump_thread = threading.Thread(target=_take_screendumps, |
272 args=(test, params, env)) | 284 args=(test, params, env)) |
273 _screendump_thread.start() | 285 _screendump_thread.start() |
274 | 286 |
275 | 287 |
| 288 @error.context_aware |
276 def postprocess(test, params, env): | 289 def postprocess(test, params, env): |
277 """ | 290 """ |
278 Postprocess all VMs and images according to the instructions in params. | 291 Postprocess all VMs and images according to the instructions in params. |
279 | 292 |
280 @param test: An Autotest test object. | 293 @param test: An Autotest test object. |
281 @param params: Dict containing all VM and image parameters. | 294 @param params: Dict containing all VM and image parameters. |
282 @param env: The environment (a dict-like object). | 295 @param env: The environment (a dict-like object). |
283 """ | 296 """ |
| 297 error.context("postprocessing") |
| 298 |
284 # Postprocess all VMs and images | 299 # Postprocess all VMs and images |
285 process(test, params, env, postprocess_image, postprocess_vm) | 300 process(test, params, env, postprocess_image, postprocess_vm) |
286 | 301 |
287 # Terminate the screendump thread | 302 # Terminate the screendump thread |
288 global _screendump_thread, _screendump_thread_termination_event | 303 global _screendump_thread, _screendump_thread_termination_event |
289 if _screendump_thread: | 304 if _screendump_thread: |
290 logging.debug("Terminating screendump thread...") | 305 logging.debug("Terminating screendump thread...") |
291 _screendump_thread_termination_event.set() | 306 _screendump_thread_termination_event.set() |
292 _screendump_thread.join(10) | 307 _screendump_thread.join(10) |
293 _screendump_thread = None | 308 _screendump_thread = None |
294 _screendump_thread_termination_event = None | |
295 | 309 |
296 # Warn about corrupt PPM files | 310 # Warn about corrupt PPM files |
297 for f in glob.glob(os.path.join(test.debugdir, "*.ppm")): | 311 for f in glob.glob(os.path.join(test.debugdir, "*.ppm")): |
298 if not ppm_utils.image_verify_ppm_file(f): | 312 if not ppm_utils.image_verify_ppm_file(f): |
299 logging.warn("Found corrupt PPM file: %s", f) | 313 logging.warn("Found corrupt PPM file: %s", f) |
300 | 314 |
301 # Should we convert PPM files to PNG format? | 315 # Should we convert PPM files to PNG format? |
302 if params.get("convert_ppm_files_to_png") == "yes": | 316 if params.get("convert_ppm_files_to_png") == "yes": |
303 logging.debug("'convert_ppm_files_to_png' specified; converting PPM " | 317 logging.debug("'convert_ppm_files_to_png' specified; converting PPM " |
304 "files to PNG format...") | 318 "files to PNG format...") |
(...skipping 18 matching lines...) Expand all Loading... |
323 logging.debug("'keep_screendumps' not specified; removing screendump " | 337 logging.debug("'keep_screendumps' not specified; removing screendump " |
324 "dirs...") | 338 "dirs...") |
325 for d in glob.glob(os.path.join(test.debugdir, "screendumps_*")): | 339 for d in glob.glob(os.path.join(test.debugdir, "screendumps_*")): |
326 if os.path.isdir(d) and not os.path.islink(d): | 340 if os.path.isdir(d) and not os.path.islink(d): |
327 shutil.rmtree(d, ignore_errors=True) | 341 shutil.rmtree(d, ignore_errors=True) |
328 | 342 |
329 # Kill all unresponsive VMs | 343 # Kill all unresponsive VMs |
330 if params.get("kill_unresponsive_vms") == "yes": | 344 if params.get("kill_unresponsive_vms") == "yes": |
331 logging.debug("'kill_unresponsive_vms' specified; killing all VMs " | 345 logging.debug("'kill_unresponsive_vms' specified; killing all VMs " |
332 "that fail to respond to a remote login request...") | 346 "that fail to respond to a remote login request...") |
333 for vm in kvm_utils.env_get_all_vms(env): | 347 for vm in env.get_all_vms(): |
334 if vm.is_alive(): | 348 if vm.is_alive(): |
335 session = vm.remote_login() | 349 try: |
336 if session: | 350 session = vm.login() |
337 session.close() | 351 session.close() |
338 else: | 352 except (kvm_utils.LoginError, kvm_vm.VMError), e: |
| 353 logging.warn(e) |
339 vm.destroy(gracefully=False) | 354 vm.destroy(gracefully=False) |
340 | 355 |
341 # Kill all kvm_subprocess tail threads | 356 # Kill all kvm_subprocess tail threads |
342 kvm_subprocess.kill_tail_threads() | 357 kvm_subprocess.kill_tail_threads() |
343 | 358 |
344 # Terminate tcpdump if no VMs are alive | 359 # Terminate tcpdump if no VMs are alive |
345 living_vms = [vm for vm in kvm_utils.env_get_all_vms(env) if vm.is_alive()] | 360 living_vms = [vm for vm in env.get_all_vms() if vm.is_alive()] |
346 if not living_vms and "tcpdump" in env: | 361 if not living_vms and "tcpdump" in env: |
347 env["tcpdump"].close() | 362 env["tcpdump"].close() |
348 del env["tcpdump"] | 363 del env["tcpdump"] |
349 | 364 |
| 365 if params.get("setup_hugepages") == "yes": |
| 366 h = kvm_utils.HugePageConfig(params) |
| 367 h.cleanup() |
| 368 |
| 369 if params.get("type") == "enospc": |
| 370 e = test_setup.EnospcConfig(test, params) |
| 371 e.cleanup() |
| 372 |
350 # Execute any post_commands | 373 # Execute any post_commands |
351 if params.get("post_command"): | 374 if params.get("post_command"): |
352 process_command(test, params, env, params.get("post_command"), | 375 process_command(test, params, env, params.get("post_command"), |
353 int(params.get("post_command_timeout", "600")), | 376 int(params.get("post_command_timeout", "600")), |
354 params.get("post_command_noncritical") == "yes") | 377 params.get("post_command_noncritical") == "yes") |
355 | 378 |
356 | 379 |
357 def postprocess_on_error(test, params, env): | 380 def postprocess_on_error(test, params, env): |
358 """ | 381 """ |
359 Perform postprocessing operations required only if the test failed. | 382 Perform postprocessing operations required only if the test failed. |
360 | 383 |
361 @param test: An Autotest test object. | 384 @param test: An Autotest test object. |
362 @param params: A dict containing all VM and image parameters. | 385 @param params: A dict containing all VM and image parameters. |
363 @param env: The environment (a dict-like object). | 386 @param env: The environment (a dict-like object). |
364 """ | 387 """ |
365 params.update(kvm_utils.get_sub_dict(params, "on_error")) | 388 params.update(params.object_params("on_error")) |
366 | 389 |
367 | 390 |
368 def _update_address_cache(address_cache, line): | 391 def _update_address_cache(address_cache, line): |
369 if re.search("Your.IP", line, re.IGNORECASE): | 392 if re.search("Your.IP", line, re.IGNORECASE): |
370 matches = re.findall(r"\d*\.\d*\.\d*\.\d*", line) | 393 matches = re.findall(r"\d*\.\d*\.\d*\.\d*", line) |
371 if matches: | 394 if matches: |
372 address_cache["last_seen"] = matches[0] | 395 address_cache["last_seen"] = matches[0] |
373 if re.search("Client.Ethernet.Address", line, re.IGNORECASE): | 396 if re.search("Client.Ethernet.Address", line, re.IGNORECASE): |
374 matches = re.findall(r"\w*:\w*:\w*:\w*:\w*:\w*", line) | 397 matches = re.findall(r"\w*:\w*:\w*:\w*:\w*:\w*", line) |
375 if matches and address_cache.get("last_seen"): | 398 if matches and address_cache.get("last_seen"): |
376 mac_address = matches[0].lower() | 399 mac_address = matches[0].lower() |
377 logging.debug("(address cache) Adding cache entry: %s ---> %s", | 400 if time.time() - address_cache.get("time_%s" % mac_address, 0) > 5: |
378 mac_address, address_cache.get("last_seen")) | 401 logging.debug("(address cache) Adding cache entry: %s ---> %s", |
| 402 mac_address, address_cache.get("last_seen")) |
379 address_cache[mac_address] = address_cache.get("last_seen") | 403 address_cache[mac_address] = address_cache.get("last_seen") |
| 404 address_cache["time_%s" % mac_address] = time.time() |
380 del address_cache["last_seen"] | 405 del address_cache["last_seen"] |
381 | 406 |
382 | 407 |
383 def _take_screendumps(test, params, env): | 408 def _take_screendumps(test, params, env): |
384 global _screendump_thread_termination_event | 409 global _screendump_thread_termination_event |
385 temp_dir = test.debugdir | 410 temp_dir = test.debugdir |
386 if params.get("screendump_temp_dir"): | 411 if params.get("screendump_temp_dir"): |
387 temp_dir = kvm_utils.get_path(test.bindir, | 412 temp_dir = kvm_utils.get_path(test.bindir, |
388 params.get("screendump_temp_dir")) | 413 params.get("screendump_temp_dir")) |
389 try: | 414 try: |
390 os.makedirs(temp_dir) | 415 os.makedirs(temp_dir) |
391 except OSError: | 416 except OSError: |
392 pass | 417 pass |
393 temp_filename = os.path.join(temp_dir, "scrdump-%s.ppm" % | 418 temp_filename = os.path.join(temp_dir, "scrdump-%s.ppm" % |
394 kvm_utils.generate_random_string(6)) | 419 kvm_utils.generate_random_string(6)) |
395 delay = float(params.get("screendump_delay", 5)) | 420 delay = float(params.get("screendump_delay", 5)) |
396 quality = int(params.get("screendump_quality", 30)) | 421 quality = int(params.get("screendump_quality", 30)) |
397 | 422 |
398 cache = {} | 423 cache = {} |
399 | 424 |
400 while True: | 425 while True: |
401 for vm in kvm_utils.env_get_all_vms(env): | 426 for vm in env.get_all_vms(): |
402 if not vm.is_alive(): | 427 if not vm.is_alive(): |
403 continue | 428 continue |
404 try: | 429 try: |
405 vm.monitor.screendump(temp_filename) | 430 vm.monitor.screendump(temp_filename) |
406 except kvm_monitor.MonitorError, e: | 431 except kvm_monitor.MonitorError, e: |
407 logging.warn(e) | 432 logging.warn(e) |
408 continue | 433 continue |
409 if not os.path.exists(temp_filename): | 434 if not os.path.exists(temp_filename): |
410 logging.warn("VM '%s' failed to produce a screendump", vm.name) | 435 logging.warn("VM '%s' failed to produce a screendump", vm.name) |
411 continue | 436 continue |
(...skipping 18 matching lines...) Expand all Loading... |
430 pass | 455 pass |
431 else: | 456 else: |
432 try: | 457 try: |
433 image = PIL.Image.open(temp_filename) | 458 image = PIL.Image.open(temp_filename) |
434 image.save(screendump_filename, format="JPEG", quality=quali
ty) | 459 image.save(screendump_filename, format="JPEG", quality=quali
ty) |
435 cache[hash] = screendump_filename | 460 cache[hash] = screendump_filename |
436 except NameError: | 461 except NameError: |
437 pass | 462 pass |
438 os.unlink(temp_filename) | 463 os.unlink(temp_filename) |
439 if _screendump_thread_termination_event.isSet(): | 464 if _screendump_thread_termination_event.isSet(): |
| 465 _screendump_thread_termination_event = None |
440 break | 466 break |
441 _screendump_thread_termination_event.wait(delay) | 467 _screendump_thread_termination_event.wait(delay) |
OLD | NEW |