Skip to content

Commit 7819ec2

Browse files
ckyrouacjeckersb
authored andcommitted
tmt: Print journals for failed units
Include each failed unit's journal in test output to make failures easier to diagnose. Assisted-by: AI Signed-off-by: ckyrouac <ckyrouac@redhat.com>
1 parent d01e723 commit 7819ec2

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎tmt/tests/booted/readonly/014-test-no-failed-units.nu‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ let failed = if $selinux_enabled {
3636

3737
if ($failed | length) > 0 {
3838
print $"Failed units:\n($failed | str join "\n")"
39+
for unit in ($failed | each { |l| $l | split row " " | first }) {
40+
print $"Journal for ($unit):"
41+
let journal = (try {
42+
do { ^journalctl --boot --unit $unit --no-pager } | complete
43+
} catch {|e|
44+
null
45+
})
46+
if $journal == null {
47+
print "# Unable to collect journal output"
48+
} else {
49+
if ($journal.stdout | str trim) != "" {
50+
print $journal.stdout
51+
}
52+
if ($journal.stderr | str trim) != "" {
53+
print $"journalctl stderr: ($journal.stderr)"
54+
}
55+
if $journal.exit_code != 0 {
56+
print $"journalctl exited with status ($journal.exit_code)"
57+
}
58+
}
59+
}
3960
assert equal ($failed | length) 0 "Expected zero failed systemd-*/bootc-* units"
4061
}
4162

0 commit comments

Comments
 (0)