diff mbox

[KVM-AUTOTEST] kvm_utils.py: remote_login(): improve regular expression matching

Message ID 43f85767b32b927ca5e32abc5ded281915343656.1243179847.git.mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish May 24, 2009, 3:46 p.m. UTC
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.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm_runtest_2/kvm_utils.py |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

Comments

sudhir kumar May 24, 2009, 6:59 p.m. UTC | #1
The patch looks sane to me. A very good thing that can be done for
remote_login() is to tune the tmeouts. I have seen especialy with
windows guests or sometimes when the machine is heavily loaded the
timeouts elapse and the test fails. When I increased the timeouts the
test did not fail. internal_timeout=0.5 is too less in my views and
even timeouts of 10 seconds prove insufficient sometimes. Do you too
have any such experience?

On Sun, May 24, 2009 at 9:16 PM, Michael Goldish <mgoldish@redhat.com> 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.
>
> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
>  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'")
> --
> 1.5.4.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Lucas Meneghel Rodrigues May 29, 2009, 6:12 a.m. UTC | #2
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 <mgoldish@redhat.com>
> ---
>  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'")
diff mbox

Patch

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'")