diff mbox

[3/5] KVM test: Verify paths to cdrom and qemu on kvm_preprocessing

Message ID 1260241145-19029-3-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues Dec. 8, 2009, 2:59 a.m. UTC
None
diff mbox

Patch

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
+