Move e2e SSH utils to e2e/ssh package; improve SSH logging.

This commit is contained in:
Max Forbes
2015-07-23 16:44:09 -07:00
parent 45def3f3f3
commit e24ab02f05
9 changed files with 153 additions and 89 deletions

View File

@@ -21,6 +21,7 @@ import (
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/test/e2e/ssh"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -41,7 +42,7 @@ var _ = Describe("SSH", func() {
It("should SSH to all nodes and run commands", func() {
// Get all nodes' external IPs.
By("Getting all nodes' SSH-able IP addresses")
hosts, err := NodeSSHHosts(c)
hosts, err := ssh.NodeSSHHosts(c)
if err != nil {
Failf("Error getting node hostnames: %v", err)
}
@@ -65,7 +66,7 @@ var _ = Describe("SSH", func() {
for _, testCase := range testCases {
By(fmt.Sprintf("SSH'ing to all nodes and running %s", testCase.cmd))
for _, host := range hosts {
stdout, stderr, code, err := SSH(testCase.cmd, host, testContext.Provider)
stdout, stderr, code, err := ssh.SSH(testCase.cmd, host, testContext.Provider)
stdout, stderr = strings.TrimSpace(stdout), strings.TrimSpace(stderr)
if err != testCase.expectedError {
Failf("Ran %s on %s, got error %v, expected %v", testCase.cmd, host, err, testCase.expectedError)
@@ -79,19 +80,12 @@ var _ = Describe("SSH", func() {
if code != testCase.expectedCode {
Failf("Ran %s on %s, got exit code %d, expected %d", testCase.cmd, host, code, testCase.expectedCode)
}
// Show stdout, stderr for logging purposes.
if len(stdout) > 0 {
Logf("Got stdout from %s: %s", host, strings.TrimSpace(stdout))
}
if len(stderr) > 0 {
Logf("Got stderr from %s: %s", host, strings.TrimSpace(stderr))
}
}
}
// Quickly test that SSH itself errors correctly.
By("SSH'ing to a nonexistent host")
if _, _, _, err = SSH(`echo "hello"`, "i.do.not.exist", testContext.Provider); err == nil {
if _, _, _, err = ssh.SSH(`echo "hello"`, "i.do.not.exist", testContext.Provider); err == nil {
Failf("Expected error trying to SSH to nonexistent host.")
}
})