Move framework ssh code to new package

The framework/ssh.go code was heavily used throughout the framework
and could be useful elsewhere but reusing those methods requires
importing all of the framework.

Extracting these methods to their own package for reuse.

Only a few methods had to be copied into this package from the
rest of the framework to avoid an import cycle.
This commit is contained in:
John Schnake
2019-05-01 11:53:13 -05:00
parent 22b6c69983
commit 338bc3ce42
32 changed files with 259 additions and 119 deletions

View File

@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
. "github.com/onsi/ginkgo"
)
@@ -33,7 +34,7 @@ var _ = SIGDescribe("SSH", func() {
f := framework.NewDefaultFramework("ssh")
BeforeEach(func() {
// When adding more providers here, also implement their functionality in util.go's framework.GetSigner(...).
// When adding more providers here, also implement their functionality in e2essh.GetSigner(...).
framework.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
// This test SSH's into the node for which it needs the $HOME/.ssh/id_rsa key to be present. So
@@ -44,7 +45,7 @@ var _ = SIGDescribe("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 := framework.NodeSSHHosts(f.ClientSet)
hosts, err := e2essh.NodeSSHHosts(f.ClientSet)
if err != nil {
framework.Failf("Error getting node hostnames: %v", err)
}
@@ -78,7 +79,7 @@ var _ = SIGDescribe("SSH", func() {
By(fmt.Sprintf("SSH'ing to %d nodes and running %s", len(testhosts), testCase.cmd))
for _, host := range testhosts {
result, err := framework.SSH(testCase.cmd, host, framework.TestContext.Provider)
result, err := e2essh.SSH(testCase.cmd, host, framework.TestContext.Provider)
stdout, stderr := strings.TrimSpace(result.Stdout), strings.TrimSpace(result.Stderr)
if err != testCase.expectedError {
framework.Failf("Ran %s on %s, got error %v, expected %v", testCase.cmd, host, err, testCase.expectedError)
@@ -104,7 +105,7 @@ var _ = SIGDescribe("SSH", func() {
// Quickly test that SSH itself errors correctly.
By("SSH'ing to a nonexistent host")
if _, err = framework.SSH(`echo "hello"`, "i.do.not.exist", framework.TestContext.Provider); err == nil {
if _, err = e2essh.SSH(`echo "hello"`, "i.do.not.exist", framework.TestContext.Provider); err == nil {
framework.Failf("Expected error trying to SSH to nonexistent host.")
}
})