From: Lucas Meneghel Rodrigues Subject: [PATCH 3/5] KVM test: Verify paths to cdrom and qemu on kvm_preprocessing Date: Tue, 8 Dec 2009 00:59:03 -0200 Message-ID: <1260241145-19029-3-git-send-email-lmr@redhat.com> References: <1260241145-19029-1-git-send-email-lmr@redhat.com> <1260241145-19029-2-git-send-email-lmr@redhat.com> Cc: kvm@vger.kernel.org, mgoldish@redhat.com, Lucas Meneghel Rodrigues To: autotest@test.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:5780 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965416AbZLHC7X (ORCPT ); Mon, 7 Dec 2009 21:59:23 -0500 In-Reply-To: <1260241145-19029-2-git-send-email-lmr@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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