tests/int: fix error handling and logging #2548
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR: this allows to show logs from failed runc restore.
Bats scripts are run with
set -e
. This is well known and obvious,and yet there are a few errors with respect to that, including a few
"gems" by yours truly :(
bats scripts are run with
set -e
, meaning that[ $? -eq 0 ]
isuseless since the execution won't ever reach this line in case of
non-zero exit code from a preceding command. So, remove all such
checks, they are useless and misleading.
bats scripts are run with
set -e
, meaning thatret=$?
is uselesssince the execution won't ever reach this line in case of non-zero
exit code from a preceding command.
In particular, the code that calls runc restore needs to save the exit
code, show the errors in the log, and only when check the exit code and
fail if it's non-zero. It can not use
run
(orrunc
which usesrun
)because of shell redirection that we need to set up.
The solution, implemented in this patch, is to use code like this:
In case
__runc ...
fails (i.e. exits with non-zero exit code),ret=$?
isexecuted, and it always succeeds, so we won't fail just yet and have
a chance to show logs before checking the value of $ret.
In case
__runc ...
succeeds,ret=$?
is never executed, so$ret
will stillbe zero (this is the reason why it needs to be set explicitly).
Should help with investigating #2475