Skip to content

Commit 3b39e7e

Browse files
author
Harish Kumar
committed
stream output as the script run
1 parent 0f02ed2 commit 3b39e7e

File tree

4 files changed

+84
-14
lines changed

4 files changed

+84
-14
lines changed

mkosi.images/base/mkosi.extra/usr/share/mangos/recovery_test.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ tpm_slot=$(cryptsetup luksDump /dev/$test_device | \
2525
tr -d ':')
2626

2727
echo "Removing TPM keyslot ${tpm_slot} (simulating TPM failure)..."
28-
PASSWORD="$recovery_key" systemd-cryptenroll --wipe-slot=tpm2 /dev/$test_device
28+
# Provide the recovery key on stdin so systemd-cryptenroll does not prompt interactively.
29+
# Use --unlock-key-file=/dev/stdin to read the key from stdin when wiping the TPM slot.
30+
printf '%s' "$recovery_key" | systemd-cryptenroll --wipe-slot=tpm2 --unlock-key-file=/dev/stdin /dev/$test_device
2931

3032

3133
# Get mount point for this partition
@@ -56,7 +58,8 @@ echo "Data accessible after recovery: OK"
5658

5759
# Re-enroll TPM (cleanup for future tests)
5860
echo "Re-enrolling TPM keyslot..."
59-
echo -n "$recovery_key" | systemd-cryptenroll /dev/$test_device \
61+
# Re-enroll by supplying the recovery key on stdin (non-interactive)
62+
printf '%s' "$recovery_key" | systemd-cryptenroll /dev/$test_device \
6063
--tpm2-device=auto \
6164
--tpm2-pcrs=7 \
6265
--tpm2-public-key-pcrs=11 \

mkosi.images/base/mkosi.extra/usr/share/mangos/self_test.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,30 @@ fi
6161

6262
echo 'Testing LUKS recovery functionality'
6363

64-
timeout 120 /usr/share/mangos/recovery_test.sh
64+
# Run recovery_test with verbose tracing and capture output for debugging when it hangs.
65+
# Use a temp logfile under /var/log so it persists in the VM for inspection.
66+
diag_log=/var/log/recovery_test.log
67+
rm -f "$diag_log" || true
68+
echo "Starting recovery_test at $(date -u +%FT%T%z)" > "$diag_log"
69+
70+
# Run the test with bash -x under timeout; capture both stdout and stderr.
71+
# We avoid `set -e` killing the script immediately so we can dump logs on failure.
72+
set +e
73+
timeout 120 bash -x /usr/share/mangos/recovery_test.sh >> "$diag_log" 2>&1
74+
rc=$?
75+
set -e
76+
77+
echo "recovery_test exited with code: $rc" >> "$diag_log"
78+
echo "--- Last 200 lines of recovery_test log ---"
79+
tail -n 200 "$diag_log" || true
80+
81+
echo "--- Relevant journal entries (cryptsetup, systemd-cryptenroll, verity) ---"
82+
journalctl -n 200 --no-pager -u systemd-cryptsetup@* -u systemd-veritysetup@* -u systemd-cryptenroll.service 2>/dev/null || true
83+
84+
if [ $rc -ne 0 ]; then
85+
echo "Recovery test failed (rc=$rc); see $diag_log inside the VM for full output"
86+
exit $rc
87+
fi
6588

6689
#if /usr/share/mangos/recovery_test.sh; then
6790
echo "LUKS recovery test: PASSED"

recovery_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ tpm_slot=$(cryptsetup luksDump /dev/$test_device | \
2424
tr -d ':')
2525

2626
echo "Removing TPM keyslot ${tpm_slot} (simulating TPM failure)..."
27-
PASSWORD="$recovery_key" systemd-cryptenroll --wipe-slot=tpm2 /dev/$test_device
27+
# Provide the recovery key on stdin so systemd-cryptenroll does not prompt interactively.
28+
# Use --unlock-key-file=/dev/stdin to read the key from stdin when wiping the TPM slot.
29+
printf '%s' "$recovery_key" | systemd-cryptenroll --wipe-slot=tpm2 --unlock-key-file=/dev/stdin /dev/$test_device
2830

