feat(bdd): adding snapshot and clone releated test cases

added snapshot and clone related test cases. Also restructure
the BDD framework to loop through the supported fstypes and perfrom all
the test cases we have.

Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
Pawan 2020-07-02 18:32:44 +05:30 committed by Kiran Mova
parent 8bbf3d7d2f
commit 21045a5b1f
9 changed files with 197 additions and 71 deletions

View file

@ -26,35 +26,35 @@ var _ = Describe("[zfspv] TEST VOLUME PROVISIONING", func() {
})
})
func datasetCreationTest() {
By("Creating zfs storage class", createZfsStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying ZFSVolume object", VerifyZFSVolume)
By("Resizing the PVC", resizeAndVerifyPVC)
By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit)
By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
By("Deleting storage class", deleteStorageClass)
}
func fsVolCreationTest() {
fstypes := []string{"zfs", "ext4", "xfs", "btrfs"}
for _, fstype := range fstypes {
By("####### Creating the storage class : " + fstype + " #######")
createFstypeStorageClass(fstype)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying ZFSVolume object", VerifyZFSVolume)
By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit)
func zvolCreationTest() {
By("Creating ext4 storage class", createExt4StorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
createSnapshot(pvcName, snapName)
verifySnapshotCreated(snapName)
createClone(clonePvcName, snapName, scObj.Name)
By("Creating and deploying clone app pod", createDeployVerifyCloneApp)
/*
* 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", VerifyZFSVolume)
By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit)
//By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
By("Deleting storage class", deleteStorageClass)
// btrfs does not support online resize
if fstype != "btrfs" {
By("Resizing the PVC", resizeAndVerifyPVC)
}
By("Deleting clone and main application deployment")
deleteAppDeployment(cloneAppName)
deleteAppDeployment(appName)
By("Deleting snapshot, main pvc and clone pvc")
deletePVC(clonePvcName)
deleteSnapshot(pvcName, snapName)
deletePVC(pvcName)
By("Deleting storage class", deleteStorageClass)
}
}
func blockVolCreationTest() {
@ -64,13 +64,14 @@ func blockVolCreationTest() {
By("Creating and deploying app pod", createDeployVerifyBlockApp)
By("verifying ZFSVolume object", VerifyZFSVolume)
By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit)
By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
By("Deleting application deployment")
deleteAppDeployment(appName)
By("Deleting pvc")
deletePVC(pvcName)
By("Deleting storage class", deleteStorageClass)
}
func volumeCreationTest() {
By("Running dataset creation test", datasetCreationTest)
By("Running zvol creation test", zvolCreationTest)
By("Running volume creation test", fsVolCreationTest)
By("Running block volume creation test", blockVolCreationTest)
}

117
tests/run_test.go Normal file
View file

@ -0,0 +1,117 @@
/*
Copyright 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
import (
"bytes"
"os/exec"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const (
snapYAML = `apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
name: #snapname
spec:
volumeSnapshotClassName: zfspv-snapclass
source:
persistentVolumeClaimName: #pvcname
`
cloneYAML = `apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: #pvcname
spec:
dataSource:
name: #snapname
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: #storageclass
`
)
func execAtLocal(cmd string, input []byte, args ...string) ([]byte, []byte, error) {
var stdout, stderr bytes.Buffer
command := exec.Command(cmd, args...)
command.Stdout = &stdout
command.Stderr = &stderr
if len(input) != 0 {
command.Stdin = bytes.NewReader(input)
}
err := command.Run()
return stdout.Bytes(), stderr.Bytes(), err
}
func kubectl(args ...string) ([]byte, []byte, error) {
return execAtLocal("kubectl", nil, args...)
}
func kubectlWithInput(input []byte, args ...string) ([]byte, []byte, error) {
return execAtLocal("kubectl", input, args...)
}
func verifySnapshotCreated(snapName string) bool {
Eventually(func() bool {
stdout, stderr, err := kubectl("get", "volumesnapshots.snapshot", snapName, "-n", OpenEBSNamespace, "-o=template", "--template={{.status.readyToUse}}")
Expect(err).ShouldNot(HaveOccurred(), "stdout=%s, stderr=%s", stdout, stderr)
return strings.TrimSpace(string(stdout)) == "true"
}, 240, 5).Should(BeTrue())
return true
}
func createSnapshot(pvcName, snapName string) {
By("creating snapshot for a pvc " + pvcName)
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 createClone(clonepvc, snapname, storageclass string) {
By("creating clone volume from snapshot " + snapname)
syaml := strings.Replace(cloneYAML, "#snapname", snapname, -1)
cyaml := strings.Replace(syaml, "#pvcname", clonepvc, -1)
yaml := strings.Replace(cyaml, "#storageclass", storageclass, -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) {
By("deleting the snapshot " + snapName)
tyaml := strings.Replace(snapYAML, "#pvcname", pvcName, -1)
yaml := strings.Replace(tyaml, "#snapname", snapName, -1)
stdout, stderr, err := kubectlWithInput([]byte(yaml), "delete", "-n", OpenEBSNamespace, "-f", "-")
Expect(err).ShouldNot(HaveOccurred(), "stdout=%s, stderr=%s", stdout, stderr)
}

View file

@ -51,7 +51,10 @@ var (
scName = "zfspv-sc"
ZFSProvisioner = "zfs.csi.openebs.io"
pvcName = "zfspv-pvc"
snapName = "zfspv-snap"
appName = "busybox-zfspv"
clonePvcName = "zfspv-pvc-clone"
cloneAppName = "busybox-zfspv-clone"
nsObj *corev1.Namespace
scObj *storagev1.StorageClass

View file

@ -106,19 +106,20 @@ func IsPVCDeletedEventually(pvcName string) bool {
Should(gomega.BeTrue())
}
func createExt4StorageClass() {
func createFstypeStorageClass(ftype string) {
var (
err error
)
parameters := map[string]string{
"poolname": POOLNAME,
"fstype": "ext4",
"fstype": ftype,
}
ginkgo.By("building a ext4 storage class")
ginkgo.By("building a " + ftype + " storage class")
scObj, err = sc.NewBuilder().
WithGenerateName(scName).
WithVolumeExpansion(true).
WithParametersNew(parameters).
WithProvisioner(ZFSProvisioner).Build()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(),
@ -149,29 +150,6 @@ func createStorageClass() {
gomega.Expect(err).To(gomega.BeNil(), "while creating a default storageclass {%s}", scName)
}
func createZfsStorageClass() {
var (
err error
)
parameters := map[string]string{
"poolname": POOLNAME,
"fstype": "zfs",
}
ginkgo.By("building a zfs storage class")
scObj, err = sc.NewBuilder().
WithGenerateName(scName).
WithParametersNew(parameters).
WithVolumeExpansion(true).
WithProvisioner(ZFSProvisioner).Build()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(),
"while building zfs storageclass obj with prefix {%s}", scName)
scObj, err = SCClient.Create(scObj)
gomega.Expect(err).To(gomega.BeNil(), "while creating a zfs storageclass {%s}", scName)
}
// VerifyZFSVolume verify the properties of a zfs-volume
func VerifyZFSVolume() {
ginkgo.By("fetching zfs volume")
@ -399,6 +377,7 @@ func resizeAndVerifyPVC() {
pvcName = "zfspv-pvc"
)
ginkgo.By("updating the pvc with new size")
pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Get(pvcObj.Name, metav1.GetOptions{})
pvcObj, err = pvc.BuildFrom(pvcObj).
WithCapacity(NewCapacity).Build()
gomega.Expect(err).To(
@ -430,16 +409,24 @@ func resizeAndVerifyPVC() {
)
}
func createDeployVerifyApp() {
ginkgo.By("creating and deploying app pod", createAndDeployAppPod)
ginkgo.By("creating and deploying app pod")
createAndDeployAppPod(appName)
time.Sleep(30 * time.Second)
ginkgo.By("verifying app pod is running", verifyAppPodRunning)
}
func createAndDeployAppPod() {
func createDeployVerifyCloneApp() {
ginkgo.By("creating and deploying app pod")
createAndDeployAppPod(cloneAppName)
time.Sleep(30 * time.Second)
ginkgo.By("verifying app pod is running", verifyAppPodRunning)
}
func createAndDeployAppPod(appname string) {
var err error
ginkgo.By("building a busybox app pod deployment using above zfs volume")
deployObj, err = deploy.NewBuilder().
WithName(appName).
WithName(appname).
WithNamespace(OpenEBSNamespace).
WithLabelsNew(
map[string]string{
@ -580,22 +567,21 @@ func verifyAppPodRunning() {
gomega.Expect(status).To(gomega.Equal(true), "while checking status of pod {%s}", appPod.Items[0].Name)
}
func deleteAppDeployment() {
func deleteAppDeployment(appname string) {
err := DeployClient.WithNamespace(OpenEBSNamespace).
Delete(deployObj.Name, &metav1.DeleteOptions{})
Delete(appname, &metav1.DeleteOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "while deleting application pod")
}
func deletePVC() {
err := PVCClient.WithNamespace(OpenEBSNamespace).Delete(pvcName, &metav1.DeleteOptions{})
func deletePVC(pvcname string) {
err := PVCClient.WithNamespace(OpenEBSNamespace).Delete(pvcname, &metav1.DeleteOptions{})
gomega.Expect(err).To(
gomega.BeNil(),
"while deleting pvc {%s} in namespace {%s}",
pvcName,
pvcname,
OpenEBSNamespace,
)
ginkgo.By("verifying deleted pvc")
status := IsPVCDeletedEventually(pvcName)
status := IsPVCDeletedEventually(pvcname)
gomega.Expect(status).To(gomega.Equal(true), "while trying to get deleted pvc")
}