start_stop_delete_test.go 2.5 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", []string{
43
			"--feature-gates",
44
			"ServerSideApply=true",
45 46 47 48 49 50
			fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
		}},
		{"containerd", []string{
			"--container-runtime=containerd",
			"--docker-opt containerd=/var/run/containerd/containerd.sock",
		}},
51
		{"crio_ignore_preflights", []string{
52
			"--container-runtime=crio",
53 54
			"--extra-config",
			"kubeadm.ignore-preflight-errors=SystemVerification",
55
		}},
56
	}
D
dlorenc 已提交
57

58
	for _, test := range tests {
59 60 61 62
		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)
63
			}
D
dlorenc 已提交
64

65 66 67 68 69
			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 已提交
70

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

77
			checkStop := func() error {
78 79
				r.RunCommand("stop", true)
				return r.CheckStatusNoFail(state.Stopped.String())
80 81 82 83 84
			}

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

86
			r.Start(test.args...)
87
			r.CheckStatus(state.Running.String())
D
dlorenc 已提交
88

89 90
			r.RunCommand("delete", true)
			r.CheckStatus(state.None.String())
91 92
		})
	}
D
dlorenc 已提交
93
}