tests pass :)

pull/7810/head
Sharif Elgamal 2020-04-20 16:59:10 -07:00
parent 7de758d515
commit c81e24ea9f
1 changed files with 51 additions and 79 deletions

View File

@ -20,12 +20,9 @@ package integration
import ( import (
"context" "context"
"encoding/json"
"os/exec" "os/exec"
"strings" "strings"
"testing" "testing"
"k8s.io/minikube/cmd/minikube/cmd"
) )
func TestMultiNode(t *testing.T) { func TestMultiNode(t *testing.T) {
@ -44,11 +41,11 @@ func TestMultiNode(t *testing.T) {
name string name string
validator validatorFunc validator validatorFunc
}{ }{
{"StartWithParam", validateStart}, {"FreshStart2Nodes", validateMultiNodeStart},
{"AddNode", validateAddNode}, {"AddNode", validateAddNodeToMultiNode},
{"StopNode", validateStopNode}, {"StopNode", validateStopRunningNode},
{"StartNode", validateStartNode}, {"StartAfterStop", validateStartNodeAfterStop},
{"DeleteNode", validateDeleteNode}, {"DeleteNode", validateDeleteNodeFromMultiNode},
} }
for _, tc := range tests { for _, tc := range tests {
tc := tc tc := tc
@ -59,7 +56,7 @@ func TestMultiNode(t *testing.T) {
}) })
} }
func validateStart(ctx context.Context, t *testing.T, profile string) { func validateMultiNodeStart(ctx context.Context, t *testing.T, profile string) {
// Start a 2 node cluster with the --nodes param // Start a 2 node cluster with the --nodes param
startArgs := append([]string{"start", "-p", profile, "--wait=true", "--nodes=2"}, StartArgs()...) startArgs := append([]string{"start", "-p", profile, "--wait=true", "--nodes=2"}, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...)) rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
@ -83,7 +80,7 @@ func validateStart(ctx context.Context, t *testing.T, profile string) {
} }
func validateAddNode(ctx context.Context, t *testing.T, profile string) { func validateAddNodeToMultiNode(ctx context.Context, t *testing.T, profile string) {
// Add a node to the current cluster // Add a node to the current cluster
addArgs := []string{"node", "add", "-p", profile, "-v", "3", "--alsologtostderr"} addArgs := []string{"node", "add", "-p", profile, "-v", "3", "--alsologtostderr"}
rr, err := Run(t, exec.CommandContext(ctx, Target(), addArgs...)) rr, err := Run(t, exec.CommandContext(ctx, Target(), addArgs...))
@ -98,86 +95,67 @@ func validateAddNode(ctx context.Context, t *testing.T, profile string) {
} }
if strings.Count(rr.Stdout.String(), "host: Running") != 3 { if strings.Count(rr.Stdout.String(), "host: Running") != 3 {
t.Errorf("status says both hosts are not running: args %q: %v", rr.Command(), rr.Stdout.String()) t.Errorf("status says all hosts are not running: args %q: %v", rr.Command(), rr.Stdout.String())
} }
if strings.Count(rr.Stdout.String(), "kubelet: Running") != 3 { if strings.Count(rr.Stdout.String(), "kubelet: Running") != 3 {
t.Errorf("status says both kubelets are not running: args %q: %v", rr.Command(), rr.Stdout.String()) t.Errorf("status says all kubelets are not running: args %q: %v", rr.Command(), rr.Stdout.String())
} }
} }
func validateStopNode(ctx context.Context, t *testing.T, profile string) { func validateStopRunningNode(ctx context.Context, t *testing.T, profile string) {
// Grab a worker node name
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status", "--output", "json"))
if err != nil {
t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
}
sts := []cmd.Status{}
err = json.Unmarshal(rr.Stdout.Bytes(), &sts)
if len(sts) != 3 {
t.Fatalf("status has the incorrect number of nodes: args %q: %v", rr.Command(), rr.Stdout.String())
}
// Names are autogenerated using the node.Name() function // Names are autogenerated using the node.Name() function
name := "m02" name := "m03"
// Run minikube node stop on that node // Run minikube node stop on that node
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "node", "stop", name)) rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "node", "stop", name))
if err != nil { if err != nil {
t.Errorf("node stop returned an error. args %q: %v", rr.Command(), err) t.Errorf("node stop returned an error. args %q: %v", rr.Command(), err)
} }
// Run status again to see the stopped host // Run status again to see the stopped host
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status", "--output", "json")) rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status"))
if err != nil { // Exit code 7 means one host is stopped, which we are expecting
if err != nil && rr.ExitCode != 7 {
t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err) t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
} }
stopped := 0 // Make sure minikube status shows 2 running nodes and 1 stopped one
for _, st := range sts { rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status"))
if st.Host == "Stopped" { if err != nil && rr.ExitCode != 7 {
stopped += 1 t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
}
} }
if stopped == 0 { if strings.Count(rr.Stdout.String(), "kubelet: Running") != 2 {
t.Errorf("no nodes were stopped: %v", rr.Stdout.String()) t.Errorf("incorrect number of running kubelets: args %q: %v", rr.Command(), rr.Stdout.String())
} else if stopped > 1 { }
t.Errorf("too many nodes were stopped: %v", rr.Stdout.String())
if strings.Count(rr.Stdout.String(), "host: Stopped") != 1 {
t.Errorf("incorrect number of stopped hosts: args %q: %v", rr.Command(), rr.Stdout.String())
}
if strings.Count(rr.Stdout.String(), "kubelet: Stopped") != 1 {
t.Errorf("incorrect number of stopped kubelets: args %q: %v", rr.Command(), rr.Stdout.String())
} }
} }
func validateStartNode(ctx context.Context, t *testing.T, profile string) { func validateStartNodeAfterStop(ctx context.Context, t *testing.T, profile string) {
// TODO (#7496): remove skip once restarts work
t.Skip("Restarting nodes is broken :(")
// Grab the stopped node // Grab the stopped node
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status", "--output", "json")) name := "m03"
if err != nil {
t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
}
sts := []cmd.Status{}
err = json.Unmarshal(rr.Stdout.Bytes(), &sts)
if len(sts) != 3 {
t.Fatalf("status has the incorrect number of nodes: args %q: %v", rr.Command(), rr.Stdout.String())
}
var name string
for _, st := range sts {
if st.Host == "Stopped" {
name = st.Name
}
}
if name == "" {
t.Fatalf("Could not find stopped node")
}
// Start the node back up // Start the node back up
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "node", "start", name)) rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "node", "start", name))
if err != nil { if err != nil {
t.Errorf("node stop returned an error. args %q: %v", rr.Command(), err) t.Errorf("node start returned an error. args %q: %v", rr.Command(), err)
}
// Make sure minikube status shows 3 running hosts
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status"))
if err != nil {
t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
} }
if strings.Count(rr.Stdout.String(), "host: Running") != 3 { if strings.Count(rr.Stdout.String(), "host: Running") != 3 {
@ -189,27 +167,21 @@ func validateStartNode(ctx context.Context, t *testing.T, profile string) {
} }
} }
func validateDeleteNode(ctx context.Context, t *testing.T, profile string) { func validateDeleteNodeFromMultiNode(ctx context.Context, t *testing.T, profile string) {
// Grab a worker node name name := "m03"
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status", "--output", "json"))
if err != nil {
t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
}
sts := []cmd.Status{}
err = json.Unmarshal(rr.Stdout.Bytes(), &sts)
if len(sts) != 3 {
t.Fatalf("status has the incorrect number of nodes: args %q: %v", rr.Command(), rr.Stdout.String())
}
name := "m02"
// Start the node back up // Start the node back up
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "node", "delete", name)) rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "node", "delete", name))
if err != nil { if err != nil {
t.Errorf("node stop returned an error. args %q: %v", rr.Command(), err) t.Errorf("node stop returned an error. args %q: %v", rr.Command(), err)
} }
// Make sure status is back down to 2 hosts
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status"))
if err != nil {
t.Fatalf("failed to run minikube status. args %q : %v", rr.Command(), err)
}
if strings.Count(rr.Stdout.String(), "host: Running") != 2 { if strings.Count(rr.Stdout.String(), "host: Running") != 2 {
t.Errorf("status says both hosts are not running: args %q: %v", rr.Command(), rr.Stdout.String()) t.Errorf("status says both hosts are not running: args %q: %v", rr.Command(), rr.Stdout.String())
} }