From bfa3a0c64fa6d069ff9482fbd85dca24440fb339 Mon Sep 17 00:00:00 2001 From: Diwakar Sharma Date: Fri, 14 Jun 2024 04:36:35 +0000 Subject: [PATCH] test: create sized snapshots for filesystem and block volumes Signed-off-by: Diwakar Sharma --- deploy/sample/lvmsnapclass.yaml | 11 +++++ tests/provision_test.go | 81 +++++++++++++++++++++------------ tests/run_test.go | 18 ++++++-- 3 files changed, 79 insertions(+), 31 deletions(-) diff --git a/deploy/sample/lvmsnapclass.yaml b/deploy/sample/lvmsnapclass.yaml index f75cac60..ec73c9d6 100644 --- a/deploy/sample/lvmsnapclass.yaml +++ b/deploy/sample/lvmsnapclass.yaml @@ -6,3 +6,14 @@ metadata: snapshot.storage.kubernetes.io/is-default-class: "true" driver: local.csi.openebs.io deletionPolicy: Delete +--- +kind: VolumeSnapshotClass +apiVersion: snapshot.storage.k8s.io/v1 +metadata: + name: lvmpv-snapclass-sized + annotations: + snapshot.storage.kubernetes.io/is-default-class: "false" +driver: local.csi.openebs.io +deletionPolicy: Delete +parameters: + snapSize: 80% diff --git a/tests/provision_test.go b/tests/provision_test.go index af54c8f7..71809665 100644 --- a/tests/provision_test.go +++ b/tests/provision_test.go @@ -25,10 +25,18 @@ import ( var _ = Describe("[lvmpv] TEST VOLUME PROVISIONING", func() { Context("App is deployed with lvm driver", func() { - It("Running volume Creation Test", volumeCreationTest) + It("Running volume Creation Tests", volumeCreationTest) + It("Running volume/snapshot Capacity Tests", capacityTest) }) }) +func deleteAppAndPvc(appname string, pvcname string) { + By("Deleting the application deployment") + deleteAppDeployment(appName) + By("Deleting the PVC") + deleteAndVerifyPVC(pvcName) +} + func fsVolCreationTest() { fstypes := []string{"ext4", "xfs", "btrfs"} for _, fstype := range fstypes { @@ -40,7 +48,7 @@ func fsVolCreationTest() { resizeAndVerifyPVC(true, "8Gi") // do not resize after creating the snapshot(not supported) - createSnapshot(pvcName, snapName) + createSnapshot(pvcName, snapName, snapYAML) verifySnapshotCreated(snapName) if fstype != "btrfs" { @@ -48,19 +56,13 @@ func fsVolCreationTest() { resizeAndVerifyPVC(false, "10Gi") } - By("Deleting the application deployment") - deleteAppDeployment(appName) - - // delete PVC should succeed - By("Deleting the PVC") - deleteAndVerifyPVC(pvcName) + deleteAppAndPvc(appName, pvcName) // PV should be present after PVC deletion since snapshot is present By("Verifying that PV exists after PVC deletion") verifyPVForPVC(true, pvcName) - By("Deleting snapshot") - deleteSnapshot(pvcName, snapName) + deleteSnapshot(pvcName, snapName, snapYAML) By("Verifying that PV is deleted after snapshot deletion") verifyPVForPVC(false, pvcName) @@ -71,23 +73,19 @@ func fsVolCreationTest() { func blockVolCreationTest() { By("Creating default storage class", createStorageClass) By("creating and verifying PVC bound status", createAndVerifyBlockPVC) - By("Creating and deploying app pod", createDeployVerifyBlockApp) By("verifying LVMVolume object", VerifyLVMVolume) By("Online resizing the block volume") resizeAndVerifyPVC(true, "8Gi") By("create snapshot") - createSnapshot(pvcName, snapName) + createSnapshot(pvcName, snapName, snapYAML) By("verify snapshot") verifySnapshotCreated(snapName) - By("Deleting application deployment") - deleteAppDeployment(appName) - By("Deleting pvc") - deleteAndVerifyPVC(pvcName) + deleteAppAndPvc(appName, pvcName) By("Verifying that PV exists after PVC deletion") verifyPVForPVC(true, pvcName) By("Deleting snapshot") - deleteSnapshot(pvcName, snapName) + deleteSnapshot(pvcName, snapName, snapYAML) By("Verifying that PV is deleted after snapshot deletion") verifyPVForPVC(false, pvcName) By("Deleting storage class", deleteStorageClass) @@ -101,17 +99,14 @@ func thinVolCreationTest() { By("Online resizing the block volume") resizeAndVerifyPVC(true, "8Gi") By("create snapshot") - createSnapshot(pvcName, snapName) + createSnapshot(pvcName, snapName, snapYAML) By("verify snapshot") verifySnapshotCreated(snapName) - By("Deleting application deployment") - deleteAppDeployment(appName) - By("Deleting pvc") - deleteAndVerifyPVC(pvcName) + deleteAppAndPvc(appName, pvcName) By("Verifying that PV exists after PVC deletion") verifyPVForPVC(true, pvcName) By("Deleting snapshot") - deleteSnapshot(pvcName, snapName) + deleteSnapshot(pvcName, snapName, snapYAML) By("Verifying that PV is deleted after snapshot deletion") verifyPVForPVC(false, pvcName) By("Deleting thinProvision storage class", deleteStorageClass) @@ -124,13 +119,39 @@ func thinVolCapacityTest() { By("Creating and deploying app pod", createDeployVerifyApp) By("verifying thinpool auto-extended", VerifyThinpoolExtend) By("verifying LVMVolume object", VerifyLVMVolume) - By("Deleting application deployment") - deleteAppDeployment(appName) - By("Deleting pvc") - deleteAndVerifyPVC(pvcName) + deleteAppAndPvc(appName, pvcName) By("Deleting thinProvision storage class", deleteStorageClass) } +func sizedSnapFSTest() { + createFstypeStorageClass("ext4") + By("creating and verifying PVC bound status", createAndVerifyPVC) + By("Creating and deploying app pod", createDeployVerifyApp) + By("verifying LVMVolume object", VerifyLVMVolume) + createSnapshot(pvcName, snapName, sizedsnapYAML) + verifySnapshotCreated(snapName) + deleteAppAndPvc(appName, pvcName) + deleteSnapshot(pvcName, snapName, sizedsnapYAML) + By("Deleting storage class", deleteStorageClass) +} + +func sizedSnapBlockTest() { + By("Creating default storage class", createStorageClass) + By("creating and verifying PVC bound status", createAndVerifyPVC) + By("Creating and deploying app pod", createDeployVerifyApp) + By("verifying LVMVolume object", VerifyLVMVolume) + createSnapshot(pvcName, snapName, sizedsnapYAML) + verifySnapshotCreated(snapName) + deleteAppAndPvc(appName, pvcName) + deleteSnapshot(pvcName, snapName, sizedsnapYAML) + By("Deleting storage class", deleteStorageClass) +} + +func sizedSnapshotTest() { + By("Sized snapshot for filesystem volume", sizedSnapFSTest) + By("Sized snapshot for block volume", sizedSnapBlockTest) +} + func leakProtectionTest() { By("Creating default storage class", createStorageClass) ds := deleteNodeDaemonSet() // ensure that provisioning remains in pending state. @@ -156,6 +177,10 @@ func volumeCreationTest() { By("Running filesystem volume creation test", fsVolCreationTest) By("Running block volume creation test", blockVolCreationTest) By("Running thin volume creation test", thinVolCreationTest) - By("Running thin volume capacity test", thinVolCapacityTest) By("Running leak protection test", leakProtectionTest) } + +func capacityTest() { + By("Running thin volume capacity test", thinVolCapacityTest) + By("Running sized snapshot test", sizedSnapshotTest) +} diff --git a/tests/run_test.go b/tests/run_test.go index d1e4ffb6..0b2f16e5 100644 --- a/tests/run_test.go +++ b/tests/run_test.go @@ -37,6 +37,18 @@ spec: ` ) +const ( + sizedsnapYAML = `apiVersion: snapshot.storage.k8s.io/v1 +kind: VolumeSnapshot +metadata: + name: #snapname +spec: + volumeSnapshotClassName: lvmpv-snapclass-sized + source: + persistentVolumeClaimName: #pvcname +` +) + func execAtLocal(cmd string, input []byte, args ...string) ([]byte, []byte, error) { var stdout, stderr bytes.Buffer command := exec.Command(cmd, args...) @@ -68,17 +80,17 @@ func verifySnapshotCreated(snapName string) bool { return true } -func createSnapshot(pvcName, snapName string) { +func createSnapshot(pvcName, snapName string, snapYaml string) { By("creating snapshot for a pvc " + pvcName) - tyaml := strings.Replace(snapYAML, "#pvcname", pvcName, -1) + tyaml := strings.Replace(snapYaml, "#pvcname", pvcName, -1) yaml := strings.Replace(tyaml, "#snapname", snapName, -1) stdout, stderr, err := kubectlWithInput([]byte(yaml), "apply", "-n", OpenEBSNamespace, "-f", "-") Expect(err).ShouldNot(HaveOccurred(), "stdout=%s, stderr=%s", stdout, stderr) } -func deleteSnapshot(pvcName, snapName string) { +func deleteSnapshot(pvcName, snapName string, snapYaml string) { By("deleting the snapshot " + snapName) tyaml := strings.Replace(snapYAML, "#pvcname", pvcName, -1)