[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 97: add retry mechanism to make sure test result download successfully

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

Commit Message

Spring Zhang Sept. 1, 2011, 3:55 p.m.
Merge authors:
  Spring Zhang (qzhang)
Related merge proposals:
  https://code.launchpad.net/~qzhang/lava-dispatcher/fix-387397-831784/+merge/73489
  proposed by: Spring Zhang (qzhang)
  review: Approve - Spring Zhang (qzhang)
------------------------------------------------------------
revno: 97 [merge]
committer: Spring Zhang <spring.zhang@linaro.org>
branch nick: temp-merge
timestamp: Thu 2011-09-01 23:52:58 +0800
message:
  add retry mechanism to make sure test result download successfully
modified:
  lava_dispatcher/actions/launch_control.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

Patch

=== modified file 'lava_dispatcher/actions/launch_control.py'
--- lava_dispatcher/actions/launch_control.py	2011-08-29 13:57:19 +0000
+++ lava_dispatcher/actions/launch_control.py	2011-09-01 15:52:58 +0000
@@ -105,10 +105,18 @@ 
         result_tarball = "http://%s/lava_results.tgz" % master_ip
         tarball_dir = mkdtemp(dir=LAVA_IMAGE_TMPDIR)
         os.chmod(tarball_dir, 0755)
-        #FIXME: need to consider exception?
-        result_path = download(result_tarball, tarball_dir)
-        id = client.proc.expect([MASTER_STR, pexpect.TIMEOUT, pexpect.EOF],
-                timeout=3)
+
+        # download test result with a retry mechanism
+        # set retry timeout to 2mins
+        now = time.time()
+        timeout = 120
+        while time.time() < now+timeout:
+            try:
+                result_path = download(result_tarball, tarball_dir)
+            except:
+                if time.time() >= now+timeout:
+                    raise
+
         client.run_shell_command('kill %1', response=MASTER_STR)
 
         tar = tarfile.open(result_path)

=== modified file 'lava_dispatcher/client.py'
--- lava_dispatcher/client.py	2011-08-29 13:57:19 +0000
+++ lava_dispatcher/client.py	2011-08-31 07:49:52 +0000
@@ -131,17 +131,18 @@ 
         self.wait_network_up()
         #tty device uses minimal match, see pexpect wiki
         #pattern1 = ".*\n(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
-        pattern1 = "(\d?\d?\d?\.\d?\d?\d?\.\d?\d?\d?\.\d?\d?\d?)"
+        pattern1 = "(\d+\d?\d?\.\d+\d?\d?\.\d+\d?\d?\.\d+\d?\d?)"
         cmd = ("ifconfig %s | grep 'inet addr' | awk -F: '{print $2}' |"
                 "awk '{print $1}'" % self.board.default_network_interface)
         self.proc.sendline(cmd)
-        #if running from ipython, it needs another Enter, don't know why
+        #if running from ipython, it needs another Enter, don't know why:
         #self.proc.sendline("")
         id = self.proc.expect([pattern1, pexpect.EOF,
             pexpect.TIMEOUT], timeout=5)
-        print "\nid=%s" %id
+        print "\nmatching pattern is %s" % id
         if id == 0:
             ip = self.proc.match.groups()[0]
+            print "Master IP is %s" % ip
             return ip
         else:
             return None