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(zfspv): adding test cases to verify zfs property update #24

Merged
merged 1 commit into from
Dec 30, 2019
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading