[PATCH 07/16] virt.virt_env_process: Add libvirt vm handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: Martin Jenner <mjenner@xxxxxxxxxx>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx>
---
 client/virt/virt_env_process.py |   52 ++++++++++++++++++++++++++++++---------
 1 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/client/virt/virt_env_process.py b/client/virt/virt_env_process.py
index 25285b8..e5316d2 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,32 @@ 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":
+            vm.params = params
+            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 +301,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 +403,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.7

--
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


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux