Skip to content

Commit

Permalink
test: add thin provision and volume type test
Browse files Browse the repository at this point in the history
Signed-off-by: sinhaashish <ashi.sinha.87@gmail.com>
  • Loading branch information
sinhaashish committed Jul 25, 2024
1 parent dddfa93 commit 855a706
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
1 change: 0 additions & 1 deletion tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
41 changes: 32 additions & 9 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 855a706

Please sign in to comment.