Index: client/virt/virt_env_process.py |
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/virt/virt_env_process.py |
similarity index 92% |
rename from client/tests/kvm/kvm_preprocessing.py |
rename to client/virt/virt_env_process.py |
index f679be04ede37eb70b64eedd90d8c7a084f4e596..625b42259366d5f9d38f32201fb96de5fc5934e4 100644 |
--- a/client/tests/kvm/kvm_preprocessing.py |
+++ b/client/virt/virt_env_process.py |
@@ -1,7 +1,8 @@ |
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, test_setup |
+import aexpect, virt_utils, kvm_monitor, ppm_utils, virt_test_setup |
+import virt_vm, kvm_vm |
try: |
import PIL.Image |
except ImportError: |
@@ -23,7 +24,7 @@ def preprocess_image(test, params): |
@param params: A dict containing image preprocessing parameters. |
@note: Currently this function just creates an image if requested. |
""" |
- image_filename = kvm_vm.get_image_filename(params, test.bindir) |
+ image_filename = virt_vm.get_image_filename(params, test.bindir) |
create_image = False |
@@ -35,7 +36,7 @@ def preprocess_image(test, params): |
logging.debug("Creating image...") |
create_image = True |
- if create_image and not kvm_vm.create_image(params, test.bindir): |
+ if create_image and not virt_vm.create_image(params, test.bindir): |
raise error.TestError("Could not create image") |
@@ -53,7 +54,9 @@ def preprocess_vm(test, params, env, name): |
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")) |
+ vm_type = params.get('vm_type') |
+ if vm_type == 'kvm': |
+ vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) |
env.register_vm(name, vm) |
start_vm = False |
@@ -68,9 +71,8 @@ def preprocess_vm(test, params, env, name): |
if not vm.is_alive(): |
logging.debug("VM is not alive; starting it...") |
start_vm = True |
- elif vm.make_qemu_command() != vm.make_qemu_command(name, params, |
- test.bindir): |
- logging.debug("VM's qemu command differs from requested one; " |
+ if vm.needs_restart(name=name, params=params, basedir=test.bindir): |
+ logging.debug("Current VM specs differ from requested one; " |
"restarting it...") |
start_vm = True |
@@ -98,9 +100,9 @@ def postprocess_image(test, params): |
@param params: A dict containing image postprocessing parameters. |
""" |
if params.get("check_image") == "yes": |
- kvm_vm.check_image(params, test.bindir) |
+ virt_vm.check_image(params, test.bindir) |
if params.get("remove_image") == "yes": |
- kvm_vm.remove_image(params, test.bindir) |
+ virt_vm.remove_image(params, test.bindir) |
def postprocess_vm(test, params, env, name): |
@@ -130,7 +132,7 @@ def postprocess_vm(test, params, env, name): |
if kill_vm_timeout: |
logging.debug("'kill_vm' specified; waiting for VM to shut down " |
"before killing it...") |
- kvm_utils.wait_for(vm.is_dead, kill_vm_timeout, 0, 1) |
+ virt_utils.wait_for(vm.is_dead, kill_vm_timeout, 0, 1) |
else: |
logging.debug("'kill_vm' specified; killing VM...") |
vm.destroy(gracefully = params.get("kill_vm_gracefully") == "yes") |
@@ -201,24 +203,24 @@ def preprocess(test, params, env): |
env["tcpdump"].close() |
del env["tcpdump"] |
if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes": |
- cmd = "%s -npvi any 'dst port 68'" % kvm_utils.find_command("tcpdump") |
+ cmd = "%s -npvi any 'dst port 68'" % virt_utils.find_command("tcpdump") |
logging.debug("Starting tcpdump (%s)...", cmd) |
- env["tcpdump"] = kvm_subprocess.Tail( |
+ env["tcpdump"] = aexpect.Tail( |
command=cmd, |
output_func=_update_address_cache, |
output_params=(env["address_cache"],)) |
- if kvm_utils.wait_for(lambda: not env["tcpdump"].is_alive(), |
+ if virt_utils.wait_for(lambda: not env["tcpdump"].is_alive(), |
0.1, 0.1, 1.0): |
logging.warn("Could not start tcpdump") |
logging.warn("Status: %s" % env["tcpdump"].get_status()) |
- logging.warn("Output:" + kvm_utils.format_str_for_message( |
+ logging.warn("Output:" + virt_utils.format_str_for_message( |
env["tcpdump"].get_output())) |
# Destroy and remove VMs that are no longer needed in the environment |
requested_vms = params.objects("vms") |
for key in env.keys(): |
vm = env[key] |
- if not kvm_utils.is_vm(vm): |
+ if not virt_utils.is_vm(vm): |
continue |
if not vm.name in requested_vms: |
logging.debug("VM '%s' found in environment but not required for " |
@@ -241,7 +243,7 @@ def preprocess(test, params, env): |
# Get the KVM userspace version and write it as a keyval |
logging.debug("Fetching KVM userspace version...") |
- qemu_path = kvm_utils.get_path(test.bindir, params.get("qemu_binary", |
+ qemu_path = virt_utils.get_path(test.bindir, params.get("qemu_binary", |
"qemu")) |
version_line = commands.getoutput("%s -help | head -n 1" % qemu_path) |
matches = re.findall("[Vv]ersion .*?,", version_line) |
@@ -254,7 +256,7 @@ def preprocess(test, params, env): |
test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) |
if params.get("setup_hugepages") == "yes": |
- h = test_setup.HugePageConfig(params) |
+ h = virt_test_setup.HugePageConfig(params) |
h.setup() |
# Execute any pre_commands |
@@ -340,12 +342,12 @@ def postprocess(test, params, env): |
try: |
session = vm.login() |
session.close() |
- except (kvm_utils.LoginError, kvm_vm.VMError), e: |
+ except (virt_utils.LoginError, virt_vm.VMError), e: |
logging.warn(e) |
vm.destroy(gracefully=False) |
- # Kill all kvm_subprocess tail threads |
- kvm_subprocess.kill_tail_threads() |
+ # Kill all aexpect tail threads |
+ aexpect.kill_tail_threads() |
# Terminate tcpdump if no VMs are alive |
living_vms = [vm for vm in env.get_all_vms() if vm.is_alive()] |
@@ -354,7 +356,7 @@ def postprocess(test, params, env): |
del env["tcpdump"] |
if params.get("setup_hugepages") == "yes": |
- h = test_setup.HugePageConfig(params) |
+ h = virt_test_setup.HugePageConfig(params) |
h.cleanup() |
# Execute any post_commands |
@@ -396,14 +398,14 @@ def _take_screendumps(test, params, env): |
global _screendump_thread_termination_event |
temp_dir = test.debugdir |
if params.get("screendump_temp_dir"): |
- temp_dir = kvm_utils.get_path(test.bindir, |
+ temp_dir = virt_utils.get_path(test.bindir, |
params.get("screendump_temp_dir")) |
try: |
os.makedirs(temp_dir) |
except OSError: |
pass |
temp_filename = os.path.join(temp_dir, "scrdump-%s.ppm" % |
- kvm_utils.generate_random_string(6)) |
+ virt_utils.generate_random_string(6)) |
delay = float(params.get("screendump_delay", 5)) |
quality = int(params.get("screendump_quality", 30)) |