diff --git a/tests/provision_test.go b/tests/provision_test.go index ea2bc32f..736f7bd0 100644 --- a/tests/provision_test.go +++ b/tests/provision_test.go @@ -31,6 +31,7 @@ var _ = Describe("[zfspv] TEST VOLUME PROVISIONING", func() { func volumeCreationTest() { By("creating and verifying PVC bound status", createAndVerifyPVC) + By("verifying ZFSVolume object", VerifyZFSVolume) By("Creating and deploying app pod", createDeployVerifyApp) By("Deleting application deployment", deleteAppDeployment) By("Deleting pvc", deletePVC) diff --git a/tests/suite_test.go b/tests/suite_test.go index 168837ee..b720d4b2 100644 --- a/tests/suite_test.go +++ b/tests/suite_test.go @@ -30,6 +30,11 @@ import ( "testing" ) +const ( + // zfs pool name where volume provisioning will happen + POOLNAME = "zfspv-pool" +) + var ( SCClient *sc.Kubeclient PVCClient *pvc.Kubeclient @@ -43,12 +48,13 @@ var ( appName = "busybox-zfspv" nsObj *corev1.Namespace - scObj *storagev1.StorageClass + scObjExt4 *storagev1.StorageClass + scObjZfs *storagev1.StorageClass deployObj *appsv1.Deployment pvcObj *corev1.PersistentVolumeClaim appPod *corev1.PodList accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce} - capacity = "5Gi" + capacity = "5368709120" // 5Gi KubeConfigPath string ) diff --git a/tests/utils.go b/tests/utils.go index 5004728f..9dd1cc84 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -21,6 +21,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/openebs/zfs-localpv/pkg/builder" "github.com/openebs/zfs-localpv/tests/container" "github.com/openebs/zfs-localpv/tests/deploy" "github.com/openebs/zfs-localpv/tests/k8svolume" @@ -77,27 +78,66 @@ func createStorageClass() { err error ) - parameters := map[string]string{ - "poolname": "zfspv-pool", + parametersZfs := map[string]string{ + "poolname": POOLNAME, "fstype": "zfs", } - By("building a sc") - scObj, err = sc.NewBuilder(). - WithGenerateName(scName). - WithParametersNew(parameters). + scNameZfs := scName + "zfs" + + By("building a zfs storage class") + scObjZfs, err = sc.NewBuilder(). + WithGenerateName(scNameZfs). + WithParametersNew(parametersZfs). WithProvisioner(ZFSProvisioner).Build() Expect(err).ShouldNot(HaveOccurred(), - "while building storageclass obj with prefix {%s}", scName) + "while building storageclass obj with prefix {%s}", scNameZfs) + + scObjZfs, err = SCClient.Create(scObjZfs) + Expect(err).To(BeNil(), "while creating a storageclass {%s}", scNameZfs) + + parametersExt4 := map[string]string{ + "poolname": POOLNAME, + "fstype": "ext4", + } - scObj, err = SCClient.Create(scObj) - Expect(err).To(BeNil(), "while creating a storageclass {%s}", scName) + scNameExt4 := scName + "ext4" + + By("building a ext4 storage class") + scObjExt4, err = sc.NewBuilder(). + WithGenerateName(scNameExt4). + WithParametersNew(parametersExt4). + WithProvisioner(ZFSProvisioner).Build() + Expect(err).ShouldNot(HaveOccurred(), + "while building storageclass obj with prefix {%s}", scNameExt4) + + scObjExt4, err = SCClient.Create(scObjExt4) + Expect(err).To(BeNil(), "while creating a storageclass {%s}", scNameExt4) +} + +func VerifyZFSVolume() { + vol, err := builder.NewKubeclient(). + WithNamespace(openebsNamespace). + Get(pvcName, metav1.GetOptions{}) + Expect(err).To(BeNil(), "while fetching the zfs volume {%s}", pvcName) + + Expect(vol.Spec.PoolName).To(Equal(scObjZfs.Parameters["poolname"]), + "while checking poolname of zfs volume") + Expect(vol.Spec.FsType).To(Equal(scObjZfs.Parameters["fstype"]), + "while checking fstype of zfs volume") + Expect(vol.Spec.VolumeType).To(Equal("DATASET"), + "while checking Volume type as dataset") + Expect(vol.Spec.Capacity).To(Equal(capacity), + "while checking capacity of zfs volume") } func deleteStorageClass() { - err := SCClient.Delete(scObj.Name, &metav1.DeleteOptions{}) + err := SCClient.Delete(scObjZfs.Name, &metav1.DeleteOptions{}) + Expect(err).To(BeNil(), + "while deleting zfs storageclass {%s}", scObjZfs.Name) + err = SCClient.Delete(scObjExt4.Name, &metav1.DeleteOptions{}) Expect(err).To(BeNil(), - "while deleting storageclass {%s}", scObj.Name) + "while deleting ext4 storageclass {%s}", scObjExt4.Name) } func createAndVerifyPVC() { @@ -109,7 +149,7 @@ func createAndVerifyPVC() { pvcObj, err = pvc.NewBuilder(). WithName(pvcName). WithNamespace(openebsNamespace). - WithStorageClass(scObj.Name). + WithStorageClass(scObjZfs.Name). WithAccessModes(accessModes). WithCapacity(capacity).Build() Expect(err).ShouldNot(