2931

3032
# Get mount point for this partition

run_tests.sh

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,59 @@ $systemd_run -u "mangos-test-${testid}-socat" -d -p SuccessExitStatus=130 -q --w
264264

265265
step ssh into VM
266266

267-
if $systemd_run -d --wait -q -p StandardOutput=journal -- ssh -i ./mkosi.key \
268-
-o UserKnownHostsFile=/dev/null \
269-
-o StrictHostKeyChecking=no \
270-
-o LogLevel=ERROR \
271-
-o ProxyCommand="mkosi sandbox -- socat - VSOCK-CONNECT:42:%p" \
272-
root@mkosi 'mangosctl --base-url=http://10.0.2.2:8081 updatectl add-overrides ; /usr/share/mangos/self_test.sh'
273-
then
267+
# Stream the remote self-test live to the workflow console and also save to a logfile
268+
diag_ssh_out="${tmpdir}/self_test_ssh.out"
269+
echo "Streaming remote self-test output to ${diag_ssh_out}"
270+
271+
# Use direct ssh (with forced tty) so output is streamed live. Save output with tee.
272+
# Run ssh+tee in background and tail the logfile in foreground so CI logs show live output
273+
ssh_cmd=(ssh -tt -i ./mkosi.key
274+
-o UserKnownHostsFile=/dev/null
275+
-o StrictHostKeyChecking=no
276+
-o LogLevel=ERROR
277+
-o ProxyCommand="mkosi sandbox -- socat - VSOCK-CONNECT:42:%p"
278+
root@mkosi "bash -lc 'mangosctl --base-url=http://10.0.2.2:8081 updatectl add-overrides ; /usr/share/mangos/self_test.sh'")
279+
280+
# Ensure diag file exists
281+
touch "${diag_ssh_out}"
282+
283+
# Trap to clean child processes on exit
284+
cleanup_ssh_tail() {
285+
if [ -n "${ssh_pid:-}" ]; then
286+
kill "${ssh_pid}" 2>/dev/null || true
287+
fi
288+
if [ -n "${tail_pid:-}" ]; then
289+
kill "${tail_pid}" 2>/dev/null || true
290+
fi
291+
}
292+
trap cleanup_ssh_tail EXIT
293+
294+
# Start ssh pipeline in background, using stdbuf to avoid buffering
295+
stdbuf -oL "${ssh_cmd[@]}" 2>&1 | stdbuf -oL tee "${diag_ssh_out}" &
296+
ssh_pid=$!
297+
298+
# Give ssh/tee a moment to start writing, then tail the logfile to stream live output
299+
sleep 1
300+
tail -n +1 -f "${diag_ssh_out}" &
301+
tail_pid=$!
302+
303+
# Wait for ssh to finish
304+
wait ${ssh_pid}
305+
ssh_rc=$?
306+
307+
# Stop tailing
308+
kill ${tail_pid} 2>/dev/null || true
309+
wait ${tail_pid} 2>/dev/null || true
310+
311+
trap - EXIT
312+
313+
if [ ${ssh_rc} -eq 0 ]; then
274314
success
275-
$systemd_run -u "mangos-test-${testid}-result" -q -- echo "Mangos test ${testid} succeeded"
315+
echo "Mangos test ${testid} succeeded" | $systemd_run -q -u "mangos-test-${testid}-result" -- cat
276316
else
277317
failure
278-
$systemd_run -u "mangos-test-${testid}-result" -q -- echo "Mangos test ${testid} failed"
279-
exit 1
318+
echo "Mangos test ${testid} failed" | $systemd_run -q -u "mangos-test-${testid}-result" -- cat
319+
echo "--- Tail of remote self-test output (last 200 lines) ---"
320+
tail -n 200 "${diag_ssh_out}" || true
321+
exit ${ssh_rc}
280322
fi

0 commit comments

Comments
 (0)