← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~hyask/autopkgtest-cloud:skia/improve_logtail into autopkgtest-cloud:master

 

Skia has proposed merging ~hyask/autopkgtest-cloud:skia/improve_logtail into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/464129

This adds the first five lines of logs, in addition to what is currently displayed for each running job.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/improve_logtail into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker
index 17906e3..7321cfd 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker/worker
@@ -494,9 +494,20 @@ def send_status_info(
         params = {}
         logtail = "Running private test"
     else:
+        logtail = ""
         # print('status_info:', release, architecture, pkgname, out_dir, running)
         try:
             with open(os.path.join(out_dir, "log"), "rb") as f:
+                # Always get the first 5 lines, as they are very valuable when
+                # debugging problematic jobs
+                logtail += f.readline().decode()
+                logtail += f.readline().decode()
+                logtail += f.readline().decode()
+                logtail += f.readline().decode()
+                logtail += f.readline().decode()
+                logtail += "\n[...]\n"
+
+                # Now get the tail of the log
                 try:
                     f.seek(-2000, os.SEEK_END)
                     # throw away the first line as we almost surely cut that out in
@@ -505,9 +516,9 @@ def send_status_info(
                 except IOError:
                     # file is smaller than 2000 bytes? okay
                     pass
-                logtail = f.read().decode("UTF-8", errors="replace")
+                logtail += f.read().decode("UTF-8", errors="replace")
         except (IOError, OSError) as e:
-            logtail = "Cannot read log file: %s" % e
+            logtail += "\nError reading log file: %s" % e
 
     msg = json.dumps(
         {