script:autobuild: Make sure we can send a failure mail
authorAndreas Schneider <asn@samba.org>
Wed, 25 Jan 2023 16:08:58 +0000 (17:08 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 30 Jan 2023 10:00:27 +0000 (10:00 +0000)
We should not run into an exception if the file doesn't exist.

Traceback (most recent call last):
  File "script/autobuild.py", line 1781, in <module>
    email_failure(-1, 'rebase', 'rebase', 'rebase',
  File "script/autobuild.py", line 1677, in email_failure
    f = open("%s/%s.stdout" % (gitroot, failed_tag), 'r')
FileNotFoundError: [Errno 2] No such file or directory:
  'samba-autobuild/rebase.stdout'

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Mon Jan 30 10:00:27 UTC 2023 on atb-devel-224

script/autobuild.py

index afa757491e067e64b44a1393fbf009107ff12ec5..492085a5bbbc7fcfb47ce7508223fade67c78335 100755 (executable)
@@ -1673,14 +1673,16 @@ The top commit for the tree that was built was:
 
 ''' % (log_base, failed_tag, log_base, failed_tag, log_base, top_commit_msg)
 
-    if add_log_tail:
-        f = open("%s/%s.stdout" % (gitroot, failed_tag), 'r')
+    log_stdout = "%s/%s.stdout" % (gitroot, failed_tag)
+    if add_log_tail and os.access(log_stdout, os.R_OK):
+        f = open(log_stdout, 'r')
         lines = f.readlines()
         log_tail = "".join(lines[-50:])
         num_lines = len(lines)
-        if num_lines < 50:
+        log_stderr = "%s/%s.stderr" % (gitroot, failed_tag)
+        if num_lines < 50 and os.access(log_stderr, os.R_OK):
             # Also include stderr (compile failures) if < 50 lines of stdout
-            f = open("%s/%s.stderr" % (gitroot, failed_tag), 'r')
+            f = open(log_stderr, 'r')
             log_tail += "".join(f.readlines()[-(50 - num_lines):])
 
         text += '''