From a7feb009967a4a1418c831793819a605f968e72d Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 21 Sep 2023 18:55:20 +0200 Subject: [PATCH] test/system: Make it easier to debug why a container didn't initialize Currently, if a Toolbx container's entry point fails to initialize the container, there's no way to see the debug logs and error messages from the entry point: not ok 106 container: Check container starts without issues # (from function `assert_success' in file test/system/libs/bats-assert/src/assert.bash, line 114, # in test file test/system/103-container.bats, line 39) # `assert_success' failed # # -- command failed -- # status : 1 # output : # -- # Instead, from now on, they will be visible: not ok 106 container: Check container starts without issues # (from function `assert_success' in file test/system/libs/bats-assert/src/assert.bash, line 114, # in test file test/system/103-container.bats, line 39) # `assert_success' failed # # -- command failed -- # status : 1 # output (90 lines): # Failed to initialize container fedora-toolbox-38 # level=debug msg="Running as real user ID 0" # level=debug msg="Resolved absolute path to the executable as /usr/bin/toolbox" # level=debug msg="TOOLBOX_PATH is /opt/bin/toolbox" # level=debug msg="Migrating to newer Podman" # level=debug msg="Migration not needed: running inside a container" # level=debug msg="Setting up configuration" # ... # -- # https://github.com/containers/toolbox/pull/1374 --- test/system/libs/helpers.bash | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index 482cf92..7283799 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -449,8 +449,6 @@ function container_started() { # shellcheck disable=SC2154 if [ "$status" -ne 0 ]; then fail "Failed to invoke '$PODMAN logs'" - [ "$output" != "" ] && echo "$output" - [ "$stderr" != "" ] && echo "$stderr" >&2 ret_val="$status" break fi @@ -465,6 +463,15 @@ function container_started() { sleep 1 done + if [ "$ret_val" -ne 0 ]; then + if [ "$j" -eq "$num_of_retries" ]; then + fail "Failed to initialize container $container_name" + fi + + [ "$output" != "" ] && echo "$output" + [ "$stderr" != "" ] && echo "$stderr" >&2 + fi + return "$ret_val" }