From aba31526731dc513c040e599b6a6236ad9a4fe41 Mon Sep 17 00:00:00 2001 From: Jarno Rajahalme Date: Sat, 12 Jun 2021 11:36:08 -0700 Subject: [PATCH] test: Log command output at fail level if action failed Log expected command failure at info level so that it is easier to reason about the following flow logs, if any. Always consider any stderr output as a failure and log it at fail level. Log stdout at fail level if the action failed, and at the debug level otherwise. This helps diagnoze test failures also when `--debug` is not on. Signed-off-by: Jarno Rajahalme --- connectivity/check/action.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/connectivity/check/action.go b/connectivity/check/action.go index 887c4a7a1d..b46f260730 100644 --- a/connectivity/check/action.go +++ b/connectivity/check/action.go @@ -167,23 +167,32 @@ func (a *Action) ExecInPod(ctx context.Context, cmd []string) { cmdName := cmd[0] cmdStr := strings.Join(cmd, " ") - if stderr.Len() > 0 { - a.test.Debugf("%s stderr: %s", cmdName, stderr.String()) - } else if stdout.Len() > 0 { - a.test.Debugf("%s stdout: %s", cmdName, stdout.String()) - } - if err != nil || stderr.Len() > 0 { if a.shouldSucceed() { a.Failf("command %q failed: %s", cmdStr, err) } else { - a.test.Debugf("command %q failed as expected: %s", cmdStr, err) + a.test.Infof("command %q failed as expected: %s", cmdStr, err) } } else { if !a.shouldSucceed() { a.Failf("command %q succeeded while it should have failed: %s", cmdStr, stdout.String()) } } + if stderr.Len() > 0 { + // Any stderr output is considered a test failure. + a.Failf("%s stderr: %s", cmdName, stderr.String()) + } + if stdout.Len() > 0 { + // Debug level logs are only shown when running with `--debug`, + // which is proper for succeeding actions. Log at the fail + // level when the action has failed to always log the failing + // output. + if a.failed { + a.Failf("%s stdout: %s", cmdName, stdout.String()) + } else { + a.Debugf("%s stdout: %s", cmdName, stdout.String()) + } + } } // shouldSucceed returns true if no drops are expected in either direction.