diff --git a/test/e2e/daemon_restart.go b/test/e2e/daemon_restart.go index 12af50770ee..03e723b8b29 100644 --- a/test/e2e/daemon_restart.go +++ b/test/e2e/daemon_restart.go @@ -56,15 +56,6 @@ const ( UPDATE = "UPDATE" ) -// nodeExec execs the given cmd on node via SSH. Note that the nodeName is an sshable name, -// eg: the name returned by framework.GetMasterHost(). This is also not guaranteed to work across -// cloud providers since it involves ssh. -func nodeExec(nodeName, cmd string) (framework.SSHResult, error) { - result, err := framework.SSH(cmd, fmt.Sprintf("%v:%v", nodeName, sshPort), framework.TestContext.Provider) - Expect(err).NotTo(HaveOccurred()) - return result, err -} - // restartDaemonConfig is a config to restart a running daemon on a node, and wait till // it comes back up. It uses ssh to send a SIGTERM to the daemon. type restartDaemonConfig struct { @@ -100,7 +91,7 @@ func (r *restartDaemonConfig) waitUp() { "curl -s -o /dev/null -I -w \"%%{http_code}\" http://localhost:%v/healthz", r.healthzPort) err := wait.Poll(r.pollInterval, r.pollTimeout, func() (bool, error) { - result, err := nodeExec(r.nodeName, healthzCheck) + result, err := framework.NodeExec(r.nodeName, healthzCheck) framework.ExpectNoError(err) if result.Code == 0 { httpCode, err := strconv.Atoi(result.Stdout) @@ -120,7 +111,8 @@ func (r *restartDaemonConfig) waitUp() { // kill sends a SIGTERM to the daemon func (r *restartDaemonConfig) kill() { framework.Logf("Killing %v", r) - nodeExec(r.nodeName, fmt.Sprintf("pgrep %v | xargs -I {} sudo kill {}", r.daemonName)) + _, err := framework.NodeExec(r.nodeName, fmt.Sprintf("pgrep %v | xargs -I {} sudo kill {}", r.daemonName)) + Expect(err).NotTo(HaveOccurred()) } // Restart checks if the daemon is up, kills it, and waits till it comes back up diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index eb214c41e74..4933b7a5dd1 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -180,6 +180,8 @@ const ( // Serve hostname image name ServeHostnameImage = "gcr.io/google_containers/serve_hostname:v1.4" + // ssh port + sshPort = "22" ) var ( @@ -3781,7 +3783,7 @@ func NodeSSHHosts(c clientset.Interface) ([]string, error) { sshHosts := make([]string, 0, len(hosts)) for _, h := range hosts { - sshHosts = append(sshHosts, net.JoinHostPort(h, "22")) + sshHosts = append(sshHosts, net.JoinHostPort(h, sshPort)) } return sshHosts, nil } @@ -3795,6 +3797,13 @@ type SSHResult struct { Code int } +// NodeExec execs the given cmd on node via SSH. Note that the nodeName is an sshable name, +// eg: the name returned by framework.GetMasterHost(). This is also not guaranteed to work across +// cloud providers since it involves ssh. +func NodeExec(nodeName, cmd string) (SSHResult, error) { + return SSH(cmd, net.JoinHostPort(nodeName, sshPort), TestContext.Provider) +} + // SSH synchronously SSHs to a node running on provider and runs cmd. If there // is no error performing the SSH, the stdout, stderr, and exit code are // returned. @@ -3835,7 +3844,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*SSHResult, host := "" for _, a := range node.Status.Addresses { if a.Type == v1.NodeExternalIP { - host = a.Address + ":22" + host = net.JoinHostPort(a.Address, sshPort) break } } @@ -4413,7 +4422,7 @@ func sshRestartMaster() error { command = "sudo /etc/init.d/kube-apiserver restart" } Logf("Restarting master via ssh, running: %v", command) - result, err := SSH(command, GetMasterHost()+":22", TestContext.Provider) + result, err := SSH(command, net.JoinHostPort(GetMasterHost(), sshPort), TestContext.Provider) if err != nil || result.Code != 0 { LogSSHResult(result) return fmt.Errorf("couldn't restart apiserver: %v", err) @@ -5381,7 +5390,7 @@ func GetNodeExternalIP(node *v1.Node) string { host := "" for _, a := range node.Status.Addresses { if a.Type == v1.NodeExternalIP { - host = a.Address + ":22" + host = net.JoinHostPort(a.Address, sshPort) break } } diff --git a/test/e2e/kubelet.go b/test/e2e/kubelet.go index b23ba045f5d..a8f6da78a23 100644 --- a/test/e2e/kubelet.go +++ b/test/e2e/kubelet.go @@ -261,7 +261,8 @@ func checkPodCleanup(c clientset.Interface, pod *v1.Pod, expectClean bool) { for _, test := range tests { framework.Logf("Wait up to %v for host's (%v) %q to be %v", timeout, nodeIP, test.feature, condMsg) err = wait.Poll(poll, timeout, func() (bool, error) { - result, _ := nodeExec(nodeIP, test.cmd) + result, err := framework.NodeExec(nodeIP, test.cmd) + Expect(err).NotTo(HaveOccurred()) framework.LogSSHResult(result) ok := (result.Code == 0 && len(result.Stdout) > 0 && len(result.Stderr) == 0) if expectClean && ok { // keep trying