If paths to CD images and qemu binaries are not correctly
configured, the tests will fail, sometimes giving to
unexperienced users little clue about what is actually
going on. So make sure we verify:

 * ISO paths
 * qemu binary paths

Inside kvm_preprocessing code, and give clear indications
if something goes wrong, asking the user to fix the
configuration problem.

Signed-off-by: Lucas Meneghel Rodrigues <l...@redhat.com>
---
 client/tests/kvm/kvm_preprocessing.py |   48 +++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_preprocessing.py 
b/client/tests/kvm/kvm_preprocessing.py
index 5bae2bd..85a2d9c 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -187,6 +187,29 @@ def preprocess(test, params, env):
     @param params: A dict containing all VM and image parameters.
     @param env: The environment (a dict-like object).
     """
+    # Verify if the:
+    #  * CD locations
+    #  * qemu and qemu-img binaries
+    # are valid paths
+    needed_paths = [[params.get("cdrom", ""),
+                     os.path.join(test.bindir, 'isos')],
+                    [params.get("qemu_binary", ""), test.bindir],
+                    [params.get("qemu_img_binary", ""), test.bindir]]
+
+    missing_paths = []
+    for needed_path, root_dir in needed_paths:
+        # If the test doesn't set one of the parameters,
+        # just don't check for it.
+        if needed_path:
+            needed_path = kvm_utils.get_path(root_dir, needed_path)
+            if not _is_path_present(needed_path):
+                missing_paths.append(needed_path)
+
+    if missing_paths:
+        raise error.TestError("The following needed paths are missing "
+                              "or are broken symbolic links: %s" %
+                              missing_paths)
+
     # Start tcpdump if it isn't already running
     if not env.has_key("address_cache"):
         env["address_cache"] = {}
@@ -343,3 +366,28 @@ def _update_address_cache(address_cache, line):
                           mac_address, address_cache.get("last_seen"))
             address_cache[mac_address] = address_cache.get("last_seen")
             del address_cache["last_seen"]
+
+
+def _is_path_present(path):
+    """
+    Verify whether a given path to a file is present (follows symlinks).
+
+    @param path: Path to the file.
+    @return: True when the file is present, False when it's not.
+    """
+    exists = True
+
+    if os.path.islink(path):
+        source = os.path.abspath(os.readlink(path))
+        if not os.path.isfile(source):
+            logging.warning("File %s, needed for this test, "
+                            "is a broken symbolic link. Please fix your "
+                            "test configuration." % path)
+            exists = False
+    elif not os.path.isfile(path):
+        logging.warning("File %s, needed for this test, does not exist. "
+                        "Please fix your test configuration." % path)
+        exists = False
+
+    return exists
+
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to