From 735e8da3051bee539b190221f3c58e8e52a2e37c Mon Sep 17 00:00:00 2001 From: dlorenc Date: Wed, 29 Jun 2016 14:52:10 -0700 Subject: [PATCH] Add an integration test for cluster persistence. --- test/integration/addons_test.go | 4 +- test/integration/cluster_dns_test.go | 6 +-- test/integration/persistence_test.go | 69 ++++++++++++++++++++++++++++ test/integration/util/util.go | 10 ++++ 4 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 test/integration/persistence_test.go diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 8b3489e6a7..79372c4dec 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -31,7 +31,6 @@ import ( ) var ( - addonManagerCmd = []string{"get", "pods", "--namespace=kube-system"} dashboardRcCmd = []string{"get", "rc", "kubernetes-dashboard", "--namespace=kube-system"} dashboardSvcCmd = []string{"get", "svc", "kubernetes-dashboard", "--namespace=kube-system"} ) @@ -55,9 +54,8 @@ func TestAddons(t *testing.T) { if strings.HasPrefix(p.ObjectMeta.Name, "kube-addon-manager-") { if p.Status.Phase == "Running" { return nil - } else { - return fmt.Errorf("Pod is not Running. Status: %s", p.Status.Phase) } + return fmt.Errorf("Pod is not Running. Status: %s", p.Status.Phase) } } diff --git a/test/integration/cluster_dns_test.go b/test/integration/cluster_dns_test.go index 1eb61c0bce..ffc55e1caa 100644 --- a/test/integration/cluster_dns_test.go +++ b/test/integration/cluster_dns_test.go @@ -50,11 +50,9 @@ func TestClusterDNS(t *testing.T) { } defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath, "--namespace=" + podNamespace}) - p := api.Pod{} + p := &api.Pod{} for p.Status.Phase != "Running" { - if err := kubectlRunner.RunCommandParseOutput([]string{"get", "pod", podName, "--namespace=" + podNamespace}, &p); err != nil { - return err - } + p = kubectlRunner.GetPod(podName, podNamespace) } dnsByteArr, err := kubectlRunner.RunCommand([]string{"exec", podName, "--namespace=" + podNamespace, diff --git a/test/integration/persistence_test.go b/test/integration/persistence_test.go new file mode 100644 index 0000000000..87d6a09e11 --- /dev/null +++ b/test/integration/persistence_test.go @@ -0,0 +1,69 @@ +// +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" + + "k8s.io/kubernetes/pkg/api" + commonutil "k8s.io/minikube/pkg/util" + + "k8s.io/minikube/test/integration/util" +) + +func TestPersistence(t *testing.T) { + minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t} + minikubeRunner.EnsureRunning() + + kubectlRunner := util.NewKubectlRunner(t) + podName := "busybox" + podPath, _ := filepath.Abs("testdata/busybox.yaml") + + podNamespace := kubectlRunner.CreateRandomNamespace() + defer kubectlRunner.DeleteNamespace(podNamespace) + + // Create a pod and wait for it to be running. + if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath, "--namespace=" + podNamespace}); err != nil { + t.Fatalf("Error creating test pod: %s", err) + } + + p := &api.Pod{} + for p.Status.Phase != "Running" { + p = kubectlRunner.GetPod(podName, podNamespace) + time.Sleep(time.Second) + } + + // Now restart minikube and make sure the pod is still there. + minikubeRunner.RunCommand("stop", true) + minikubeRunner.CheckStatus("Stopped") + + minikubeRunner.RunCommand("start", true) + minikubeRunner.CheckStatus("Running") + + checkPod := func() error { + _, err := kubectlRunner.RunCommand( + []string{"get", "pod", podName, "--namespace", podNamespace}) + return err + } + if err := commonutil.RetryAfter(5, checkPod, 3*time.Second); err != nil { + t.Fatalf("Error checking the status of pod %s. Err: %s", podName, err) + } +} diff --git a/test/integration/util/util.go b/test/integration/util/util.go index a19b322b34..c7357c0e5a 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -29,6 +29,8 @@ import ( "strings" "testing" "time" + + "k8s.io/kubernetes/pkg/api" ) type MinikubeRunner struct { @@ -148,3 +150,11 @@ func (k *KubectlRunner) DeleteNamespace(namespace string) error { _, err := k.RunCommand([]string{"delete", "namespace", namespace}) return err } + +func (k *KubectlRunner) GetPod(name, namespace string) *api.Pod { + p := &api.Pod{} + if err := k.RunCommandParseOutput([]string{"get", "pod", name, "--namespace=" + namespace}, p); err != nil { + k.T.Fatalf("Error checking pod status: %s", err) + } + return p +}