2016-06-29 21:52:10 +00:00
|
|
|
// +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"
|
|
|
|
|
2017-05-18 16:56:07 +00:00
|
|
|
"github.com/docker/machine/libmachine/state"
|
2016-06-29 21:52:10 +00:00
|
|
|
"k8s.io/minikube/test/integration/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPersistence(t *testing.T) {
|
2019-07-26 22:27:05 +00:00
|
|
|
if isTestNoneDriver() {
|
2019-07-30 04:52:05 +00:00
|
|
|
t.Skip("skipping test as none driver does not support persistence")
|
2019-07-26 22:27:05 +00:00
|
|
|
}
|
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)
|
2019-07-30 05:17:03 +00:00
|
|
|
defer mk.TearDown(t)
|
2019-07-12 18:50:57 +00:00
|
|
|
mk.EnsureRunning()
|
2016-06-29 21:52:10 +00:00
|
|
|
|
2019-07-24 02:05:57 +00:00
|
|
|
kr := util.NewKubectlRunner(t, p)
|
2016-06-29 21:52:10 +00:00
|
|
|
|
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)
|
2016-06-29 21:52:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 05:00:57 +00:00
|
|
|
verifyBusybox := func(t *testing.T) {
|
2019-07-24 19:38:40 +00:00
|
|
|
if err := util.WaitForBusyboxRunning(t, "default", p); err != nil {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("waiting for busybox to be up: %v", err)
|
2016-07-12 17:50:44 +00:00
|
|
|
}
|
2016-07-18 22:35:37 +00:00
|
|
|
|
|
|
|
}
|
2017-08-23 18:33:00 +00:00
|
|
|
// Make sure everything is up before we stop.
|
2019-07-27 05:00:57 +00:00
|
|
|
verifyBusybox(t)
|
2017-08-23 18:33:00 +00:00
|
|
|
|
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)
|
2019-07-12 18:50:57 +00:00
|
|
|
return mk.CheckStatusNoFail(state.Stopped.String())
|
2017-02-22 03:27:51 +00:00
|
|
|
}
|
2017-08-23 15:51:14 +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 {
|
2019-07-30 02:19:56 +00:00
|
|
|
t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", t.Name(), err, stdout, stderr)
|
2019-07-30 00:57:36 +00:00
|
|
|
}
|
2019-07-12 18:50:57 +00:00
|
|
|
mk.CheckStatus(state.Running.String())
|
2016-07-18 22:35:37 +00:00
|
|
|
|
2017-08-23 18:33:00 +00:00
|
|
|
// Make sure the same things come up after we've restarted.
|
2019-07-27 05:00:57 +00:00
|
|
|
verifyBusybox(t)
|
2016-06-29 21:52:10 +00:00
|
|
|
}
|