Skip to content

Commit

Permalink
feat(bdd): adding snapshot and clone releated cases
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pawanpraka1 committed Jul 3, 2020
1 parent a19877e commit 4ff95f7
Showing 7 changed files with 196 additions and 70 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -y zfsutils-linux
- truncate -s 100G /tmp/disk.img
- sudo zpool create -f zfspv-pool /tmp/disk.img
- sudo zpool create zfspv-pool `sudo losetup -f /tmp/disk.img --show`
install:
- if [ "$TRAVIS_BUILD_DIR" != "$GOPATH/src/github.com/openebs/zfs-localpv" ]; then
mkdir -p $GOPATH/src/github.com/openebs/;
@@ -30,13 +30,13 @@ install:
fi
- make bootstrap
- make format
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.17.4/bin/linux/amd64/kubectl
&& chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.4.0/minikube-linux-amd64
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.8.1/minikube-linux-amd64
&& chmod +x minikube && sudo mv minikube /usr/local/bin/
- mkdir -p $HOME/.kube $HOME/.minikube
- touch $KUBECONFIG
- sudo minikube start --vm-driver=none --kubernetes-version=v1.16.0
- sudo minikube start --vm-driver=none --kubernetes-version=v1.17.4
- sudo chown -R $USER $HOME/.minikube
- sudo chown -R $USER $HOME/.kube
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}';
10 changes: 10 additions & 0 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
@@ -20,11 +20,15 @@ export OPENEBS_NAMESPACE="openebs"
export NodeID=$HOSTNAME

ZFS_OPERATOR=deploy/zfs-operator.yaml
SNAP_CLASS=deploy/sample/zfssnapclass.yaml

TEST_DIR="tests"


# Prepare env for runnging BDD tests
# Minikube is already running
kubectl apply -f $ZFS_OPERATOR
kubectl apply -f $SNAP_CLASS

dumpAgentLogs() {
NR=$1
@@ -110,12 +114,18 @@ kubectl get pods -owide --all-namespaces
echo "get pvc and pv details"
kubectl get pvc,pv -oyaml --all-namespaces

echo "get snapshot details"
kubectl get volumesnapshot.snapshot -oyaml --all-namespaces

echo "get sc details"
kubectl get sc --all-namespaces -oyaml

echo "get zfs volume details"
kubectl get zfsvolumes.zfs.openebs.io -n openebs -oyaml

echo "get zfs snapshot details"
kubectl get zfssnapshots.zfs.openebs.io -n openebs -oyaml

exit 1
fi

8 changes: 8 additions & 0 deletions deploy/sample/zfssnapclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: VolumeSnapshotClass
apiVersion: snapshot.storage.k8s.io/v1beta1
metadata:
name: zfspv-snapclass
annotations:
snapshot.storage.kubernetes.io/is-default-class: "true"
driver: zfs.csi.openebs.io
deletionPolicy: Delete
63 changes: 32 additions & 31 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
@@ -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 changes: 117 additions & 0 deletions tests/run_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
@@ -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
57 changes: 22 additions & 35 deletions tests/utils.go
Original file line number Diff line number Diff line change
@@ -105,19 +105,20 @@ func IsPVCDeletedEventually(pvcName string) bool {
Should(BeTrue())
}

func createExt4StorageClass() {
func createFstypeStorageClass(ftype string) {
var (
err error
)

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

By("building a ext4 storage class")
By("building a " + ftype + " storage class")
scObj, err = sc.NewBuilder().
WithGenerateName(scName).
WithVolumeExpansion(true).
WithParametersNew(parameters).
WithProvisioner(ZFSProvisioner).Build()
Expect(err).ShouldNot(HaveOccurred(),
@@ -148,29 +149,6 @@ func createStorageClass() {
Expect(err).To(BeNil(), "while creating a default storageclass {%s}", scName)
}

func createZfsStorageClass() {
var (
err error
)

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

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

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

func VerifyZFSVolume() {
By("fetching zfs volume")
vol, err := ZFSClient.WithNamespace(OpenEBSNamespace).
@@ -396,6 +374,7 @@ func resizeAndVerifyPVC() {
pvcName = "zfspv-pvc"
)
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()
Expect(err).To(
@@ -427,16 +406,24 @@ func resizeAndVerifyPVC() {
)
}
func createDeployVerifyApp() {
By("creating and deploying app pod", createAndDeployAppPod)
By("creating and deploying app pod")
createAndDeployAppPod(appName)
time.Sleep(30 * time.Second)
By("verifying app pod is running", verifyAppPodRunning)
}

func createAndDeployAppPod() {
func createDeployVerifyCloneApp() {
By("creating and deploying app pod")
createAndDeployAppPod(cloneAppName)
time.Sleep(30 * time.Second)
By("verifying app pod is running", verifyAppPodRunning)
}

func createAndDeployAppPod(appname string) {
var err error
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{
@@ -577,22 +564,22 @@ func verifyAppPodRunning() {
Expect(status).To(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{})
Expect(err).ShouldNot(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{})
Expect(err).To(
BeNil(),
"while deleting pvc {%s} in namespace {%s}",
pvcName,
pvcname,
OpenEBSNamespace,
)
By("verifying deleted pvc")
status := IsPVCDeletedEventually(pvcName)
status := IsPVCDeletedEventually(pvcname)
Expect(status).To(Equal(true), "while trying to get deleted pvc")

}

0 comments on commit 4ff95f7

Please sign in to comment.