start_stop_delete_test.go 3.3 KB
Newer Older
D
dlorenc 已提交
1 2 3
// +build integration

/*
4
Copyright 2016 The Kubernetes Authors All rights reserved.
5

D
dlorenc 已提交
6 7 8
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
9

D
dlorenc 已提交
10
    http://www.apache.org/licenses/LICENSE-2.0
11

D
dlorenc 已提交
12 13 14 15 16 17 18 19 20 21
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
22
	"fmt"
D
Dan Lorenc 已提交
23 24
	"net"
	"strings"
D
dlorenc 已提交
25
	"testing"
26
	"time"
27

A
Aaron Prindle 已提交
28
	"github.com/docker/machine/libmachine/state"
29
	"k8s.io/minikube/pkg/minikube/constants"
30
	"k8s.io/minikube/test/integration/util"
D
dlorenc 已提交
31 32 33
)

func TestStartStop(t *testing.T) {
34
	tests := []struct {
35 36
		name string
		args []string
37
	}{
38
		{"nocache_oldest", []string{
39 40 41
			"--cache-images=false",
			fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion),
		}},
42
		{"feature_gates_newest_cni", []string{
43
			"--feature-gates",
44
			"ServerSideApply=true",
45 46
			"--network-plugin=cni",
			"--extra-config=kubelet.network-plugin=cni",
47 48
			fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
		}},
49
		{"containerd_and_non_default_apiserver_port", []string{
50 51
			"--container-runtime=containerd",
			"--docker-opt containerd=/var/run/containerd/containerd.sock",
52
			"--apiserver-port=8444",
53
		}},
54
		{"crio_ignore_preflights", []string{
55
			"--container-runtime=crio",
56 57
			"--extra-config",
			"kubeadm.ignore-preflight-errors=SystemVerification",
58
		}},
59
	}
D
dlorenc 已提交
60

61
	for _, test := range tests {
62 63 64 65
		t.Run(test.name, func(t *testing.T) {
			r := NewMinikubeRunner(t)
			if !strings.Contains(test.name, "docker") && usingNoneDriver(r) {
				t.Skipf("skipping %s - incompatible with none driver", test.name)
66
			}
D
dlorenc 已提交
67

68 69 70 71 72
			r.RunCommand("config set WantReportErrorPrompt false", true)
			r.RunCommand("delete", false)
			r.CheckStatus(state.None.String())
			r.Start(test.args...)
			r.CheckStatus(state.Running.String())
D
dlorenc 已提交
73

74
			ip := r.RunCommand("ip", true)
75 76 77 78
			ip = strings.TrimRight(ip, "\n")
			if net.ParseIP(ip) == nil {
				t.Fatalf("IP command returned an invalid address: %s", ip)
			}
79

H
Himanshu Pandey 已提交
80
			// check for the current-context before and after the stop
H
Himanshu Pandey 已提交
81 82 83 84 85 86
			kubectlRunner := util.NewKubectlRunner(t)
			currentContext, err := kubectlRunner.RunCommand([]string{"config", "current-context"})
			if err != nil {
				t.Fatalf("Failed to fetch current-context")
			}
			if string(currentContext) != "minikube" {
87
				t.Fatalf("got current-context - %q, want  current-context %q", string(currentContext), "minikube")
88 89
			}

90
			checkStop := func() error {
91 92
				r.RunCommand("stop", true)
				return r.CheckStatusNoFail(state.Stopped.String())
93 94
			}

H
Himanshu Pandey 已提交
95 96 97 98 99
			currentContext, err = kubectlRunner.RunCommand([]string{"config", "current-context"})
			if err != nil {
				t.Fatalf("Failed to fetch current-context")
			}
			if string(currentContext) != "" {
100 101 102
				t.Fatalf("Failed to unset the current-context")
			}

103 104 105
			if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil {
				t.Fatalf("timed out while checking stopped status: %v", err)
			}
D
dlorenc 已提交
106

107
			r.Start(test.args...)
108
			r.CheckStatus(state.Running.String())
D
dlorenc 已提交
109

110 111
			r.RunCommand("delete", true)
			r.CheckStatus(state.None.String())
112 113
		})
	}
D
dlorenc 已提交
114
}