With this patch, we make libvirt vm handling integrating to pre/postprocessing code, making it possible the execution of a libvirt test. The idea was to try to abstract some concepts and intrude the least possible in the pre/postprocessing code. Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx> --- client/virt/virt_env_process.py | 51 +++++++++++++++++++++++++++++--------- 1 files changed, 39 insertions(+), 12 deletions(-) diff --git a/client/virt/virt_env_process.py b/client/virt/virt_env_process.py index 51c7e8a..6235c4e 100644 --- a/client/virt/virt_env_process.py +++ b/client/virt/virt_env_process.py @@ -2,7 +2,7 @@ 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 aexpect, virt_utils, kvm_monitor, ppm_utils, virt_test_setup -import virt_vm, kvm_vm +import virt_vm, kvm_vm, libvirt_vm try: import PIL.Image except ImportError: @@ -51,13 +51,23 @@ def preprocess_vm(test, params, env, name): """ logging.debug("Preprocessing VM '%s'", name) vm = env.get_vm(name) + vm_type = params.get('vm_type') if not vm: logging.debug("VM object for '%s' does not exist, creating it", name) - vm_type = params.get('vm_type') if vm_type == 'kvm': vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache")) + if vm_type == 'libvirt': + vm = libvirt_vm.VM(name, params, test.bindir, env.get("address_cache")) env.register_vm(name, vm) + remove_vm = False + if params.get("force_remove_vm") == "yes": + logging.debug("'force_remove_vm' specified; removing VM...") + remove_vm = True + + if remove_vm and not libvirt_vm.virsh_remove_domain(name): + raise error.TestError("Could not remove VM") + start_vm = False if params.get("restart_vm") == "yes": @@ -68,18 +78,31 @@ def preprocess_vm(test, params, env, name): "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") - start_vm = True - 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 + # need to deal with libvirt VM differently than qemu + if vm_type == 'libvirt': + if not libvirt_vm.virsh_is_alive(name): + logging.debug("VM is not alive; starting it...") + start_vm = True + else: + if not vm.is_alive(): + logging.debug("VM is not alive, starting it") + start_vm = True + 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 if start_vm: - # Start the VM (or restart it if it's already up) - vm.create(name, params, test.bindir, - migration_mode=params.get("migration_mode")) + if vm_type == 'libvirt' and params.get("type") != "unattended_install": + libvirt_vm.virsh_start(name, vm) + # Wait for the domain to be created + virt_utils.wait_for(func=vm.is_alive, timeout=60, + text=("waiting for domain %s to start" % + vm.name)) + else: + # Start the VM (or restart it if it's already up) + 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 @@ -277,6 +300,8 @@ def preprocess(test, params, env): if params.get("setup_hugepages") == "yes": h = virt_test_setup.HugePageConfig(params) h.setup() + if params.get("vm_type") == "libvirt": + libvirt_vm.libvirtd_restart() # Execute any pre_commands if params.get("pre_command"): @@ -377,6 +402,8 @@ def postprocess(test, params, env): if params.get("setup_hugepages") == "yes": h = virt_test_setup.HugePageConfig(params) h.cleanup() + if params.get("vm_type") == "libvirt": + libvirt_vm.libvirtd_restart() # Execute any post_commands if params.get("post_command"): -- 1.7.6.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html