build.py: handle errors from ssh in a better way
authorHelmut Grohne <helmut@subdivi.de>
Thu, 1 Aug 2019 08:12:37 +0000 (10:12 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Thu, 1 Aug 2019 08:12:37 +0000 (10:12 +0200)
Previously, it would retry immediately and produce empty log files
marked as failures. When ssh fails, we no longer record a build nor log.
We also wait a little before retrying.

build.py

index 3ede7f1..3312bd0 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -31,12 +31,17 @@ def do_build(source, version, architecture, server):
                                         now.strftime("%Y%m%d%H%M%S"))
     cmdline = ["ssh", server, "sh", "/dev/stdin", architecture,
                "%s_%s" % (source, version)]
-    with open(os.path.join("logs", logtarget), "w+b") as output:
+    logname = os.path.join("logs", logtarget)
+    with open(logname, "w+b") as output:
         with open("build.sh", "rb") as instructions:
             code = subprocess.call(cmdline, stdin=instructions, stdout=output)
         output.seek(0)
         status = scan_log_status(output)
-        print("status %s code %d" % (status, code))
+    if code == 255:
+        os.unlink(logname)
+        time.sleep(300)
+        raise RuntimeError("ssh failed")
+    print("status %s code %d" % (status, code))
     return (now, code == 0, logtarget, status == "given-back")
 
 def main():