From patchwork Fri Apr 16 16:11:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 93165 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3GGBeoj007417 for ; Fri, 16 Apr 2010 16:11:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758280Ab0DPQLg (ORCPT ); Fri, 16 Apr 2010 12:11:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1624 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757309Ab0DPQLf (ORCPT ); Fri, 16 Apr 2010 12:11:35 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3GGBYZ7029602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 16 Apr 2010 12:11:34 -0400 Received: from localhost.localdomain (vpn-9-143.rdu.redhat.com [10.11.9.143]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3GGBWNp012502; Fri, 16 Apr 2010 12:11:33 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: More improvements for autotest subtest Date: Fri, 16 Apr 2010 13:11:30 -0300 Message-Id: <1271434290-10775-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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.3 (demeter.kernel.org [140.211.167.41]); Fri, 16 Apr 2010 16:11:40 +0000 (UTC) diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py index 699601e..fb63798 100644 --- a/client/tests/kvm/kvm_test_utils.py +++ b/client/tests/kvm/kvm_test_utils.py @@ -252,36 +252,32 @@ def run_autotest(vm, session, control_path, timeout, outputdir): @param outputdir: Path on host where we should copy the guest autotest results to. """ - def copy_if_size_differs(vm, local_path, remote_path): + def copy_if_hash_differs(vm, local_path, remote_path): """ - Copy a file to a guest if it doesn't exist or if its size differs. + Copy a file to a guest if it doesn't exist or if its MD5sum differs. @param vm: VM object. @param local_path: Local path. @param remote_path: Remote path. """ copy = False + local_hash = utils.hash_file(local_path) basename = os.path.basename(local_path) - local_size = os.path.getsize(local_path) - output = session.get_command_output("ls -l %s" % remote_path) + output = session.get_command_output("md5sum %s" % remote_path) if "such file" in output: - logging.info("Copying %s to guest (remote file is missing)" % - basename) - copy = True + remote_hash = "0" + elif output: + remote_hash = output.split()[0] else: - try: - remote_size = output.split()[4] - remote_size = int(remote_size) - except IndexError, ValueError: - logging.error("Check for remote path size %s returned %s. " - "Cannot process.", remote_path, output) - raise error.TestFail("Failed to check for %s (Guest died?)" % - remote_path) - if remote_size != local_size: - logging.debug("Copying %s to guest due to size mismatch" - "(remote size %s, local size %s)" % - (basename, remote_size, local_size)) - copy = True + logging.warning("MD5 check for remote path %s did not return.", + remote_path) + # Let's be a little more lenient here and see if it wasn't a + # temporary problem + remote_hash = "0" + + if remote_hash != local_hash: + logging.debug("Copying %s to guest", basename) + copy = True if copy: if not vm.copy_files_to(local_path, remote_path): @@ -298,11 +294,11 @@ def run_autotest(vm, session, control_path, timeout, outputdir): """ basename = os.path.basename(remote_path) logging.info("Extracting %s...", basename) - (status, output) = session.get_command_status_output( - "tar xjvf %s -C %s" % (remote_path, dest_dir)) - if status != 0: - logging.error("Uncompress output:\n%s" % output) - raise error.TestFail("Could not extract %s on guest" % basename) + e_cmd = "tar xjvf %s -C %s" % (remote_path, dest_dir) + s, o = session.get_command_status_output(e_cmd) + if s != 0: + logging.error("Uncompress output:\n%s", o) + raise error.TestFail("Failed to extract %s on guest" % basename) def get_results(): @@ -324,13 +320,17 @@ def run_autotest(vm, session, control_path, timeout, outputdir): the session where autotest was being executed. """ output = session.get_command_output("cat results/*/status") - results = scan_results.parse_results(output) - # Report test results - logging.info("Results (test, status, duration, info):") - for result in results: - logging.info(str(result)) - session.close() - return results + try: + results = scan_results.parse_results(output) + # Report test results + logging.info("Results (test, status, duration, info):") + for result in results: + logging.info(str(result)) + session.close() + return results + except Exception, e: + logging.error("Error processing guest autotest results: %s", e) + return None if not os.path.isfile(control_path): @@ -349,14 +349,14 @@ def run_autotest(vm, session, control_path, timeout, outputdir): 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/control*" % autotest_path cmd += " --exclude=*.pyc" cmd += " --exclude=*.svn" cmd += " --exclude=*.git" utils.run(cmd) # Copy autotest.tar.bz2 - copy_if_size_differs(vm, compressed_autotest_path, compressed_autotest_path) + copy_if_hash_differs(vm, compressed_autotest_path, compressed_autotest_path) # Extract autotest.tar.bz2 extract(vm, compressed_autotest_path, "/") @@ -366,7 +366,8 @@ def run_autotest(vm, session, control_path, timeout, outputdir): raise error.TestFail("Could not copy the test control file to guest") # Run the test - logging.info("Running autotest control file %s on guest", control_path) + logging.info("Running autotest control file %s on guest, timeout %ss", + os.path.basename(control_path), timeout) session.get_command_output("cd %s" % autotest_path) session.get_command_output("rm -f control.state") session.get_command_output("rm -rf results/*") @@ -396,7 +397,8 @@ def run_autotest(vm, session, control_path, timeout, outputdir): "recognizable results") if bad_results: if len(bad_results) == 1: - e_msg = "Test %s failed during control file execution" % r[0] + e_msg = ("Test %s failed during control file execution" % + bad_results[0]) else: e_msg = ("Tests %s failed during control file execution" % " ".join(bad_results))