From 8fd8564acd45bf057f89ddc8e215192477ea0a47 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Sat, 25 Feb 2017 19:05:07 -0800 Subject: [PATCH] Add an integration test for pvcs. --- hack/jenkins/common.sh | 1 + test/integration/functional_test.go | 1 + test/integration/pv_test.go | 67 +++++++++++++++++++++++++++++ test/integration/testdata/pvc.yaml | 10 +++++ 4 files changed, 79 insertions(+) create mode 100644 test/integration/pv_test.go create mode 100644 test/integration/testdata/pvc.yaml diff --git a/hack/jenkins/common.sh b/hack/jenkins/common.sh index 207752f13a..54cb1ef4f5 100644 --- a/hack/jenkins/common.sh +++ b/hack/jenkins/common.sh @@ -29,6 +29,7 @@ mkdir -p out/ testdata/ gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/minikube-${OS_ARCH} out/ gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/e2e-${OS_ARCH} out/ gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox.yaml testdata/ +gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/pvc.yaml testdata/ # Set the executable bit on the e2e binary and out binary chmod +x out/e2e-${OS_ARCH} diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index ab9176bf07..7e4639ae16 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -40,4 +40,5 @@ func TestFunctional(t *testing.T) { t.Run("Addons", testAddons) t.Run("Dashboard", testDashboard) t.Run("ServicesList", testServicesList) + t.Run("Provisioning", testProvisioning) } diff --git a/test/integration/pv_test.go b/test/integration/pv_test.go new file mode 100644 index 0000000000..2eba6f2964 --- /dev/null +++ b/test/integration/pv_test.go @@ -0,0 +1,67 @@ +// +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 ( + "fmt" + "path/filepath" + "testing" + "time" + + "k8s.io/kubernetes/pkg/api" + commonutil "k8s.io/minikube/pkg/util" + "k8s.io/minikube/test/integration/util" +) + +var ( + pvcName = "testpvc" + pvcCmd = []string{"get", "pvc", pvcName} +) + +func testProvisioning(t *testing.T) { + t.Parallel() + kubectlRunner := util.NewKubectlRunner(t) + + defer func() { + kubectlRunner.RunCommand([]string{"delete", "pvc", pvcName}) + }() + + pvcPath, _ := filepath.Abs("testdata/pvc.yaml") + + if _, err := kubectlRunner.RunCommand([]string{"create", "-f", pvcPath}); err != nil { + t.Fatalf("Error creating pvc") + } + + checkStorage := func() error { + pvc := api.PersistentVolumeClaim{} + if err := kubectlRunner.RunCommandParseOutput(pvcCmd, &pvc); err != nil { + return &commonutil.RetriableError{Err: err} + } + // The test passes if the volume claim gets bound. + if pvc.Status.Phase == "Bound" { + return nil + } + return &commonutil.RetriableError{Err: fmt.Errorf("PV not attached to PVC: %v", pvc)} + } + + if err := commonutil.RetryAfter(25, checkStorage, 20*time.Second); err != nil { + t.Fatal("PV Creation failed with error:", err) + } + +} diff --git a/test/integration/testdata/pvc.yaml b/test/integration/testdata/pvc.yaml new file mode 100644 index 0000000000..93f487d03d --- /dev/null +++ b/test/integration/testdata/pvc.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: testpvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi \ No newline at end of file