From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 1/4] KVM test: allow setting shell line separator string in the config file Date: Sun, 20 Sep 2009 18:16:27 +0300 Message-ID: <1253459790-17859-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]:13716 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753435AbZITPTT (ORCPT ); Sun, 20 Sep 2009 11:19:19 -0400 Sender: kvm-owner@vger.kernel.org List-ID: The shell line separator string is appended to strings sent by sendline(). The string is controlled by the parameter shell_linesep. It defaults to "\n". Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_tests.cfg.sample | 1 + client/tests/kvm/kvm_utils.py | 12 ++++++------ client/tests/kvm/kvm_vm.py | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample index 38f5a5a..540d0a2 100644 --- a/client/tests/kvm/kvm_tests.cfg.sample +++ b/client/tests/kvm/kvm_tests.cfg.sample @@ -364,6 +364,7 @@ variants: shell_prompt = "^\w:\\.*>\s*$" username = Administrator password = 123456 + shell_linesep = "\r\n" shell_client = nc shell_port = 22 # File transfers are currently unsupported diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 88299be..53b664a 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -576,7 +576,7 @@ def scp_from_remote(host, port, username, password, remote_path, local_path, return remote_scp(command, password, timeout) -def ssh(host, port, username, password, prompt, timeout=10): +def ssh(host, port, username, password, prompt, linesep="\n", timeout=10): """ Log into a remote host (guest) using SSH. @@ -591,10 +591,10 @@ def ssh(host, port, username, password, prompt, timeout=10): """ command = ("ssh -o UserKnownHostsFile=/dev/null -p %s %s@%s" % (port, username, host)) - return remote_login(command, password, prompt, "\n", timeout) + return remote_login(command, password, prompt, linesep, timeout) -def telnet(host, port, username, password, prompt, timeout=10): +def telnet(host, port, username, password, prompt, linesep="\n", timeout=10): """ Log into a remote host (guest) using Telnet. @@ -608,10 +608,10 @@ def telnet(host, port, username, password, prompt, timeout=10): @return: kvm_spawn object on success and None on failure. """ command = "telnet -l %s %s %s" % (username, host, port) - return remote_login(command, password, prompt, "\r\n", timeout) + return remote_login(command, password, prompt, linesep, timeout) -def netcat(host, port, username, password, prompt, timeout=10): +def netcat(host, port, username, password, prompt, linesep="\n", timeout=10): """ Log into a remote host (guest) using Netcat. @@ -625,7 +625,7 @@ def netcat(host, port, username, password, prompt, timeout=10): @return: kvm_spawn object on success and None on failure. """ command = "nc %s %s" % (host, port) - return remote_login(command, password, prompt, "\n", timeout) + return remote_login(command, password, prompt, linesep, timeout) # The following are utility functions related to ports. diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 55220f9..07ceb6d 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -669,6 +669,7 @@ class VM: username = self.params.get("username", "") password = self.params.get("password", "") prompt = self.params.get("shell_prompt", "[\#\$]") + linesep = eval("'%s'" % self.params.get("shell_linesep", r"\n")) client = self.params.get("shell_client") address = self.get_address(nic_index) port = self.get_port(int(self.params.get("shell_port"))) @@ -679,13 +680,13 @@ class VM: if client == "ssh": session = kvm_utils.ssh(address, port, username, password, - prompt, timeout) + prompt, linesep, timeout) elif client == "telnet": session = kvm_utils.telnet(address, port, username, password, - prompt, timeout) + prompt, linesep, timeout) elif client == "nc": session = kvm_utils.netcat(address, port, username, password, - prompt, timeout) + prompt, linesep, timeout) if session: session.set_status_test_command(self.params.get("status_test_" -- 1.5.4.1