Skip to content

Commit

Permalink
Fix SIG Node SSH e2e test
Browse files Browse the repository at this point in the history
This assumes that SSH via bastion works if the `KUBE_SSH_BASTION`
environment variable is set, which is the case for
`pull-kubernetes-e2e-gce-correctness`.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Jul 21, 2021
1 parent f27a086 commit af15ebf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/e2e/framework/ssh/ssh.go
Expand Up @@ -49,6 +49,9 @@ const (
// singleCallTimeout is how long to try single API calls (like 'get' or 'list'). Used to prevent
// transient failures from failing tests.
singleCallTimeout = 5 * time.Minute

// sshBastionEnvKey is the environment variable key for running SSH commands via bastion.
sshBastionEnvKey = "KUBE_SSH_BASTION"
)

// GetSigner returns an ssh.Signer for the provider ("gce", etc.) that can be
Expand Down Expand Up @@ -160,9 +163,13 @@ func NodeSSHHosts(c clientset.Interface) ([]string, error) {

// canConnect returns true if a network connection is possible to the SSHPort.
func canConnect(host string) bool {
if _, ok := os.LookupEnv(sshBastionEnvKey); ok {
return true
}
hostPort := net.JoinHostPort(host, SSHPort)
conn, err := net.DialTimeout("tcp", hostPort, 3*time.Second)
if err != nil {
e2elog.Logf("cannot dial %s: %v", hostPort, err)
return false
}
conn.Close()
Expand Down Expand Up @@ -205,7 +212,7 @@ func SSH(cmd, host, provider string) (Result, error) {
result.User = os.Getenv("USER")
}

if bastion := os.Getenv("KUBE_SSH_BASTION"); len(bastion) > 0 {
if bastion := os.Getenv(sshBastionEnvKey); len(bastion) > 0 {
stdout, stderr, code, err := runSSHCommandViaBastion(cmd, result.User, bastion, host, signer)
result.Stdout = stdout
result.Stderr = stderr
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/node/ssh.go
Expand Up @@ -49,6 +49,7 @@ var _ = SIGDescribe("SSH", func() {
if err != nil {
framework.Failf("Error getting node hostnames: %v", err)
}
ginkgo.By(fmt.Sprintf("Found %d SSH'able hosts", len(hosts)))

testCases := []struct {
cmd string
Expand Down Expand Up @@ -79,6 +80,8 @@ var _ = SIGDescribe("SSH", func() {
ginkgo.By(fmt.Sprintf("SSH'ing to %d nodes and running %s", len(testhosts), testCase.cmd))

for _, host := range testhosts {
ginkgo.By(fmt.Sprintf("SSH'ing host %s", host))

result, err := e2essh.SSH(testCase.cmd, host, framework.TestContext.Provider)
stdout, stderr := strings.TrimSpace(result.Stdout), strings.TrimSpace(result.Stderr)
if err != testCase.expectedError {
Expand Down

0 comments on commit af15ebf

Please sign in to comment.