From patchwork Tue Dec 8 19:22:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 65736 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB8JNDn6031196 for ; Tue, 8 Dec 2009 19:23:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965855AbZLHTWo (ORCPT ); Tue, 8 Dec 2009 14:22:44 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S965853AbZLHTWo (ORCPT ); Tue, 8 Dec 2009 14:22:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52640 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965835AbZLHTWn (ORCPT ); Tue, 8 Dec 2009 14:22:43 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB8JMmGo000744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Dec 2009 14:22:48 -0500 Received: from localhost.localdomain (vpn-9-102.rdu.redhat.com [10.11.9.102]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB8JMkF3004290; Tue, 8 Dec 2009 14:22:47 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, mgoldish@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH 1/2] KVM test: autotest subtest - avoid dependencies on symlinks Date: Tue, 8 Dec 2009 17:22:43 -0200 Message-Id: <1260300164-9916-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/tests/autotest.py b/client/tests/kvm/tests/autotest.py index 798217d..f19a2ec 100644 --- a/client/tests/kvm/tests/autotest.py +++ b/client/tests/kvm/tests/autotest.py @@ -1,5 +1,6 @@ import os, logging from autotest_lib.client.common_lib import error +from autotest_lib.client.bin import utils import kvm_subprocess, kvm_utils, kvm_test_utils, scan_results @@ -21,14 +22,26 @@ def run_autotest(test, params, env): @param remote_path: Remote path """ copy = False + basename = os.path.basename(local_path) output = session.get_command_output("ls -l %s" % remote_path) - if ("such file" in output or - int(output.split()[4]) != os.path.getsize(local_path)): - basename = os.path.basename(local_path) - logging.info("Copying %s to guest (file is missing or has a " - "different size)..." % basename) + local_size = os.path.getsize(local_path) + if "such file" in output: + logging.info("Copying %s to guest (remote file is missing)" % + basename) + copy = True + else: + remote_size = int(output.split()[4]) + if remote_size != local_size: + logging.info("Copying %s to guest due to size mismatch" + "(remote size %s, local size %s)" % (basename, + remote_size, + local_size)) + copy = True + + if copy: if not vm.copy_files_to(local_path, remote_path): - raise error.TestFail("Could not copy %s to guest" % basename) + raise error.TestFail("Could not copy %s to guest" % local_path) + def extract(vm, remote_path, dest_dir="."): """ @@ -40,10 +53,11 @@ def run_autotest(test, params, env): """ basename = os.path.basename(remote_path) logging.info("Extracting %s..." % basename) - status = session.get_command_status("tar xfj %s -C %s" % - (remote_path, dest_dir)) + (status, output) = session.get_command_status_output( + "tar xjvf %s -C %s" % (remote_path, dest_dir)) if status != 0: - raise error.TestFail("Could not extract %s" % basename) + raise error.TestFail("Could not extract %s, command output: %s" % + (basename, output)) vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) session = kvm_test_utils.wait_for_login(vm) @@ -52,54 +66,60 @@ def run_autotest(test, params, env): test_name = params.get("test_name") test_timeout = int(params.get("test_timeout", 300)) test_control_file = params.get("test_control_file", "control") + tarred_autotest_path = "/tmp/autotest.tar.bz2" tarred_test_path = "/tmp/%s.tar.bz2" % test_name + # To avoid problems, let's make the test use the current AUTODIR + # (autotest client path) location + autotest_path = os.environ['AUTODIR'] + tests_path = os.path.join(autotest_path, 'tests') + test_path = os.path.join(tests_path, test_name) + # tar the contents of bindir/autotest - cmd = "cd %s; tar cvjf %s autotest/*" - cmd += " --exclude=autotest/tests" - cmd += " --exclude=autotest/results" - cmd += " --exclude=autotest/tmp" - cmd += " --exclude=autotest/control" + cmd = "tar cvjf %s %s/*" % (tarred_autotest_path, autotest_path) + cmd += " --exclude=%s/tests" % autotest_path + cmd += " --exclude=%s/results" % autotest_path + cmd += " --exclude=%s/tmp" % autotest_path + cmd += " --exclude=%s/control" % autotest_path cmd += " --exclude=*.pyc" cmd += " --exclude=*.svn" cmd += " --exclude=*.git" - kvm_subprocess.run_fg(cmd % (test.bindir, tarred_autotest_path), timeout=30) + utils.run(cmd) # tar the contents of bindir/autotest/tests/ - cmd = "cd %s; tar cvjf %s %s/*" + cmd = "tar cvjf %s %s/*" % (tarred_test_path, test_path) cmd += " --exclude=*.pyc" cmd += " --exclude=*.svn" cmd += " --exclude=*.git" - kvm_subprocess.run_fg(cmd % - (os.path.join(test.bindir, "autotest", "tests"), - tarred_test_path, test_name), timeout=30) + utils.run(cmd) # Copy autotest.tar.bz2 - copy_if_size_differs(vm, tarred_autotest_path, "autotest.tar.bz2") + copy_if_size_differs(vm, tarred_autotest_path, tarred_autotest_path) # Copy .tar.bz2 - copy_if_size_differs(vm, tarred_test_path, test_name + ".tar.bz2") + copy_if_size_differs(vm, tarred_test_path, tarred_test_path) # Extract autotest.tar.bz2 - extract(vm, "autotest.tar.bz2") + extract(vm, tarred_autotest_path, "/") # mkdir autotest/tests - session.get_command_output("mkdir autotest/tests") + session.get_command_output("mkdir -p %s" % tests_path) # Extract .tar.bz2 into autotest/tests - extract(vm, test_name + ".tar.bz2", "autotest/tests") + extract(vm, tarred_test_path, "/") # Copy the selected control file (located inside # test.bindir/autotest_control) to the autotest dir control_file_path = os.path.join(test.bindir, "autotest_control", test_control_file) - if not vm.copy_files_to(control_file_path, "autotest/control"): + if not vm.copy_files_to(control_file_path, + os.path.join(autotest_path, 'control')): raise error.TestFail("Could not copy the test control file to guest") # Run the test logging.info("Running test '%s'..." % test_name) - session.get_command_output("cd autotest") + session.get_command_output("cd %s" % autotest_path) session.get_command_output("rm -f control.state") session.get_command_output("rm -rf results/*") logging.info("---------------- Test output ----------------") @@ -121,7 +141,8 @@ def run_autotest(test, params, env): guest_results_dir = os.path.join(test.outputdir, "guest_results") if not os.path.exists(guest_results_dir): os.mkdir(guest_results_dir) - if not vm.copy_files_from("autotest/results/default/*", guest_results_dir): + if not vm.copy_files_from("%s/results/default/*" % autotest_path, + guest_results_dir): logging.error("Could not copy results back from guest") # Report test results