From 855a70636979f068d69232605816c8397d097b7f Mon Sep 17 00:00:00 2001 From: sinhaashish Date: Thu, 25 Jul 2024 07:15:46 +0000 Subject: [PATCH] test: add thin provision and volume type test Signed-off-by: sinhaashish --- tests/provision_test.go | 1 - tests/suite_test.go | 19 ++++++++++--------- tests/utils.go | 41 ++++++++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/tests/provision_test.go b/tests/provision_test.go index 4aec84992..aba8da779 100644 --- a/tests/provision_test.go +++ b/tests/provision_test.go @@ -55,7 +55,6 @@ func create(parameters map[string]string) { By("verifying ZFSVolume object", VerifyZFSVolume) By("verifying storage class parameters") VerifyStorageClassParams(parameters) - } // Creates the snapshot/clone resources diff --git a/tests/suite_test.go b/tests/suite_test.go index ed14574e0..d75c416c2 100644 --- a/tests/suite_test.go +++ b/tests/suite_test.go @@ -55,15 +55,16 @@ var ( clonePvcName = "zfspv-pvc-clone" cloneAppName = "busybox-zfspv-clone" - scObj *storagev1.StorageClass - deployObj *appsv1.Deployment - pvcObj *corev1.PersistentVolumeClaim - appPod *corev1.PodList - accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce} - capacity = "5368709120" // 5Gi - NewCapacity = "8Gi" // 8Gi, for testing resize - KubeConfigPath string - OpenEBSNamespace string + scObj *storagev1.StorageClass + deployObj *appsv1.Deployment + pvcObj *corev1.PersistentVolumeClaim + appPod *corev1.PodList + accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce} + capacity = "5368709120" // 5Gi + NewCapacity = "8Gi" // 8Gi, for testing resize + defaultReservation = "0" // The default value for reservation is 0 + KubeConfigPath string + OpenEBSNamespace string ) func init() { diff --git a/tests/utils.go b/tests/utils.go index 0b5053bd7..4a520ec31 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -84,7 +84,6 @@ func IsPodRunningEventually(namespace, podName string) bool { // IsPropUpdatedEventually checks if the property is updated or not eventually func IsPropUpdatedEventually(vol *apis.ZFSVolume, prop string, val string) bool { return gomega.Eventually(func() bool { - newVal, err := zfs.GetVolumeProperty(vol, prop) gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) return (newVal == val) @@ -107,16 +106,40 @@ func IsPVCDeletedEventually(pvcName string) bool { } // VerifyStorageClassParams verifies the volume properties set at creation time -func VerifyStorageClassParams(parameters map[string]string) { - for propertyKey, propertyVal := range parameters { - if propertyKey != "fstype" && propertyKey != "thinprovision" { - vol, err := ZFSClient.WithNamespace(OpenEBSNamespace). - Get(pvcObj.Spec.VolumeName, metav1.GetOptions{}) - gomega.Expect(err).To(gomega.BeNil(), "while fetching the zfs volume {%s}", vol.Name) - status := IsPropUpdatedEventually(vol, propertyKey, propertyVal) - gomega.Expect(status).To(gomega.Equal(true), "while updating {%s%}={%s%} {%s}", propertyKey, propertyVal, vol.Name) +func VerifyStorageClassParams(property map[string]string) { + vol, err := ZFSClient.WithNamespace(OpenEBSNamespace). + Get(pvcObj.Spec.VolumeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil(), "while fetching the zfs volume {%s}", vol.Name) + // Check for file system type + if property["fstype"] == "zfs" { + property["type"] = "filesystem" + } else { + property["type"] = "volume" + } + generateThinProvisionParams(property) + delete(property, "fstype") + + for propertyKey, propertyVal := range property { + status := IsPropUpdatedEventually(vol, propertyKey, propertyVal) + gomega.Expect(status).To(gomega.Equal(true), "while updating {%s%}={%s%} {%s}", propertyKey, propertyVal, vol.Name) + } + +} + +// It populates the map for thing provisioning params +// Refer https://github.com/openebs/zfs-localpv/issues/560#issuecomment-2232535073 +func generateThinProvisionParams(property map[string]string) { + if property["fstype"] == "zfs" { + property["quota"] = capacity + property["reservation"] = defaultReservation + if property["thinprovision"] == "no" { + property["reservation"] = capacity } + } else { + property["quota"] = "-" + property["reservation"] = defaultReservation } + delete(property, "thinprovision") } func createFstypeStorageClass(addons map[string]string) {