未验证 提交 63933c1b 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #8024 from medyagh/breakdown_start_stop

integration test: break-down TestStartStop to sub-tests
......@@ -80,15 +80,14 @@ func TestStartStop(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
MaybeParallel(t)
profile := UniqueProfileName(tc.name)
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
defer Cleanup(t, profile, cancel)
type validateStartStopFunc func(context.Context, *testing.T, string, string, string, []string)
if !strings.Contains(tc.name, "docker") && NoneDriver() {
t.Skipf("skipping %s - incompatible with none driver", t.Name())
}
profile := UniqueProfileName(tc.name)
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
defer CleanupWithLogs(t, profile, cancel)
waitFlag := "--wait=true"
if strings.Contains(tc.name, "cni") { // wait=app_running is broken for CNI https://github.com/kubernetes/minikube/issues/7354
waitFlag = "--wait=apiserver,system_pods,default_sa"
......@@ -98,80 +97,140 @@ func TestStartStop(t *testing.T) {
startArgs = append(startArgs, StartArgs()...)
startArgs = append(startArgs, fmt.Sprintf("--kubernetes-version=%s", tc.version))
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
t.Fatalf("failed starting minikube -first start-. args %q: %v", rr.Command(), err)
}
t.Run("serial", func(t *testing.T) {
serialTests := []struct {
name string
validator validateStartStopFunc
}{
{"FirstStart", validateFirstStart},
{"DeployApp", validateDeploying},
{"Stop", validateStop},
{"EnableAddonAfterStop", validateEnableAddonAfterStop},
{"SecondStart", validateSecondStart},
{"UserAppExistsAfterStop", validateAppExistsAfterStop},
{"AddonExistsAfterStop", validateAddonAfterStop},
{"VerifyKubernetesImages", validateKubernetesImages},
{"Pause", validatePauseAfterSart},
}
for _, stc := range serialTests {
tcName := tc.name
tcVersion := tc.version
stc := stc
t.Run(stc.name, func(t *testing.T) {
stc.validator(ctx, t, profile, tcName, tcVersion, startArgs)
})
}
if !strings.Contains(tc.name, "cni") {
testPodScheduling(ctx, t, profile)
}
if *cleanup {
// Normally handled by cleanuprofile, but not fatal there
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
if err != nil {
t.Errorf("failed to clean up: args %q: %v", rr.Command(), err)
}
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "config", "get-contexts", profile))
if err != nil {
t.Logf("config context error: %v (may be ok)", err)
}
if rr.ExitCode != 1 {
t.Errorf("expected exit code 1, got %d. output: %s", rr.ExitCode, rr.Output())
}
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile, "--alsologtostderr", "-v=3"))
if err != nil {
t.Fatalf("failed stopping minikube - first stop-. args %q : %v", rr.Command(), err)
}
})
// The none driver never really stops
if !NoneDriver() {
got := Status(ctx, t, Target(), profile, "Host")
if got != state.Stopped.String() {
t.Fatalf("expected post-stop host status to be -%q- but got *%q*", state.Stopped, got)
}
}
})
}
})
}
// Enable an addon to assert it comes up afterwards
rr, err = Run(t, exec.CommandContext(ctx, Target(), "addons", "enable", "dashboard", "-p", profile))
if err != nil {
t.Fatalf("failed to enable an addon post-stop. args %q: %v", rr.Command(), err)
}
func validateFirstStart(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
t.Fatalf("failed starting minikube -first start-. args %q: %v", rr.Command(), err)
}
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
// Explicit fatal so that failures don't move directly to deletion
t.Fatalf("failed to start minikube post-stop. args %q: %v", rr.Command(), err)
}
func validateDeploying(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
if !strings.Contains(tcName, "cni") {
testPodScheduling(ctx, t, profile)
}
}
if strings.Contains(tc.name, "cni") {
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
} else {
if _, err := PodWait(ctx, t, profile, "default", "integration-test=busybox", Minutes(7)); err != nil {
t.Fatalf("failed waiting for pod 'busybox' post-stop-start: %v", err)
}
if _, err := PodWait(ctx, t, profile, "kubernetes-dashboard", "k8s-app=kubernetes-dashboard", Minutes(9)); err != nil {
t.Fatalf("failed waiting for 'addon dashboard' pod post-stop-start: %v", err)
}
}
func validateStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
rr, err := Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile, "--alsologtostderr", "-v=3"))
if err != nil {
t.Fatalf("failed stopping minikube - first stop-. args %q : %v", rr.Command(), err)
}
}
got := Status(ctx, t, Target(), profile, "Host")
if got != state.Running.String() {
t.Fatalf("expected host status after start-stop-start to be -%q- but got *%q*", state.Running, got)
}
func validateEnableAddonAfterStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
// The none driver never really stops
if !NoneDriver() {
got := Status(ctx, t, Target(), profile, "Host")
if got != state.Stopped.String() {
t.Errorf("expected post-stop host status to be -%q- but got *%q*", state.Stopped, got)
}
}
if !NoneDriver() {
testPulledImages(ctx, t, profile, tc.version)
}
// Enable an addon to assert it comes up afterwards
rr, err := Run(t, exec.CommandContext(ctx, Target(), "addons", "enable", "dashboard", "-p", profile))
if err != nil {
t.Errorf("failed to enable an addon post-stop. args %q: %v", rr.Command(), err)
}
testPause(ctx, t, profile)
}
if *cleanup {
// Normally handled by cleanuprofile, but not fatal there
rr, err = Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
if err != nil {
t.Errorf("failed to clean up: args %q: %v", rr.Command(), err)
}
func validateSecondStart(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
// Explicit fatal so that failures don't move directly to deletion
t.Fatalf("failed to start minikube post-stop. args %q: %v", rr.Command(), err)
}
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "config", "get-contexts", profile))
if err != nil {
t.Logf("config context error: %v (may be ok)", err)
}
if rr.ExitCode != 1 {
t.Errorf("expected exit code 1, got %d. output: %s", rr.ExitCode, rr.Output())
}
}
})
}
})
got := Status(ctx, t, Target(), profile, "Host")
if got != state.Running.String() {
t.Errorf("expected host status after start-stop-start to be -%q- but got *%q*", state.Running, got)
}
}
// validateAppExistsAfterStop verifies that a user's app will not vanish after a minikube stop
func validateAppExistsAfterStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
if strings.Contains(tcName, "cni") {
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
} else if _, err := PodWait(ctx, t, profile, "kubernetes-dashboard", "k8s-app=kubernetes-dashboard", Minutes(9)); err != nil {
t.Errorf("failed waiting for 'addon dashboard' pod post-stop-start: %v", err)
}
}
// validateAddonAfterStop validates that an addon which was enabled when minikube is stopped will be enabled and working..
func validateAddonAfterStop(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
if strings.Contains(tcName, "cni") {
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
} else if _, err := PodWait(ctx, t, profile, "kubernetes-dashboard", "k8s-app=kubernetes-dashboard", Minutes(9)); err != nil {
t.Errorf("failed waiting for 'addon dashboard' pod post-stop-start: %v", err)
}
}
func validateKubernetesImages(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
if !NoneDriver() {
testPulledImages(ctx, t, profile, tcVersion)
}
}
func validatePauseAfterSart(ctx context.Context, t *testing.T, profile string, tcName string, tcVersion string, startArgs []string) {
defer PostMortemLogs(t, profile)
testPause(ctx, t, profile)
}
// testPodScheduling asserts that this configuration can schedule new pods
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册