| OLD | NEW |
| 1 import os, time, commands, re, logging, glob, threading, shutil | 1 import os, time, commands, re, logging, glob, threading, shutil |
| 2 from autotest_lib.client.bin import 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, test_setup | 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 ' |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 # Start the VM (or restart it if it's already up) | 78 # Start the VM (or restart it if it's already up) |
| 79 vm.create(name, params, test.bindir, | 79 vm.create(name, params, test.bindir, |
| 80 migration_mode=params.get("migration_mode")) | 80 migration_mode=params.get("migration_mode")) |
| 81 else: | 81 else: |
| 82 # Don't start the VM, just update its params | 82 # Don't start the VM, just update its params |
| 83 vm.params = params | 83 vm.params = params |
| 84 | 84 |
| 85 scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name) | 85 scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name) |
| 86 try: | 86 try: |
| 87 if vm.monitor: | 87 if vm.monitor: |
| 88 vm.monitor.screendump(scrdump_filename) | 88 vm.monitor.screendump(scrdump_filename, debug=False) |
| 89 except kvm_monitor.MonitorError, e: | 89 except kvm_monitor.MonitorError, e: |
| 90 logging.warn(e) | 90 logging.warn(e) |
| 91 | 91 |
| 92 | 92 |
| 93 def postprocess_image(test, params): | 93 def postprocess_image(test, params): |
| 94 """ | 94 """ |
| 95 Postprocess a single QEMU image according to the instructions in params. | 95 Postprocess a single QEMU image according to the instructions in params. |
| 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. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 114 @param name: The name of the VM object. | 114 @param name: The name of the VM object. |
| 115 """ | 115 """ |
| 116 logging.debug("Postprocessing VM '%s'..." % name) | 116 logging.debug("Postprocessing VM '%s'..." % name) |
| 117 vm = env.get_vm(name) | 117 vm = env.get_vm(name) |
| 118 if not vm: | 118 if not vm: |
| 119 return | 119 return |
| 120 | 120 |
| 121 scrdump_filename = os.path.join(test.debugdir, "post_%s.ppm" % name) | 121 scrdump_filename = os.path.join(test.debugdir, "post_%s.ppm" % name) |
| 122 try: | 122 try: |
| 123 if vm.monitor: | 123 if vm.monitor: |
| 124 vm.monitor.screendump(scrdump_filename) | 124 vm.monitor.screendump(scrdump_filename, debug=False) |
| 125 except kvm_monitor.MonitorError, e: | 125 except kvm_monitor.MonitorError, e: |
| 126 logging.warn(e) | 126 logging.warn(e) |
| 127 | 127 |
| 128 if params.get("kill_vm") == "yes": | 128 if params.get("kill_vm") == "yes": |
| 129 kill_vm_timeout = float(params.get("kill_vm_timeout", 0)) | 129 kill_vm_timeout = float(params.get("kill_vm_timeout", 0)) |
| 130 if kill_vm_timeout: | 130 if kill_vm_timeout: |
| 131 logging.debug("'kill_vm' specified; waiting for VM to shut down " | 131 logging.debug("'kill_vm' specified; waiting for VM to shut down " |
| 132 "before killing it...") | 132 "before killing it...") |
| 133 kvm_utils.wait_for(vm.is_dead, kill_vm_timeout, 0, 1) | 133 kvm_utils.wait_for(vm.is_dead, kill_vm_timeout, 0, 1) |
| 134 else: | 134 else: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 def preprocess(test, params, env): | 187 def preprocess(test, params, env): |
| 188 """ | 188 """ |
| 189 Preprocess all VMs and images according to the instructions in params. | 189 Preprocess all VMs and images according to the instructions in params. |
| 190 Also, collect some host information, such as the KVM version. | 190 Also, collect some host information, such as the KVM version. |
| 191 | 191 |
| 192 @param test: An Autotest test object. | 192 @param test: An Autotest test object. |
| 193 @param params: A dict containing all VM and image parameters. | 193 @param params: A dict containing all VM and image parameters. |
| 194 @param env: The environment (a dict-like object). | 194 @param env: The environment (a dict-like object). |
| 195 """ | 195 """ |
| 196 error.context("preprocessing") | 196 error.context("preprocessing") |
| 197 | |
| 198 # Start tcpdump if it isn't already running | 197 # Start tcpdump if it isn't already running |
| 199 if "address_cache" not in env: | 198 if "address_cache" not in env: |
| 200 env["address_cache"] = {} | 199 env["address_cache"] = {} |
| 201 if "tcpdump" in env and not env["tcpdump"].is_alive(): | 200 if "tcpdump" in env and not env["tcpdump"].is_alive(): |
| 202 env["tcpdump"].close() | 201 env["tcpdump"].close() |
| 203 del env["tcpdump"] | 202 del env["tcpdump"] |
| 204 if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes": | 203 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") | 204 cmd = "%s -npvi any 'dst port 68'" % kvm_utils.find_command("tcpdump") |
| 206 logging.debug("Starting tcpdump (%s)...", cmd) | 205 logging.debug("Starting tcpdump (%s)...", cmd) |
| 207 env["tcpdump"] = kvm_subprocess.Tail( | 206 env["tcpdump"] = kvm_subprocess.Tail( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 else: | 250 else: |
| 252 kvm_userspace_version = "Unknown" | 251 kvm_userspace_version = "Unknown" |
| 253 logging.debug("Could not fetch KVM userspace version") | 252 logging.debug("Could not fetch KVM userspace version") |
| 254 logging.debug("KVM userspace version: %s" % kvm_userspace_version) | 253 logging.debug("KVM userspace version: %s" % kvm_userspace_version) |
| 255 test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) | 254 test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) |
| 256 | 255 |
| 257 if params.get("setup_hugepages") == "yes": | 256 if params.get("setup_hugepages") == "yes": |
| 258 h = test_setup.HugePageConfig(params) | 257 h = test_setup.HugePageConfig(params) |
| 259 h.setup() | 258 h.setup() |
| 260 | 259 |
| 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 | |
| 269 # Execute any pre_commands | 260 # Execute any pre_commands |
| 270 if params.get("pre_command"): | 261 if params.get("pre_command"): |
| 271 process_command(test, params, env, params.get("pre_command"), | 262 process_command(test, params, env, params.get("pre_command"), |
| 272 int(params.get("pre_command_timeout", "600")), | 263 int(params.get("pre_command_timeout", "600")), |
| 273 params.get("pre_command_noncritical") == "yes") | 264 params.get("pre_command_noncritical") == "yes") |
| 274 | 265 |
| 275 # Preprocess all VMs and images | 266 # Preprocess all VMs and images |
| 276 process(test, params, env, preprocess_image, preprocess_vm) | 267 process(test, params, env, preprocess_image, preprocess_vm) |
| 277 | 268 |
| 278 # Start the screendump thread | 269 # Start the screendump thread |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 # Terminate tcpdump if no VMs are alive | 350 # Terminate tcpdump if no VMs are alive |
| 360 living_vms = [vm for vm in env.get_all_vms() if vm.is_alive()] | 351 living_vms = [vm for vm in env.get_all_vms() if vm.is_alive()] |
| 361 if not living_vms and "tcpdump" in env: | 352 if not living_vms and "tcpdump" in env: |
| 362 env["tcpdump"].close() | 353 env["tcpdump"].close() |
| 363 del env["tcpdump"] | 354 del env["tcpdump"] |
| 364 | 355 |
| 365 if params.get("setup_hugepages") == "yes": | 356 if params.get("setup_hugepages") == "yes": |
| 366 h = test_setup.HugePageConfig(params) | 357 h = test_setup.HugePageConfig(params) |
| 367 h.cleanup() | 358 h.cleanup() |
| 368 | 359 |
| 369 if params.get("type") == "enospc": | |
| 370 e = test_setup.EnospcConfig(test, params) | |
| 371 e.cleanup() | |
| 372 | |
| 373 # Execute any post_commands | 360 # Execute any post_commands |
| 374 if params.get("post_command"): | 361 if params.get("post_command"): |
| 375 process_command(test, params, env, params.get("post_command"), | 362 process_command(test, params, env, params.get("post_command"), |
| 376 int(params.get("post_command_timeout", "600")), | 363 int(params.get("post_command_timeout", "600")), |
| 377 params.get("post_command_noncritical") == "yes") | 364 params.get("post_command_noncritical") == "yes") |
| 378 | 365 |
| 379 | 366 |
| 380 def postprocess_on_error(test, params, env): | 367 def postprocess_on_error(test, params, env): |
| 381 """ | 368 """ |
| 382 Perform postprocessing operations required only if the test failed. | 369 Perform postprocessing operations required only if the test failed. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 delay = float(params.get("screendump_delay", 5)) | 407 delay = float(params.get("screendump_delay", 5)) |
| 421 quality = int(params.get("screendump_quality", 30)) | 408 quality = int(params.get("screendump_quality", 30)) |
| 422 | 409 |
| 423 cache = {} | 410 cache = {} |
| 424 | 411 |
| 425 while True: | 412 while True: |
| 426 for vm in env.get_all_vms(): | 413 for vm in env.get_all_vms(): |
| 427 if not vm.is_alive(): | 414 if not vm.is_alive(): |
| 428 continue | 415 continue |
| 429 try: | 416 try: |
| 430 vm.monitor.screendump(temp_filename) | 417 vm.monitor.screendump(filename=temp_filename, debug=False) |
| 431 except kvm_monitor.MonitorError, e: | 418 except kvm_monitor.MonitorError, e: |
| 432 logging.warn(e) | 419 logging.warn(e) |
| 433 continue | 420 continue |
| 434 if not os.path.exists(temp_filename): | 421 if not os.path.exists(temp_filename): |
| 435 logging.warn("VM '%s' failed to produce a screendump", vm.name) | 422 logging.warn("VM '%s' failed to produce a screendump", vm.name) |
| 436 continue | 423 continue |
| 437 if not ppm_utils.image_verify_ppm_file(temp_filename): | 424 if not ppm_utils.image_verify_ppm_file(temp_filename): |
| 438 logging.warn("VM '%s' produced an invalid screendump", vm.name) | 425 logging.warn("VM '%s' produced an invalid screendump", vm.name) |
| 439 os.unlink(temp_filename) | 426 os.unlink(temp_filename) |
| 440 continue | 427 continue |
| (...skipping 17 matching lines...) Expand all Loading... |
| 458 image = PIL.Image.open(temp_filename) | 445 image = PIL.Image.open(temp_filename) |
| 459 image.save(screendump_filename, format="JPEG", quality=quali
ty) | 446 image.save(screendump_filename, format="JPEG", quality=quali
ty) |
| 460 cache[hash] = screendump_filename | 447 cache[hash] = screendump_filename |
| 461 except NameError: | 448 except NameError: |
| 462 pass | 449 pass |
| 463 os.unlink(temp_filename) | 450 os.unlink(temp_filename) |
| 464 if _screendump_thread_termination_event.isSet(): | 451 if _screendump_thread_termination_event.isSet(): |
| 465 _screendump_thread_termination_event = None | 452 _screendump_thread_termination_event = None |
| 466 break | 453 break |
| 467 _screendump_thread_termination_event.wait(delay) | 454 _screendump_thread_termination_event.wait(delay) |
| OLD | NEW |