Merge pull request #4339 from zmerlynn/issue_4177

Fix hack/e2e.go exit status for -test
This commit is contained in:
Filipe Brandenburger
2015-02-11 13:21:37 -08:00

View File

@@ -146,21 +146,21 @@ func main() {
} }
} }
failure := false success := true
switch { switch {
case *ctlCmd != "": case *ctlCmd != "":
ctlArgs := strings.Fields(*ctlCmd) ctlArgs := strings.Fields(*ctlCmd)
os.Setenv("KUBE_CONFIG_FILE", "config-test.sh") os.Setenv("KUBE_CONFIG_FILE", "config-test.sh")
failure = !finishRunning("'kubectl "+*ctlCmd+"'", exec.Command(path.Join(versionRoot, "cluster/kubectl.sh"), ctlArgs...)) success = finishRunning("'kubectl "+*ctlCmd+"'", exec.Command(path.Join(versionRoot, "cluster/kubectl.sh"), ctlArgs...))
case *test: case *test:
failure = Test() success = Test()
} }
if *down { if *down {
TearDown() TearDown()
} }
if failure { if !success {
os.Exit(1) os.Exit(1)
} }
} }
@@ -277,8 +277,8 @@ func Test() bool {
// call the returned anonymous function to stop. // call the returned anonymous function to stop.
func runBashUntil(stepName string, cmd *exec.Cmd) func() { func runBashUntil(stepName string, cmd *exec.Cmd) func() {
log.Printf("Running in background: %v", stepName) log.Printf("Running in background: %v", stepName)
stdout, stderr := bytes.NewBuffer(nil), bytes.NewBuffer(nil) output := bytes.NewBuffer(nil)
cmd.Stdout, cmd.Stderr = stdout, stderr cmd.Stdout, cmd.Stderr = output, output
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
log.Printf("Unable to start '%v': '%v'", stepName, err) log.Printf("Unable to start '%v': '%v'", stepName, err)
return func() {} return func() {}
@@ -287,7 +287,7 @@ func runBashUntil(stepName string, cmd *exec.Cmd) func() {
cmd.Process.Signal(os.Interrupt) cmd.Process.Signal(os.Interrupt)
headerprefix := stepName + " " headerprefix := stepName + " "
lineprefix := " " lineprefix := " "
printBashOutputs(headerprefix, lineprefix, string(stdout.Bytes()), string(stderr.Bytes()), false) printBashOutputs(headerprefix, lineprefix, string(output.Bytes()), false)
} }
} }
@@ -327,44 +327,11 @@ func finishRunning(stepName string, cmd *exec.Cmd) bool {
return result return result
} }
func printBashOutputs(headerprefix, lineprefix, stdout, stderr string, escape bool) { func printBashOutputs(headerprefix, lineprefix, output string, escape bool) {
// The |'s (plus appropriate prefixing) are to make this look if output != "" {
// "YAMLish" to the Jenkins TAP plugin: fmt.Printf("%voutput: |\n", headerprefix)
// https://wiki.jenkins-ci.org/display/JENKINS/TAP+Plugin printPrefixedLines(lineprefix, output)
if stdout != "" {
fmt.Printf("%vstdout: |\n", headerprefix)
if escape {
stdout = escapeOutput(stdout)
}
printPrefixedLines(lineprefix, stdout)
} }
if stderr != "" {
fmt.Printf("%vstderr: |\n", headerprefix)
if escape {
stderr = escapeOutput(stderr)
}
printPrefixedLines(lineprefix, stderr)
}
}
// Escape stdout/stderr so the Jenkins YAMLish parser doesn't barf on
// it. This escaping is crude (it masks all colons as something humans
// will hopefully see as a colon, for instance), but it should get the
// job done without pulling in a whole YAML package.
func escapeOutput(s string) (out string) {
for _, r := range s {
switch {
case r == '\n':
out += string(r)
case !strconv.IsPrint(r):
out += " "
case r == ':':
out += "\ua789" // "", modifier letter colon
default:
out += string(r)
}
}
return
} }
func printPrefixedLines(prefix, s string) { func printPrefixedLines(prefix, s string) {