From 21bd26ebc41b4bcd9d88eb7d6473152fce3aa1ac Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 16 Jun 2020 16:36:15 +0530 Subject: [PATCH] e2e: Add E2E for ROX PVC Added E2E testing for creation and mounting of ROX PVC, if the PVC accessmode is ReadOnlyMany the application pod should not get write access to it. Signed-off-by: Madhu Rajanna --- e2e/cephfs.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index 8e0d0c2e8..9053abd55 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -5,6 +5,7 @@ import ( "strings" . "github.com/onsi/ginkgo" // nolint + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" @@ -353,6 +354,49 @@ var _ = Describe("cephfs", func() { Fail(err.Error()) } }) + + By("Create ROX PVC and Bind it to an app", func() { + // create pvc and bind it to an app + pvc, err := loadPVC(pvcPath) + if err != nil { + Fail(err.Error()) + } + + pvc.Namespace = f.UniqueName + pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany} + app, err := loadApp(appPath) + if err != nil { + Fail(err.Error()) + } + + app.Namespace = f.UniqueName + label := map[string]string{ + "app": app.Name, + } + app.Labels = label + app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name + err = createPVCAndApp("", f, pvc, app, deployTimeout) + if err != nil { + Fail(err.Error()) + } + + opt := metav1.ListOptions{ + LabelSelector: fmt.Sprintf("app=%s", app.Name), + } + + filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test" + _, stdErr := execCommandInPodAndAllowFail(f, fmt.Sprintf("echo 'Hello World' > %s", filePath), app.Namespace, &opt) + readOnlyErr := fmt.Sprintf("cannot create %s: Read-only file system", filePath) + if !strings.Contains(stdErr, readOnlyErr) { + Fail(stdErr) + } + + // delete pvc and app + err = deletePVCAndApp("", f, pvc, app) + if err != nil { + Fail(err.Error()) + } + }) // Make sure this should be last testcase in this file, because // it deletes pool By("Create a PVC and Delete PVC when backend pool deleted", func() {