diff mbox series

testimage: handle missing boot log file gracefully

Message ID 20260518142235.2077-1-peter.tatrai.ext@siemens.com
State New
Headers show
Series testimage: handle missing boot log file gracefully | expand

Commit Message

P. Tatrai May 18, 2026, 2:22 p.m. UTC
From: Peter Tatrai <peter.tatrai.ext@siemens.com>

QemuRunner writes boot console output to logfile + '.2' (the primary
serial port). The primary logfile path (without extension) is used for
the secondary serial port and may not exist if QEMU does not open it.

testimage_main crashed with FileNotFoundError at open(bootlog) when
results.wasSuccessful() returned False, because the file was absent.

Fall back to the '.2' variant when the primary file does not exist.
Wrap open() in a try/except OSError so a missing log emits a warning
instead of aborting the task.

Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com>
---
 meta/classes-recipe/testimage.bbclass | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/testimage.bbclass b/meta/classes-recipe/testimage.bbclass
index 9902b8a568..1af060342f 100644
--- a/meta/classes-recipe/testimage.bbclass
+++ b/meta/classes-recipe/testimage.bbclass
@@ -415,9 +415,14 @@  def testimage_main(d):
     if not results or not complete:
         bb.error('%s - FAILED - tests were interrupted during execution, check the logs in %s' % (pn, d.getVar("LOG_DIR")), forcelog=True)
     if results and not results.wasSuccessful():
-        with open(bootlog, 'r') as bootlogfile:
-            bootlines = "".join(bootlogfile.readlines()[-20:])
-        bb.plain('%s - FAILED - Last lines of QEMU boot log:\n%s' % (pn, bootlines))
+        # QemuRunner writes boot output to bootlog + ".2"; the primary file may not exist
+        bootlog_actual = bootlog if os.path.exists(bootlog) else bootlog + ".2"
+        try:
+            with open(bootlog_actual, 'r') as bootlogfile:
+                bootlines = "".join(bootlogfile.readlines()[-20:])
+            bb.plain('%s - FAILED - Last lines of QEMU boot log:\n%s' % (pn, bootlines))
+        except OSError as e:
+            bb.warn('%s - could not read boot log: %s' % (pn, e))
         bb.error('%s - FAILED - also check the logs in %s' % (pn, d.getVar("LOG_DIR")), forcelog=True)
 
 def get_runtime_paths(d):