Skip to content

Commit

Permalink
test(compression): add compressing algo test
Browse files Browse the repository at this point in the history
Signed-off-by: sinhaashish <[email protected]>
  • Loading branch information
sinhaashish committed Jul 18, 2024
1 parent 1c4a810 commit bac4d06
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 29 deletions.
102 changes: 79 additions & 23 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,28 @@ 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)
parameters := getStoragClassParams(fstype, "", "")
exhaustiveVolumeTests(fstype, parameters)

// verify the different compression type
compression := []string{"on", "lzjb", "zstd-19", "gzip-9", "zle", "lz4", "off"}
for _, compressionValue := range compression {
By("####### Creating the storage class : " + fstype + " and compression as " + compressionValue + " #######")
parameters = getStoragClassParams(fstype, "compression", compressionValue)
minimalVolumeTest("compression", compressionValue, parameters)
}

// verify the ddedup functionality
dedup := []string{"on", "off"}
for _, dedupValue := range dedup {
By("####### Creating the storage class : " + fstype + " and dedup as " + dedupValue + " #######")
parameters = getStoragClassParams(fstype, "dedup", dedupValue)
minimalVolumeTest("dedup", dedupValue, parameters)
}
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)
}
}

Expand All @@ -75,3 +70,64 @@ func volumeCreationTest() {
By("Running volume creation test", fsVolCreationTest)
By("Running block volume creation test", blockVolCreationTest)
}

// Test to cater create and delete resources
func minimalVolumeTest(property, property_value string, parameters map[string]string) {
create(parameters)
VerifyStorageClassParams(property, property_value)
cleanUp()
}

// Returns a map to be consumed by storage class
func getStoragClassParams(fstype, key, value string) map[string]string {
parameters := map[string]string{
"poolname": POOLNAME,
"fstype": fstype,
}
if len(key) != 0 && len(value) != 0 {
parameters[key] = value
}
return parameters
}

// Test to cater create, snapshot, clone and delete resources
func exhaustiveVolumeTests(fstype string, parameters map[string]string) {
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) {
createFstypeStorageClass(parameters)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying ZFSVolume object", VerifyZFSVolume)
}

// 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)
}
23 changes: 17 additions & 6 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package tests

import (
"encoding/json"
"time"

"github.com/onsi/ginkgo"
Expand Down Expand Up @@ -84,6 +85,7 @@ 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 {
print(vol)

newVal, err := zfs.GetVolumeProperty(vol, prop)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
Expand All @@ -106,17 +108,15 @@ func IsPVCDeletedEventually(pvcName string) bool {
Should(gomega.BeTrue())
}

func createFstypeStorageClass(ftype string) {
func createFstypeStorageClass(parameters map[string]string) {
var (
err error
)

parameters := map[string]string{
"poolname": POOLNAME,
"fstype": ftype,
}
// Convert the map to a JSON string
paramAsString, _ := json.Marshal(parameters)

ginkgo.By("building a " + ftype + " storage class")
ginkgo.By("building a storage class with given params" + string(paramAsString))
scObj, err = sc.NewBuilder().
WithGenerateName(scName).
WithVolumeExpansion(true).
Expand Down Expand Up @@ -176,10 +176,21 @@ func VerifyZFSVolume() {
gomega.Expect(vol.Finalizers[0]).To(gomega.Equal(zfs.ZFSFinalizer), "while checking finializer to be set {%s}", pvcObj.Spec.VolumeName)
}

// VerifyStorageClassParams verifies the volume properties set at creation time
func VerifyStorageClassParams(property, propertyVal 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)
status := IsPropUpdatedEventually(vol, property, propertyVal)
gomega.Expect(status).To(gomega.Equal(true), "while updating {%s%}={%s%} {%s}", property, propertyVal, vol.Name)
}

// VerifyZFSVolumePropEdit verifies the volume properties
func VerifyZFSVolumePropEdit() {
ginkgo.By("verifying compression property update")

println(" Inside VerifyZFSVolumePropEdit ashish {%s}", pvcObj.Spec.VolumeName)

ginkgo.By("fetching zfs volume for setting compression=on")
vol, err := ZFSClient.WithNamespace(OpenEBSNamespace).
Get(pvcObj.Spec.VolumeName, metav1.GetOptions{})
Expand Down

0 comments on commit bac4d06

Please sign in to comment.