minikube/test/integration/persistence_test.go

73 lines
2.0 KiB
Go
Raw Normal View History

// +build integration
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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
http://www.apache.org/licenses/LICENSE-2.0
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 (
"path/filepath"
"testing"
"time"
"github.com/docker/machine/libmachine/state"
"k8s.io/minikube/test/integration/util"
)
func TestPersistence(t *testing.T) {
if isTestNoneDriver() {
2019-07-30 04:52:05 +00:00
t.Skip("skipping test as none driver does not support persistence")
}
2019-07-30 04:52:05 +00:00
t.Parallel()
p := profile(t) // profile name
2019-07-27 05:00:57 +00:00
mk := NewMinikubeRunner(t, p)
defer mk.TearDown(t)
mk.EnsureRunning()
2019-07-24 02:05:57 +00:00
kr := util.NewKubectlRunner(t, p)
2019-07-27 05:00:57 +00:00
if _, err := kr.RunCommand([]string{"create", "-f", filepath.Join(*testdataDir, "busybox.yaml")}); err != nil {
t.Fatalf("creating busybox pod: %s", err)
}
2019-07-27 05:00:57 +00:00
verifyBusybox := func(t *testing.T) {
if err := util.WaitForBusyboxRunning(t, "default", p); err != nil {
t.Fatalf("waiting for busybox to be up: %v", err)
}
2016-07-18 22:35:37 +00:00
}
// Make sure everything is up before we stop.
2019-07-27 05:00:57 +00:00
verifyBusybox(t)
2016-07-18 22:35:37 +00:00
// Now restart minikube and make sure the pod is still there.
2017-02-22 03:27:51 +00:00
checkStop := func() error {
2019-07-27 05:00:57 +00:00
mk.RunCommand("stop", false)
return mk.CheckStatusNoFail(state.Stopped.String())
2017-02-22 03:27:51 +00:00
}
if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil {
2019-07-27 05:00:57 +00:00
t.Fatalf("TestPersistence Failed to stop minikube : %v", err)
2017-02-22 03:27:51 +00:00
}
2016-07-18 22:35:37 +00:00
2019-07-30 07:22:01 +00:00
stdout, stderr, err := mk.Start()
2019-07-30 00:57:36 +00:00
if err != nil {
t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", t.Name(), err, stdout, stderr)
2019-07-30 00:57:36 +00:00
}
mk.CheckStatus(state.Running.String())
2016-07-18 22:35:37 +00:00
// Make sure the same things come up after we've restarted.
2019-07-27 05:00:57 +00:00
verifyBusybox(t)
}