Skip to content

Commit

Permalink
Merge pull request #570 from sinhaashish/tests
Browse files Browse the repository at this point in the history
test: refactor tests
  • Loading branch information
sinhaashish authored Jul 24, 2024
2 parents d4c1903 + 08ed197 commit dddfa93
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 30 deletions.
77 changes: 50 additions & 27 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 74 additions & 3 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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",
},
}
}

0 comments on commit dddfa93

Please sign in to comment.