Skip to content

Commit

Permalink
test: create sized snapshots for filesystem and block volumes
Browse files Browse the repository at this point in the history
Signed-off-by: Diwakar Sharma <[email protected]>
  • Loading branch information
dsharma-dc committed Jun 14, 2024
1 parent 4a57750 commit fc34cd7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 26 deletions.
11 changes: 11 additions & 0 deletions deploy/sample/lvmsnapclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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%
72 changes: 49 additions & 23 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -40,27 +48,21 @@ 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" {
// if snapshot is there, resize should fail
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)
Expand All @@ -74,10 +76,7 @@ func blockVolCreationTest() {

By("Creating and deploying app pod", createDeployVerifyBlockApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("Deleting application deployment")
deleteAppDeployment(appName)
By("Deleting pvc")
deleteAndVerifyPVC(pvcName)
deleteAppAndPvc(appName, pvcName)
By("Deleting storage class", deleteStorageClass)
}

Expand All @@ -87,10 +86,7 @@ func thinVolCreationTest() {

By("Creating and deploying app pod", createDeployVerifyApp)
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)
}

Expand All @@ -101,13 +97,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.
Expand All @@ -133,6 +155,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)
}
18 changes: 15 additions & 3 deletions tests/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fc34cd7

Please sign in to comment.