From 08ed1975b3e7ca58228eeb1bcd360341c7d1acb0 Mon Sep 17 00:00:00 2001 From: sinhaashish Date: Wed, 24 Jul 2024 06:12:38 +0000 Subject: [PATCH] test: refactor tests Signed-off-by: sinhaashish --- tests/provision_test.go | 77 ++++++++++++++++++++++++++--------------- tests/utils.go | 77 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 30 deletions(-) diff --git a/tests/provision_test.go b/tests/provision_test.go index 276e64729..4aec84992 100644 --- a/tests/provision_test.go +++ b/tests/provision_test.go @@ -27,36 +27,59 @@ var _ = Describe("[zfspv] TEST VOLUME PROVISIONING", func() { }) func fsVolCreationTest() { - fstypes := []string{"zfs", "ext4", "xfs", "btrfs"} - for _, fstype := range fstypes { - By("####### Creating the storage class : " + fstype + " #######") - createFstypeStorageClass(fstype) - By("creating and verifying PVC bound status", createAndVerifyPVC) - By("Creating and deploying app pod", createDeployVerifyApp) - By("verifying ZFSVolume object", VerifyZFSVolume) - By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit) - - createSnapshot(pvcName, snapName) - verifySnapshotCreated(snapName) - createClone(clonePvcName, snapName, scObj.Name) - By("Creating and deploying clone app pod", createDeployVerifyCloneApp) - - // btrfs does not support online resize - if fstype != "btrfs" { - By("Resizing the PVC", resizeAndVerifyPVC) - } - By("Deleting clone and main application deployment") - deleteAppDeployment(cloneAppName) - deleteAppDeployment(appName) - - By("Deleting snapshot, main pvc and clone pvc") - deletePVC(clonePvcName) - deleteSnapshot(pvcName, snapName) - deletePVC(pvcName) - By("Deleting storage class", deleteStorageClass) + storageClass := getStoragClassParams() + for _, params := range storageClass { + exhaustiveVolumeTests(params) } } +// Test to cater create, snapshot, clone and delete resources +func exhaustiveVolumeTests(parameters map[string]string) { + fstype := parameters["fstype"] + create(parameters) + snapshotAndCloneCreate() + // btrfs does not support online resize + if fstype != "btrfs" { + By("Resizing the PVC", resizeAndVerifyPVC) + } + snapshotAndCloneCleanUp() + cleanUp() +} + +// Creates the resources +func create(parameters map[string]string) { + By("####### Creating the storage class : " + parameters["fstype"] + " #######") + createFstypeStorageClass(parameters) + By("creating and verifying PVC bound status", createAndVerifyPVC) + By("Creating and deploying app pod", createDeployVerifyApp) + By("verifying ZFSVolume object", VerifyZFSVolume) + By("verifying storage class parameters") + VerifyStorageClassParams(parameters) + +} + +// Creates the snapshot/clone resources +func snapshotAndCloneCreate() { + createSnapshot(pvcName, snapName) + verifySnapshotCreated(snapName) + createClone(clonePvcName, snapName, scObj.Name) + By("Creating and deploying clone app pod", createDeployVerifyCloneApp) +} + +// Removes the snapshot/clone resources +func snapshotAndCloneCleanUp() { + deleteAppDeployment(cloneAppName) + deletePVC(clonePvcName) + deleteSnapshot(pvcName, snapName) +} + +// Removes the resources +func cleanUp() { + deleteAppDeployment(appName) + deletePVC(pvcName) + By("Deleting storage class", deleteStorageClass) +} + func blockVolCreationTest() { By("Creating default storage class", createStorageClass) By("creating and verifying PVC bound status", createAndVerifyBlockPVC) diff --git a/tests/utils.go b/tests/utils.go index e598b23ad..0b5053bd7 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -106,17 +106,34 @@ func IsPVCDeletedEventually(pvcName string) bool { Should(gomega.BeTrue()) } -func createFstypeStorageClass(ftype string) { +// 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 createFstypeStorageClass(addons map[string]string) { var ( err error ) parameters := map[string]string{ "poolname": POOLNAME, - "fstype": ftype, } - ginkgo.By("building a " + ftype + " storage class") + // Update params with addons + for key, value := range addons { + parameters[key] = value + } + + ginkgo.By("building a " + addons["ftype"] + " storage class") scObj, err = sc.NewBuilder(). WithGenerateName(scName). WithVolumeExpansion(true). @@ -585,3 +602,57 @@ func deletePVC(pvcname string) { status := IsPVCDeletedEventually(pvcname) gomega.Expect(status).To(gomega.Equal(true), "while trying to get deleted pvc") } + +func getStoragClassParams() []map[string]string { + return []map[string]string{ + { + "fstype": "zfs", + "compression": "lz4", + }, + { + "fstype": "zfs", + "compression": "lz4", + "dedup": "on", + }, + { + "fstype": "zfs", + "compression": "zstd-6", + "dedup": "on", + "thinprovision": "yes", + }, + { + "fstype": "zfs", + "dedup": "on", + }, + { + "fstype": "zfs", + "compression": "gzip", + "thinprovision": "yes", + }, + { + "fstype": "zfs", + "compression": "gzip", + "dedup": "on", + "thinprovision": "yes", + }, + { + "fstype": "xfs", + "compression": "zstd-6", + }, + { + "fstype": "xfs", + "compression": "zstd-6", + "dedup": "on", + "thinprovision": "yes", + }, + { + "fstype": "ext4", + "dedup": "on", + }, + { + "fstype": "btrfs", + "compression": "zstd-6", + "dedup": "on", + }, + } +}