From patchwork Mon Sep 5 21:07:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 1125472 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p85L7MBH019330 for ; Mon, 5 Sep 2011 21:07:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752961Ab1IEVHV (ORCPT ); Mon, 5 Sep 2011 17:07:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23999 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751459Ab1IEVHT (ORCPT ); Mon, 5 Sep 2011 17:07:19 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p85L7H22012431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Sep 2011 17:07:18 -0400 Received: from freedom.local.com (vpn-11-168.rdu.redhat.com [10.11.11.168]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p85L7FJB003601; Mon, 5 Sep 2011 17:07:16 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH] virt: run_autotest: Fix bug under python < 2.6 Date: Mon, 5 Sep 2011 18:07:11 -0300 Message-Id: <1315256831-28099-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 05 Sep 2011 21:07:22 +0000 (UTC) We recently had a bugfix in r5494 that uses os.path.relpath, but it turns out that this API is only available from python >= 2.6. So, in order to keep the bug fixed while still using py 2.4 only APIs, made some changes on how we compress the autotest client on the host and uncompress the tarball in the guest. Signed-off-by: Lucas Meneghel Rodrigues --- client/virt/virt_test_utils.py | 76 +++++++++++++++++++++++++++------------ 1 files changed, 52 insertions(+), 24 deletions(-) diff --git a/client/virt/virt_test_utils.py b/client/virt/virt_test_utils.py index cf718c4..7c3343b 100644 --- a/client/virt/virt_test_utils.py +++ b/client/virt/virt_test_utils.py @@ -451,7 +451,10 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): @param vm: VM object. @param local_path: Local path. @param remote_path: Remote path. + + @return: Whether the hash differs (True) or not (False). """ + hash_differs = False local_hash = utils.hash_file(local_path) basename = os.path.basename(local_path) output = session.cmd_output("md5sum %s" % remote_path) @@ -466,13 +469,18 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): # temporary problem remote_hash = "0" if remote_hash != local_hash: - logging.debug("Copying %s to guest", basename) + hash_differs = True + logging.debug("Copying %s to guest " + "(remote hash: %s, local hash:%s)", + basename, remote_hash, local_hash) vm.copy_files_to(local_path, remote_path) + return hash_differs - def extract(vm, remote_path, dest_dir="."): + def extract(vm, remote_path, dest_dir): """ - Extract a .tar.bz2 file on the guest. + Extract the autotest .tar.bz2 file on the guest, ensuring the final + destination path will be dest_dir. @param vm: VM object @param remote_path: Remote file path @@ -480,11 +488,23 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): """ basename = os.path.basename(remote_path) logging.debug("Extracting %s on VM %s", basename, vm.name) - e_cmd = "tar xjvf %s -C %s" % (remote_path, dest_dir) - session.cmd(e_cmd, timeout=120) + session.cmd("rm -rf %s" % dest_dir) + dirname = os.path.dirname(remote_path) + session.cmd("cd %s" % dirname) + session.cmd("mkdir -p %s" % os.path.dirname(dest_dir)) + e_cmd = "tar xjvf %s -C %s" % (basename, os.path.dirname(dest_dir)) + output = session.cmd(e_cmd, timeout=120) + autotest_dirname = "" + for line in output.splitlines(): + autotest_dirname = line.split("/")[0] + break + if autotest_dirname != os.path.basename(dest_dir): + session.cmd("cd %s" % os.path.dirname(dest_dir)) + session.cmd("mv %s %s" % + (autotest_dirname, os.path.basename(dest_dir))) - def get_results(): + def get_results(guest_autotest_path): """ Copy autotest results present on the guest back to the host. """ @@ -492,15 +512,16 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): guest_results_dir = os.path.join(outputdir, "guest_autotest_results") if not os.path.exists(guest_results_dir): os.mkdir(guest_results_dir) - vm.copy_files_from("%s/results/default/*" % autotest_path, + vm.copy_files_from("%s/results/default/*" % guest_autotest_path, guest_results_dir) - def get_results_summary(): + def get_results_summary(guest_autotest_path): """ Get the status of the tests that were executed on the host and close the session where autotest was being executed. """ + session.cmd("cd %s" % guest_autotest_path) output = session.cmd_output("cat results/*/status") try: results = scan_results.parse_results(output) @@ -524,36 +545,43 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") - compressed_autotest_path = os.path.relpath("/tmp/autotest.tar.bz2") + compressed_autotest_path = "/tmp/autotest.tar.bz2" + destination_autotest_path = "/usr/local/autotest" # To avoid problems, let's make the test use the current AUTODIR # (autotest client path) location - autotest_path = os.path.relpath(os.environ['AUTODIR']) + autotest_path = os.environ['AUTODIR'] + autotest_basename = os.path.basename(autotest_path) + autotest_parentdir = os.path.dirname(autotest_path) # tar the contents of bindir/autotest - cmd = "tar cvjf %s %s/*" % (compressed_autotest_path, autotest_path) + cmd = ("cd %s; tar cvjf %s %s/*" % + (autotest_parentdir, compressed_autotest_path, autotest_basename)) # Until we have nested virtualization, we don't need the kvm test :) - cmd += " --exclude=%s/tests/kvm" % autotest_path - cmd += " --exclude=%s/results" % autotest_path - cmd += " --exclude=%s/tmp" % autotest_path - cmd += " --exclude=%s/control*" % autotest_path + cmd += " --exclude=%s/tests/kvm" % autotest_basename + cmd += " --exclude=%s/results" % autotest_basename + cmd += " --exclude=%s/tmp" % autotest_basename + cmd += " --exclude=%s/control*" % autotest_basename cmd += " --exclude=*.pyc" cmd += " --exclude=*.svn" cmd += " --exclude=*.git" utils.run(cmd) # Copy autotest.tar.bz2 - copy_if_hash_differs(vm, compressed_autotest_path, compressed_autotest_path) + update = copy_if_hash_differs(vm, compressed_autotest_path, + compressed_autotest_path) # Extract autotest.tar.bz2 - extract(vm, compressed_autotest_path, "/") + if update: + extract(vm, compressed_autotest_path, destination_autotest_path) - vm.copy_files_to(control_path, os.path.join(autotest_path, 'control')) + vm.copy_files_to(control_path, + os.path.join(destination_autotest_path, 'control')) # Run the test logging.info("Running autotest control file %s on guest, timeout %ss", os.path.basename(control_path), timeout) - session.cmd("cd %s" % autotest_path) + session.cmd("cd %s" % destination_autotest_path) try: session.cmd("rm -f control.state") session.cmd("rm -rf results/*") @@ -587,20 +615,20 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): bg.join() except aexpect.ShellTimeoutError: if vm.is_alive(): - get_results() - get_results_summary() + get_results(destination_autotest_path) + get_results_summary(destination_autotest_path) raise error.TestError("Timeout elapsed while waiting for job to " "complete") else: raise error.TestError("Autotest job on guest failed " "(VM terminated during job)") except aexpect.ShellProcessTerminatedError: - get_results() + get_results(destination_autotest_path) raise error.TestError("Autotest job on guest failed " "(Remote session terminated during job)") - results = get_results_summary() - get_results() + results = get_results_summary(destination_autotest_path) + get_results(destination_autotest_path) # Make a list of FAIL/ERROR/ABORT results (make sure FAIL results appear # before ERROR results, and ERROR results appear before ABORT results)