From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 2/6] KVM test: AutoIt and Autotest wrappers: use get_command_output() instead of sendline() Date: Tue, 29 Sep 2009 22:04:23 +0200 Message-ID: <1254254667-19385-2-git-send-email-mgoldish@redhat.com> References: <1254254667-19385-1-git-send-email-mgoldish@redhat.com> Cc: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:41357 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752068AbZI2UIB (ORCPT ); Tue, 29 Sep 2009 16:08:01 -0400 In-Reply-To: <1254254667-19385-1-git-send-email-mgoldish@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: get_command_output() is safer because it waits for the prompt to return. sendline() returns immediately, and the output generated in response to the command can appear later and interfere with the test. For example, the prompt can appear while the Autotest wrapper waits for an Autotest test to complete, and this will make the wrapper exit as if the test has completed. Signed-off-by: Michael Goldish --- client/tests/kvm/tests/autoit.py | 7 +++---- client/tests/kvm/tests/autotest.py | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client/tests/kvm/tests/autoit.py b/client/tests/kvm/tests/autoit.py index fd2a2cb..9435d7c 100644 --- a/client/tests/kvm/tests/autoit.py +++ b/client/tests/kvm/tests/autoit.py @@ -30,18 +30,17 @@ def run_autoit(test, params, env): # Send AutoIt script to guest (this code will be replaced once we # support sending files to Windows guests) - session.sendline("del script.au3") + session.get_command_output("del script.au3", internal_timeout=0) file = open(kvm_utils.get_path(test.bindir, script)) for line in file.readlines(): # Insert a '^' before each character line = "".join("^" + c for c in line.rstrip()) if line: # Append line to the file - session.sendline("echo %s>>script.au3" % line) + session.get_command_output("echo %s>>script.au3" % line, + internal_timeout=0) file.close() - session.read_up_to_prompt() - command = "cmd /c %s script.au3 %s" % (binary, script_params) logging.info("---------------- Script output ----------------") diff --git a/client/tests/kvm/tests/autotest.py b/client/tests/kvm/tests/autotest.py index 5c9b2aa..798217d 100644 --- a/client/tests/kvm/tests/autotest.py +++ b/client/tests/kvm/tests/autotest.py @@ -85,7 +85,7 @@ def run_autotest(test, params, env): extract(vm, "autotest.tar.bz2") # mkdir autotest/tests - session.sendline("mkdir autotest/tests") + session.get_command_output("mkdir autotest/tests") # Extract .tar.bz2 into autotest/tests extract(vm, test_name + ".tar.bz2", "autotest/tests") @@ -99,10 +99,9 @@ def run_autotest(test, params, env): # Run the test logging.info("Running test '%s'..." % test_name) - session.sendline("cd autotest") - session.sendline("rm -f control.state") - session.sendline("rm -rf results/*") - session.read_up_to_prompt() + session.get_command_output("cd autotest") + session.get_command_output("rm -f control.state") + session.get_command_output("rm -rf results/*") logging.info("---------------- Test output ----------------") status = session.get_command_status("bin/autotest control", timeout=test_timeout, -- 1.5.4.1