diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 109: Fix problem with return code detection in commands that specify a

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

Commit Message

Paul Larson Sept. 14, 2011, 4:08 p.m. UTC
Merge authors:
  Spring Zhang (qzhang)
Related merge proposals:
  https://code.launchpad.net/~qzhang/lava-dispatcher/fix-lava-test-install/+merge/75352
  proposed by: Spring Zhang (qzhang)
  review: Approve - Paul Larson (pwlars)
  review: Resubmit - Spring Zhang (qzhang)
------------------------------------------------------------
revno: 109 [merge]
committer: Paul Larson <paul.larson@canonical.com>
branch nick: big-dispatcher-merge
timestamp: Wed 2011-09-14 11:05:43 -0500
message:
  Fix problem with return code detection in commands that specify a
  response to expect.
modified:
  lava_dispatcher/actions/lava-test.py
  lava_dispatcher/client.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/actions/lava-test.py'
--- lava_dispatcher/actions/lava-test.py	2011-09-14 14:43:58 +0000
+++ lava_dispatcher/actions/lava-test.py	2011-09-14 16:05:43 +0000
@@ -71,7 +71,7 @@ 
     try:
         client.run_shell_command(
             'chroot /mnt/root lava-test help',
-            response="list-test", timeout=10)
+            response="list-test", timeout=60)
     except:
         tb = traceback.format_exc()
         client.sio.write(tb)

=== modified file 'lava_dispatcher/client.py'
--- lava_dispatcher/client.py	2011-09-14 14:43:58 +0000
+++ lava_dispatcher/client.py	2011-09-14 16:05:43 +0000
@@ -103,7 +103,7 @@ 
                 self.in_master_shell()
             except:
                 raise
-        self.proc.sendline('export PS1="rc=$(echo \$?) $PS1"')
+        self.proc.sendline('export PS1="$PS1 [rc=$(echo \$?)]: "')
         self.proc.expect(self.master_str)
 
     def boot_linaro_image(self):
@@ -130,7 +130,7 @@ 
         # Details: system PS1 is set in /etc/bash.bashrc and user PS1 is set in
         # /root/.bashrc, it is
         # "${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
-        self.proc.sendline('export PS1="rc=$(echo \$?) $PS1"')
+        self.proc.sendline('export PS1="$PS1 rc=$(echo \$?) "')
         self.proc.expect(self.tester_str)
 
     def enter_uboot(self):
@@ -153,6 +153,16 @@ 
         self.empty_pexpect_buffer()
         # return return-code if captured, else return None
         self.proc.sendline(cmd)
+        start_time = time.time()
+        if response:
+            self.proc.expect(response, timeout=timeout)
+            elapsed_time = int(time.time()-start_time)
+            # if reponse is master/tester string, make rc expect timeout to be
+            # 2 sec, else make it consume remained timeout
+            if response in [self.master_str, self.tester_str]:
+                timeout = 2
+            else:
+                timeout = int(timeout-elapsed_time)
         #verify return value of last command, match one number at least
         #PS1 setting is in boot_linaro_image or boot_master_image
         pattern1 = "rc=(\d+\d?\d?)"
@@ -162,8 +172,6 @@ 
             rc = int(self.proc.match.groups()[0])
         else:
             rc = None
-        if response:
-            self.proc.expect(response, timeout=2)
         return rc
 
     def run_cmd_master(self, cmd, timeout=-1):