diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 431: when waiting for a prompt, send the occasional newline to see if a prompt has appeared but was ma...

Message ID 20121101073613.27856.29205.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Nov. 1, 2012, 7:36 a.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 431 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Thu 2012-11-01 08:35:50 +0100
message:
  when waiting for a prompt, send the occasional newline to see if a prompt has appeared but was mangled by a kernel log message or serial corruption
modified:
  lava_dispatcher/client/base.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py	2012-10-18 16:29:08 +0000
+++ lava_dispatcher/client/base.py	2012-10-31 15:33:04 +0000
@@ -34,6 +34,32 @@ 
 from lava_dispatcher.test_data import create_attachment
 
 
+def wait_for_prompt(connection, prompt_pattern, timeout):
+    # One of the challenges we face is that kernel log messages can appear
+    # half way through a shell prompt.  So, if things are taking a while,
+    # we send a newline along to maybe provoke a new prompt.  We wait for
+    # half the timeout period and then wait for one tenth of the timeout
+    # 6 times (so we wait for 1.1 times the timeout period overall).
+    prompt_wait_count = 0
+    if timeout == -1:
+        timeout = connection.timeout
+    partial_timeout = timeout / 2.0
+    while True:
+        try:
+            connection.expect(prompt_pattern, timeout=partial_timeout)
+        except pexpect.TIMEOUT:
+            if prompt_wait_count < 6:
+                logging.warning('Sending newline in case of corruption.')
+                prompt_wait_count += 1
+                partial_timeout = timeout / 10
+                connection.sendline('')
+                continue
+            else:
+                raise
+        else:
+            break
+
+
 class CommandRunner(object):
     """A convenient way to run a shell command and wait for a shell prompt.
 
@@ -89,7 +115,9 @@ 
         else:
             self.match_id = None
             self.match = None
-        self._connection.expect(self._prompt_str, timeout=timeout)
+
+        wait_for_prompt(self._connection, self._prompt_str, timeout)
+
         if self._prompt_str_includes_rc:
             rc = int(self._connection.match.group(1))
             if rc != 0 and not failok:
@@ -365,7 +393,7 @@ 
         self._boot_linaro_image()
         timeout = self.config.boot_linaro_timeout
         TESTER_PS1_PATTERN = self.target_device.deployment_data['TESTER_PS1_PATTERN']
-        self.proc.expect(TESTER_PS1_PATTERN, timeout=timeout)
+        wait_for_prompt(self.proc, TESTER_PS1_PATTERN, timeout=timeout)
         self.setup_proxy(TESTER_PS1_PATTERN)
         logging.info("System is in test image now")
 
@@ -386,10 +414,10 @@ 
     def boot_linaro_android_image(self):
         """Reboot the system to the test android image."""
         self._boot_linaro_android_image()
-        match_id = self.proc.expect(
-            [self.target_device.deployment_data['TESTER_PS1'], pexpect.TIMEOUT],
-            timeout=900)
-        if match_id == 1:
+        TESTER_PS1_PATTERN = self.target_device.deployment_data['TESTER_PS1_PATTERN']
+        try:
+            wait_for_prompt(self.proc, TESTER_PS1_PATTERN, timeout=900)
+        except pexpect.TIMEOUT:
             raise OperationFailed("booting into android test image failed")
         #TODO: set up proxy