Index: client/tests/kvm/kvm_preprocessing.py |
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py |
index 1ddf99b90c121d7f86dd2c322741b681ee7b20ba..9c53f02d34cbc476ab442b7fa0a909c8457cd1ee 100644 |
--- a/client/tests/kvm/kvm_preprocessing.py |
+++ b/client/tests/kvm/kvm_preprocessing.py |
@@ -1,7 +1,7 @@ |
-import sys, os, time, commands, re, logging, signal, glob, threading, shutil |
-from autotest_lib.client.bin import test, utils |
+import os, time, commands, re, logging, glob, threading, shutil |
+from autotest_lib.client.bin import utils |
from autotest_lib.client.common_lib import error |
-import kvm_vm, kvm_utils, kvm_subprocess, kvm_monitor, ppm_utils |
+import kvm_vm, kvm_utils, kvm_subprocess, kvm_monitor, ppm_utils, test_setup |
try: |
import PIL.Image |
except ImportError: |
@@ -50,19 +50,20 @@ def preprocess_vm(test, params, env, name): |
@param name: The name of the VM object. |
""" |
logging.debug("Preprocessing VM '%s'..." % name) |
- vm = kvm_utils.env_get_vm(env, name) |
- if vm: |
- logging.debug("VM object found in environment") |
- else: |
+ vm = env.get_vm(name) |
+ if not vm: |
logging.debug("VM object does not exist; creating it") |
vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) |
- kvm_utils.env_register_vm(env, name, vm) |
+ env.register_vm(name, vm) |
start_vm = False |
if params.get("restart_vm") == "yes": |
logging.debug("'restart_vm' specified; (re)starting VM...") |
start_vm = True |
+ elif params.get("migration_mode"): |
+ logging.debug("Starting VM in incoming migration mode...") |
+ start_vm = True |
elif params.get("start_vm") == "yes": |
if not vm.is_alive(): |
logging.debug("VM is not alive; starting it...") |
@@ -75,8 +76,8 @@ def preprocess_vm(test, params, env, name): |
if start_vm: |
# Start the VM (or restart it if it's already up) |
- if not vm.create(name, params, test.bindir): |
- raise error.TestError("Could not start VM") |
+ vm.create(name, params, test.bindir, |
+ migration_mode=params.get("migration_mode")) |
else: |
# Don't start the VM, just update its params |
vm.params = params |
@@ -92,11 +93,12 @@ def preprocess_vm(test, params, env, name): |
def postprocess_image(test, params): |
""" |
Postprocess a single QEMU image according to the instructions in params. |
- Currently this function just removes an image if requested. |
@param test: An Autotest test object. |
@param params: A dict containing image postprocessing parameters. |
""" |
+ if params.get("check_image") == "yes": |
+ kvm_vm.check_image(params, test.bindir) |
if params.get("remove_image") == "yes": |
kvm_vm.remove_image(params, test.bindir) |
@@ -112,11 +114,8 @@ def postprocess_vm(test, params, env, name): |
@param name: The name of the VM object. |
""" |
logging.debug("Postprocessing VM '%s'..." % name) |
- vm = kvm_utils.env_get_vm(env, name) |
- if vm: |
- logging.debug("VM object found in environment") |
- else: |
- logging.debug("VM object does not exist in environment") |
+ vm = env.get_vm(name) |
+ if not vm: |
return |
scrdump_filename = os.path.join(test.debugdir, "post_%s.ppm" % name) |
@@ -173,19 +172,18 @@ def process(test, params, env, image_func, vm_func): |
@param vm_func: A function to call for each VM. |
""" |
# Get list of VMs specified for this test |
- vm_names = kvm_utils.get_sub_dict_names(params, "vms") |
- for vm_name in vm_names: |
- vm_params = kvm_utils.get_sub_dict(params, vm_name) |
+ for vm_name in params.objects("vms"): |
+ vm_params = params.object_params(vm_name) |
# Get list of images specified for this VM |
- image_names = kvm_utils.get_sub_dict_names(vm_params, "images") |
- for image_name in image_names: |
- image_params = kvm_utils.get_sub_dict(vm_params, image_name) |
+ for image_name in vm_params.objects("images"): |
+ image_params = vm_params.object_params(image_name) |
# Call image_func for each image |
image_func(test, image_params) |
# Call vm_func for each vm |
vm_func(test, vm_params, env, vm_name) |
+@error.context_aware |
def preprocess(test, params, env): |
""" |
Preprocess all VMs and images according to the instructions in params. |
@@ -195,6 +193,8 @@ def preprocess(test, params, env): |
@param params: A dict containing all VM and image parameters. |
@param env: The environment (a dict-like object). |
""" |
+ error.context("preprocessing") |
+ |
# Start tcpdump if it isn't already running |
if "address_cache" not in env: |
env["address_cache"] = {} |
@@ -204,7 +204,7 @@ def preprocess(test, params, env): |
if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes": |
cmd = "%s -npvi any 'dst port 68'" % kvm_utils.find_command("tcpdump") |
logging.debug("Starting tcpdump (%s)...", cmd) |
- env["tcpdump"] = kvm_subprocess.kvm_tail( |
+ env["tcpdump"] = kvm_subprocess.Tail( |
command=cmd, |
output_func=_update_address_cache, |
output_params=(env["address_cache"],)) |
@@ -216,7 +216,7 @@ def preprocess(test, params, env): |
env["tcpdump"].get_output())) |
# Destroy and remove VMs that are no longer needed in the environment |
- requested_vms = kvm_utils.get_sub_dict_names(params, "vms") |
+ requested_vms = params.objects("vms") |
for key in env.keys(): |
vm = env[key] |
if not kvm_utils.is_vm(vm): |
@@ -254,6 +254,18 @@ def preprocess(test, params, env): |
logging.debug("KVM userspace version: %s" % kvm_userspace_version) |
test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) |
+ if params.get("setup_hugepages") == "yes": |
+ h = test_setup.HugePageConfig(params) |
+ h.setup() |
+ |
+ if params.get("type") == "unattended_install": |
+ u = test_setup.UnattendedInstallConfig(test, params) |
+ u.setup() |
+ |
+ if params.get("type") == "enospc": |
+ e = test_setup.EnospcConfig(test, params) |
+ e.setup() |
+ |
# Execute any pre_commands |
if params.get("pre_command"): |
process_command(test, params, env, params.get("pre_command"), |
@@ -273,6 +285,7 @@ def preprocess(test, params, env): |
_screendump_thread.start() |
+@error.context_aware |
def postprocess(test, params, env): |
""" |
Postprocess all VMs and images according to the instructions in params. |
@@ -281,6 +294,8 @@ def postprocess(test, params, env): |
@param params: Dict containing all VM and image parameters. |
@param env: The environment (a dict-like object). |
""" |
+ error.context("postprocessing") |
+ |
# Postprocess all VMs and images |
process(test, params, env, postprocess_image, postprocess_vm) |
@@ -291,7 +306,6 @@ def postprocess(test, params, env): |
_screendump_thread_termination_event.set() |
_screendump_thread.join(10) |
_screendump_thread = None |
- _screendump_thread_termination_event = None |
# Warn about corrupt PPM files |
for f in glob.glob(os.path.join(test.debugdir, "*.ppm")): |
@@ -330,23 +344,32 @@ def postprocess(test, params, env): |
if params.get("kill_unresponsive_vms") == "yes": |
logging.debug("'kill_unresponsive_vms' specified; killing all VMs " |
"that fail to respond to a remote login request...") |
- for vm in kvm_utils.env_get_all_vms(env): |
+ for vm in env.get_all_vms(): |
if vm.is_alive(): |
- session = vm.remote_login() |
- if session: |
+ try: |
+ session = vm.login() |
session.close() |
- else: |
+ except (kvm_utils.LoginError, kvm_vm.VMError), e: |
+ logging.warn(e) |
vm.destroy(gracefully=False) |
# Kill all kvm_subprocess tail threads |
kvm_subprocess.kill_tail_threads() |
# Terminate tcpdump if no VMs are alive |
- living_vms = [vm for vm in kvm_utils.env_get_all_vms(env) if vm.is_alive()] |
+ living_vms = [vm for vm in env.get_all_vms() if vm.is_alive()] |
if not living_vms and "tcpdump" in env: |
env["tcpdump"].close() |
del env["tcpdump"] |
+ if params.get("setup_hugepages") == "yes": |
+ h = kvm_utils.HugePageConfig(params) |
+ h.cleanup() |
+ |
+ if params.get("type") == "enospc": |
+ e = test_setup.EnospcConfig(test, params) |
+ e.cleanup() |
+ |
# Execute any post_commands |
if params.get("post_command"): |
process_command(test, params, env, params.get("post_command"), |
@@ -362,7 +385,7 @@ def postprocess_on_error(test, params, env): |
@param params: A dict containing all VM and image parameters. |
@param env: The environment (a dict-like object). |
""" |
- params.update(kvm_utils.get_sub_dict(params, "on_error")) |
+ params.update(params.object_params("on_error")) |
def _update_address_cache(address_cache, line): |
@@ -374,9 +397,11 @@ def _update_address_cache(address_cache, line): |
matches = re.findall(r"\w*:\w*:\w*:\w*:\w*:\w*", line) |
if matches and address_cache.get("last_seen"): |
mac_address = matches[0].lower() |
- logging.debug("(address cache) Adding cache entry: %s ---> %s", |
- mac_address, address_cache.get("last_seen")) |
+ if time.time() - address_cache.get("time_%s" % mac_address, 0) > 5: |
+ logging.debug("(address cache) Adding cache entry: %s ---> %s", |
+ mac_address, address_cache.get("last_seen")) |
address_cache[mac_address] = address_cache.get("last_seen") |
+ address_cache["time_%s" % mac_address] = time.time() |
del address_cache["last_seen"] |
@@ -398,7 +423,7 @@ def _take_screendumps(test, params, env): |
cache = {} |
while True: |
- for vm in kvm_utils.env_get_all_vms(env): |
+ for vm in env.get_all_vms(): |
if not vm.is_alive(): |
continue |
try: |
@@ -437,5 +462,6 @@ def _take_screendumps(test, params, env): |
pass |
os.unlink(temp_filename) |
if _screendump_thread_termination_event.isSet(): |
+ _screendump_thread_termination_event = None |
break |
_screendump_thread_termination_event.wait(delay) |