KVM test: allow the user to specify the paths of the qemu and qemu-img binaries

Currently, qemu and qemu-img are accessed via symlinks that must be present in
test.bindir (the KVM test dir).

This patch adds new parameters qemu_binary and qemu_img_binary, which specify
the paths of the qemu and qemu-img binaries.
They may be absolute paths or relative to test.bindir (the KVM test dir).
In kvm_tests.cfg.sample they are set to 'qemu' and 'qemu-img', which means the
binaries are expected to be found in test.bindir, which is the current behavior.

Adding these parameters results in slightly cleaner code, but also allows for
some more flexibility in defining tests.  For example, the user can 'variant'
on the parameter qemu_binary, i.e. define several variants of a test set that

differ only in this parameter.  This will make the test set run several times,
each time using a different pre-installed version of qemu.  The parameters also
make it possible to use pre-installed qemu and qemu-img that reside somewhere
outside the Autotest dir, e.g. in /usr/bin.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3550 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py
index 960bda9..8fa74cf 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -19,7 +19,6 @@
     @param params: A dict containing image preprocessing parameters.
     @note: Currently this function just creates an image if requested.
     """
-    qemu_img_path = os.path.join(test.bindir, "qemu-img")
     image_filename = kvm_vm.get_image_filename(params, test.bindir)
 
     create_image = False
@@ -27,13 +26,13 @@
     if params.get("force_create_image") == "yes":
         logging.debug("'force_create_image' specified; creating image...")
         create_image = True
-    elif params.get("create_image") == "yes" and not \
-    os.path.exists(image_filename):
+    elif (params.get("create_image") == "yes" and not
+          os.path.exists(image_filename)):
         logging.debug("Creating image...")
         create_image = True
 
     if create_image:
-        if not kvm_vm.create_image(params, qemu_img_path, test.bindir):
+        if not kvm_vm.create_image(params, test.bindir):
             message = "Could not create image"
             logging.error(message)
             raise error.TestError(message)
@@ -49,16 +48,13 @@
     @param env: The environment (a dict-like object).
     @param name: The name of the VM object.
     """
-    qemu_path = os.path.join(test.bindir, "qemu")
-
     logging.debug("Preprocessing 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; creating it")
-        vm = kvm_vm.VM(name, params, qemu_path, test.bindir,
-                       env.get("address_cache"))
+        vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache"))
         kvm_utils.env_register_vm(env, name, vm)
 
     start_vm = False
@@ -77,14 +73,13 @@
             logging.debug("VM is not alive; starting it...")
             start_vm = True
         elif vm.make_qemu_command() != vm.make_qemu_command(name, params,
-                                                            qemu_path,
                                                             test.bindir):
             logging.debug("VM's qemu command differs from requested one; "
                           "restarting it...")
             start_vm = True
 
     if start_vm:
-        if not vm.create(name, params, qemu_path, test.bindir, for_migration):
+        if not vm.create(name, params, test.bindir, for_migration):
             message = "Could not start VM"
             logging.error(message)
             raise error.TestError(message)
@@ -254,7 +249,8 @@
 
     # Get the KVM userspace version and write it as a keyval
     logging.debug("Fetching KVM userspace version...")
-    qemu_path = os.path.join(test.bindir, "qemu")
+    qemu_path = kvm_utils.get_path(test.bindir, params.get("qemu_binary",
+                                                           "qemu"))
     version_line = commands.getoutput("%s -help | head -n 1" % qemu_path)
     exp = re.compile("[Vv]ersion .*?,")
     match = exp.search(version_line)