tests/int: fix error handling and logging#2548
Merged
mrunalp merged 1 commit intoopencontainers:masterfrom Aug 10, 2020
Merged
Conversation
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. 1. bats scripts are run with `set -e`, meaning that `[ $? -eq 0 ]` is useless 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. 2. bats scripts are run with `set -e`, meaning that `ret=$?` is useless since 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` (or `runc` which uses `run`) because of shell redirection that we need to set up. The solution, implemented in this patch, is to use code like this: ```bash ret=0 __runc ... || ret=$? show_logs [ $ret -eq 0 ] ``` In case __runc exits with non-zero exit code, `ret=$?` is executed, 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 still be zero (this is the reason why it needs to be set explicitly). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Closed
Contributor
Author
Contributor
|
Makes sense, thanks for fixing this! |
AkihiroSuda
approved these changes
Aug 9, 2020
Contributor
|
Nice. LGTM. |
mrunalp
approved these changes
Aug 10, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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(orruncwhich 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$retwill stillbe zero (this is the reason why it needs to be set explicitly).
Should help with investigating #2475