Skip to content

Commit

Permalink
test(zfspv): adding zfs property update test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 authored and kmova committed Dec 30, 2019
1 parent 620be59 commit 7547554
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,5 +1,5 @@
sudo: required
dist: xenial
dist: bionic
env:
global:
- CHANGE_MINIKUBE_NONE_USER=true
Expand Down Expand Up @@ -46,7 +46,7 @@ install:
before_script:
- "./buildscripts/travis-build.sh"
script:
- make ci
- sudo -E env "PATH=$PATH" make ci
after_success:
- make deploy-images
- bash <(curl -s https://codecov.io/bash)
Expand Down
2 changes: 2 additions & 0 deletions ci/ci-test.sh
Expand Up @@ -63,6 +63,8 @@ sudo zpool status

sudo zfs list -t all

sudo zfs get all

echo "******************** ZFS Controller logs***************************** "
dumpControllerLogs 1000

Expand Down
2 changes: 1 addition & 1 deletion pkg/mgmt/mgmt.go
Expand Up @@ -89,7 +89,7 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
// the volume. And if it is set then volume has already been
// created and this event is for property change only.
if zv.Finalizers != nil {
err = zfs.SetZvolProp(zv)
err = zfs.SetVolumeProp(zv)
} else {
err = zfs.CreateVolume(zv)
if err == nil {
Expand Down
23 changes: 21 additions & 2 deletions pkg/zfs/zfs_util.go
Expand Up @@ -36,6 +36,7 @@ const (
ZFSCreateArg = "create"
ZFSDestroyArg = "destroy"
ZFSSetArg = "set"
ZFSGetArg = "get"
ZFSListArg = "list"
)

Expand Down Expand Up @@ -270,8 +271,26 @@ func UmountZFSDataset(vol *apis.ZFSVolume) error {
return SetDatasetMountProp(volume, "none")
}

// SetZvolProp sets the volume property
func SetZvolProp(vol *apis.ZFSVolume) error {
// GetVolumeProperty gets zfs properties for the volume
func GetVolumeProperty(vol *apis.ZFSVolume, prop string) (string, error) {
var ZFSVolArg []string
volume := vol.Spec.PoolName + "/" + vol.Name

ZFSVolArg = append(ZFSVolArg, ZFSGetArg, "-pH", "-o", "value", prop, volume)

cmd := exec.Command(ZFSVolCmd, ZFSVolArg...)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfs: could not get %s on dataset %v cmd %v error: %s",
prop, volume, ZFSVolArg, string(out))
return "", err
}
val := out[:len(out)-1]
return string(val), nil
}

// SetVolumeProp sets the volume property
func SetVolumeProp(vol *apis.ZFSVolume) error {
var err error
volume := vol.Spec.PoolName + "/" + vol.Name

Expand Down
2 changes: 2 additions & 0 deletions tests/provision_test.go
Expand Up @@ -31,6 +31,7 @@ func datasetCreationTest() {
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)
By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
By("Deleting storage class", deleteStorageClass)
Expand All @@ -49,6 +50,7 @@ func zvolCreationTest() {
*/
//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)
Expand Down
43 changes: 24 additions & 19 deletions tests/suite_test.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package tests

import (
"github.com/Sirupsen/logrus"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openebs/zfs-localpv/pkg/builder"
Expand All @@ -40,31 +41,35 @@ const (
)

var (
ZFSClient *builder.Kubeclient
SCClient *sc.Kubeclient
PVCClient *pvc.Kubeclient
DeployClient *deploy.Kubeclient
PodClient *pod.KubeClient
openebsNamespace = "openebs"
nsName = "zfspv-provision"
scName = "zfspv-sc"
ZFSProvisioner = "zfs.csi.openebs.io"
pvcName = "zfspv-pvc"
appName = "busybox-zfspv"
ZFSClient *builder.Kubeclient
SCClient *sc.Kubeclient
PVCClient *pvc.Kubeclient
DeployClient *deploy.Kubeclient
PodClient *pod.KubeClient
nsName = "zfspv-provision"
scName = "zfspv-sc"
ZFSProvisioner = "zfs.csi.openebs.io"
pvcName = "zfspv-pvc"
appName = "busybox-zfspv"

nsObj *corev1.Namespace
scObj *storagev1.StorageClass
deployObj *appsv1.Deployment
pvcObj *corev1.PersistentVolumeClaim
appPod *corev1.PodList
accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
capacity = "5368709120" // 5Gi
KubeConfigPath string
nsObj *corev1.Namespace
scObj *storagev1.StorageClass
deployObj *appsv1.Deployment
pvcObj *corev1.PersistentVolumeClaim
appPod *corev1.PodList
accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
capacity = "5368709120" // 5Gi
KubeConfigPath string
OpenEBSNamespace string
)

func init() {
KubeConfigPath = os.Getenv("KUBECONFIG")

OpenEBSNamespace = os.Getenv("OPENEBS_NAMESPACE")
if OpenEBSNamespace == "" {
logrus.Fatalf("OPENEBS_NAMESPACE environment variable not set")
}
SCClient = sc.NewKubeClient(sc.WithKubeConfigPath(KubeConfigPath))
PVCClient = pvc.NewKubeClient(pvc.WithKubeConfigPath(KubeConfigPath))
DeployClient = deploy.NewKubeClient(deploy.WithKubeConfigPath(KubeConfigPath))
Expand Down

0 comments on commit 7547554

Please sign in to comment.