mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Merge pull request #10770 from mbforbes/streamOutput
Cluster upgrade: make command calling stream stdout/stderr.
This commit is contained in:
commit
cfb10b5a5b
@ -19,8 +19,10 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -440,20 +442,22 @@ func retryCmd(command string, args ...string) (string, string, error) {
|
|||||||
return stdout, stderr, err
|
return stdout, stderr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// runCmd runs cmd using args and returns stdout and stderr.
|
// runCmd runs cmd using args and returns its stdout and stderr. It also outputs
|
||||||
|
// cmd's stdout and stderr to their respective OS streams.
|
||||||
func runCmd(command string, args ...string) (string, string, error) {
|
func runCmd(command string, args ...string) (string, string, error) {
|
||||||
Logf("Running %s %v", command, args)
|
Logf("Running %s %v", command, args)
|
||||||
var bout, berr bytes.Buffer
|
var bout, berr bytes.Buffer
|
||||||
cmd := exec.Command(command, args...)
|
cmd := exec.Command(command, args...)
|
||||||
cmd.Stdout, cmd.Stderr = &bout, &berr
|
// We also output to the OS stdout/stderr to aid in debugging in case cmd
|
||||||
|
// hangs and never retruns before the test gets killed.
|
||||||
|
cmd.Stdout = io.MultiWriter(os.Stdout, &bout)
|
||||||
|
cmd.Stderr = io.MultiWriter(os.Stderr, &berr)
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
stdout, stderr := bout.String(), berr.String()
|
stdout, stderr := bout.String(), berr.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", fmt.Errorf("error running %s %v; got error %v, stdout %q, stderr %q",
|
return "", "", fmt.Errorf("error running %s %v; got error %v, stdout %q, stderr %q",
|
||||||
command, args, err, stdout, stderr)
|
command, args, err, stdout, stderr)
|
||||||
}
|
}
|
||||||
Logf("stdout: %s", stdout)
|
|
||||||
Logf("stderr: %s", stderr)
|
|
||||||
return stdout, stderr, nil
|
return stdout, stderr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user