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
This commit is contained in:
Debarshi Ray 2023-09-21 18:55:20 +02:00
parent 6e5bffe9a0
commit a7feb00996

View file

@ -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"
}