Skip to content

Commit

Permalink
verifying zfs and ext4 sc before after deplying application
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <[email protected]>
  • Loading branch information
pawanpraka1 committed Dec 3, 2019
1 parent e89873f commit b58a5b6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 50 deletions.
34 changes: 24 additions & 10 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,40 @@ import (
)

var _ = Describe("[zfspv] TEST VOLUME PROVISIONING", func() {
BeforeEach(prepareForVolumeCreationTest)
AfterEach(cleanupAfterVolumeCreationTest)

Context("App is deployed with zfs driver", func() {
It("Should run Volume Creation Test", volumeCreationTest)
It("Running zfs volume Creation Test", volumeCreationTest)
})
})

func volumeCreationTest() {
func datasetCreationTest() {
By("Creating zfs storage class", createZfsStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("verifying ZFSVolume object", VerifyZFSVolume)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying ZFSVolume object", VerifyZFSVolumeApp)
By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
By("Deleting storage class", deleteStorageClass)
}

func prepareForVolumeCreationTest() {
By("Creating storage class", createStorageClass)
}
func zvolCreationTest() {
By("Creating ext4 storage class", createExt4StorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)

func cleanupAfterVolumeCreationTest() {
/*
* commenting app deployment as provisioning is taking time
* since we are creating a zfs pool on a sparse file and mkfs
* is taking forever for zvol.
* Should create the zfs pool on the disk. Need to check if travis
* has that functionality.
*/
//By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying ZFSVolume object", VerifyZFSVolumeApp)
//By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
By("Deleting storage class", deleteStorageClass)
}

func volumeCreationTest() {
By("Running dataset creation test", datasetCreationTest)
By("Running zvol creation test", zvolCreationTest)
}
3 changes: 1 addition & 2 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ var (
appName = "busybox-zfspv"

nsObj *corev1.Namespace
scObjExt4 *storagev1.StorageClass
scObjZfs *storagev1.StorageClass
scObj *storagev1.StorageClass
deployObj *appsv1.Deployment
pvcObj *corev1.PersistentVolumeClaim
appPod *corev1.PodList
Expand Down
81 changes: 43 additions & 38 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,72 +72,77 @@ func IsPVCDeletedEventually(pvcName string) bool {
Should(BeTrue())
}

func createStorageClass() {
func createExt4StorageClass() {
var (
err error
)

parametersZfs := map[string]string{
parameters := map[string]string{
"poolname": POOLNAME,
"fstype": "zfs",
"fstype": "ext4",
}

scNameZfs := scName + "zfs"

By("building a zfs storage class")
scObjZfs, err = sc.NewBuilder().
WithGenerateName(scNameZfs).
WithParametersNew(parametersZfs).
By("building a ext4 storage class")
scObj, err = sc.NewBuilder().
WithGenerateName(scName).
WithParametersNew(parameters).
WithProvisioner(ZFSProvisioner).Build()
Expect(err).ShouldNot(HaveOccurred(),
"while building storageclass obj with prefix {%s}", scNameZfs)
"while building ext4 storageclass obj with prefix {%s}", scName)

scObjZfs, err = SCClient.Create(scObjZfs)
Expect(err).To(BeNil(), "while creating a storageclass {%s}", scNameZfs)
scObj, err = SCClient.Create(scObj)
Expect(err).To(BeNil(), "while creating a ext4 storageclass {%s}", scName)
}

func createZfsStorageClass() {
var (
err error
)

parametersExt4 := map[string]string{
parameters := map[string]string{
"poolname": POOLNAME,
"fstype": "ext4",
"fstype": "zfs",
}

scNameExt4 := scName + "ext4"

By("building a ext4 storage class")
scObjExt4, err = sc.NewBuilder().
WithGenerateName(scNameExt4).
WithParametersNew(parametersExt4).
By("building a zfs storage class")
scObj, err = sc.NewBuilder().
WithGenerateName(scName).
WithParametersNew(parameters).
WithProvisioner(ZFSProvisioner).Build()
Expect(err).ShouldNot(HaveOccurred(),
"while building storageclass obj with prefix {%s}", scNameExt4)
"while building zfs storageclass obj with prefix {%s}", scName)

scObjExt4, err = SCClient.Create(scObjExt4)
Expect(err).To(BeNil(), "while creating a storageclass {%s}", scNameExt4)
scObj, err = SCClient.Create(scObj)
Expect(err).To(BeNil(), "while creating a zfs storageclass {%s}", scName)
}

func VerifyZFSVolume() {
By("fetching zfs volume")
func VerifyZFSVolumeApp() {
By("fetching zfs volume after deploying app")
vol, err := ZFSClient.WithNamespace(openebsNamespace).
Get(pvcObj.Spec.VolumeName, metav1.GetOptions{})
Expect(err).To(BeNil(), "while fetching the zfs volume {%s}", pvcObj.Spec.VolumeName)

volType := "ZVOL"
if scObj.Parameters["fstype"] == "zfs" {
volType = "DATASET"
}

By("verifying zfs volume")
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.PoolName).To(Equal(scObj.Parameters["poolname"]),
"while checking poolname of zfs volume", pvcObj.Spec.VolumeName)
Expect(vol.Spec.FsType).To(Equal(scObj.Parameters["fstype"]),
"while checking fstype of zfs volume", pvcObj.Spec.VolumeName)
Expect(vol.Spec.VolumeType).To(Equal(volType),
"while checking Volume type as dataset", pvcObj.Spec.VolumeName)
Expect(vol.Spec.Capacity).To(Equal(capacity),
"while checking capacity of zfs volume")
"while checking capacity of zfs volume", pvcObj.Spec.VolumeName)
Expect(vol.Finalizers[0]).To(Equal("zfs.openebs.io/finalizer"), "while checking finializer to be set {%s}", pvcObj.Spec.VolumeName)
}

func deleteStorageClass() {
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{})
err := SCClient.Delete(scObj.Name, &metav1.DeleteOptions{})
Expect(err).To(BeNil(),
"while deleting ext4 storageclass {%s}", scObjExt4.Name)
"while deleting zfs storageclass {%s}", scObj.Name)
}

func createAndVerifyPVC() {
Expand All @@ -149,7 +154,7 @@ func createAndVerifyPVC() {
pvcObj, err = pvc.NewBuilder().
WithName(pvcName).
WithNamespace(openebsNamespace).
WithStorageClass(scObjZfs.Name).
WithStorageClass(scObj.Name).
WithAccessModes(accessModes).
WithCapacity(capacity).Build()
Expect(err).ShouldNot(
Expand Down

0 comments on commit b58a5b6

Please sign in to comment.