Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add thin provision and volume type test #572

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading