Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move from daemon_restart.go to framework/util.go #45423

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 3 additions & 11 deletions test/e2e/daemon_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
17 changes: 13 additions & 4 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ const (

// Serve hostname image name
ServeHostnameImage = "gcr.io/google_containers/serve_hostname:v1.4"
// ssh port
sshPort = "22"
)

var (
Expand Down Expand Up @@ -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
}
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a move? I don't see it being removed from somewhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh! Thanks. Somehow daemon_restart.go didn't get commited.

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.
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -5382,7 +5391,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
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down