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 creating sized snapshots for filesystem and block volumes #309

Merged
merged 1 commit into from
Jun 14, 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
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%
81 changes: 53 additions & 28 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 @@ -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)
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -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)
}
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
Loading