From fdc23832cc6dac142b696a8c6675ed788f45ad94 Mon Sep 17 00:00:00 2001 From: danfengl Date: Wed, 21 Sep 2022 02:26:00 +0000 Subject: [PATCH] Fix issue of fail to get command output for test verification When running velero backup/restore command, if the command result is "PartiallyFailed", it won't reture error as design, but we do need to know the debug information to figure out the reason, so the command output is needed to get the command result, then further action will be taken. Signed-off-by: danfengl --- test/e2e/util/velero/velero_utils.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/e2e/util/velero/velero_utils.go b/test/e2e/util/velero/velero_utils.go index e7bc0404e..9b68024a8 100644 --- a/test/e2e/util/velero/velero_utils.go +++ b/test/e2e/util/velero/velero_utils.go @@ -431,17 +431,19 @@ func VeleroScheduleCreate(ctx context.Context, veleroCLI string, veleroNamespace func VeleroCmdExec(ctx context.Context, veleroCLI string, args []string) error { cmd := exec.CommandContext(ctx, veleroCLI, args...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + var errBuf, outBuf bytes.Buffer + cmd.Stderr = io.MultiWriter(os.Stderr, &errBuf) + cmd.Stdout = io.MultiWriter(os.Stdout, &outBuf) fmt.Printf("velero cmd =%v\n", cmd) err := cmd.Run() - if strings.Contains(fmt.Sprint(cmd.Stdout), "Failed") { + retAll := outBuf.String() + " " + errBuf.String() + if strings.Contains(strings.ToLower(retAll), "failed") { return errors.New(fmt.Sprintf("velero cmd =%v return with failure\n", cmd)) } if err != nil { return err } - return err + return nil } func VeleroBackupLogs(ctx context.Context, veleroCLI string, veleroNamespace string, backupName string) error {