From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lucas Meneghel Rodrigues Subject: Re: [KVM-AUTOTEST PATCH] kvm_utils.py: remote_login(): improve regular expression matching Date: Fri, 29 May 2009 03:12:08 -0300 Message-ID: <1243577528.2890.0.camel@localhost.localdomain> References: <8e37a36c044c20259dcd8a34d72a651e85b37d5f.1243179847.git.mgoldish@redhat.com> <838bcae1b49be011e2cde1294a391a296059464a.1243179847.git.mgoldish@redhat.com> <6a70cb56a775fdb688da0231073abb0ce4baa7b1.1243179847.git.mgoldish@redhat.com> <63bacaa214ccd95c18fb644056855acd72757ac4.1243179847.git.mgoldish@redhat.com> <43f85767b32b927ca5e32abc5ded281915343656.1243179847.git.mgoldish@redhat.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Michael Goldish Return-path: Received: from mx2.redhat.com ([66.187.237.31]:54872 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753376AbZE2GMK (ORCPT ); Fri, 29 May 2009 02:12:10 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4T6CC7i000490 for ; Fri, 29 May 2009 02:12:12 -0400 In-Reply-To: <43f85767b32b927ca5e32abc5ded281915343656.1243179847.git.mgoldish@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sun, 2009-05-24 at 18:46 +0300, Michael Goldish wrote: > 1. Make the 'login:' regular expression stricter so it doesn't match > 'Last login: ...' messages. > 2. Make the 'password:' regular expression stricter. > 3. Handle 'Connection refused' messages. Looks good to me > Signed-off-by: Michael Goldish > --- > client/tests/kvm_runtest_2/kvm_utils.py | 13 +++++++++---- > 1 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/client/tests/kvm_runtest_2/kvm_utils.py b/client/tests/kvm_runtest_2/kvm_utils.py > index be8ad95..5736cf6 100644 > --- a/client/tests/kvm_runtest_2/kvm_utils.py > +++ b/client/tests/kvm_runtest_2/kvm_utils.py > @@ -413,7 +413,8 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): > > while True: > (match, text) = sub.read_until_last_line_matches( > - ["[Aa]re you sure", "[Pp]assword:", "[Ll]ogin:", "[Cc]onnection.*closed", prompt], > + [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"^\s*[Ll]ogin:\s*$", > + r"[Cc]onnection.*closed", r"[Cc]onnection.*refused", prompt], > timeout=timeout, internal_timeout=0.5) > if match == 0: # "Are you sure you want to continue connecting" > kvm_log.debug("Got 'Are you sure...'; sending 'yes'") > @@ -437,11 +438,15 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): > kvm_log.debug("Got 'Connection closed'") > sub.close() > return None > - elif match == 4: # prompt > + elif match == 4: # "Connection refused" > + kvm_log.debug("Got 'Connection refused'") > + sub.close() > + return None > + elif match == 5: # prompt > kvm_log.debug("Got shell prompt -- logged in") > return sub > else: # match == None > - kvm_log.debug("Timeout or process terminated") > + kvm_log.debug("Timeout elapsed or process terminated") > sub.close() > return None > > @@ -470,7 +475,7 @@ def remote_scp(command, password, timeout=300, login_timeout=10): > > while True: > (match, text) = sub.read_until_last_line_matches( > - ["[Aa]re you sure", "[Pp]assword:", "lost connection"], > + [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"lost connection"], > timeout=_timeout, internal_timeout=0.5) > if match == 0: # "Are you sure you want to continue connecting" > kvm_log.debug("Got 'Are you sure...'; sending 'yes'") -- Lucas Meneghel Rodrigues Software Engineer (QE) Red Hat - Emerging Technologies