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

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

Merged
merged 1 commit into from
Jul 7, 2020
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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand All @@ -31,13 +31,13 @@ install:
- make bootstrap
- make format
- make golint
- 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}';
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions changelogs/unreleased/174-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adding snapshot and clone releated test cases in BDD
10 changes: 10 additions & 0 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
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
Expand Up @@ -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() {
Expand All @@ -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
Expand Up @@ -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
Expand Down
Loading