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(resize): adding BDD test for Online volume expansion #52

Merged
merged 1 commit into from
Mar 6, 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
1 change: 1 addition & 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("Resizing the PVC", resizeAndVerifyPVC)
By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit)
By("Deleting application deployment", deleteAppDeployment)
By("Deleting pvc", deletePVC)
Expand Down
1 change: 1 addition & 0 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
appPod *corev1.PodList
accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
capacity = "5368709120" // 5Gi
NewCapacity = "8589934592" // 8Gi, for testing resize
KubeConfigPath string
OpenEBSNamespace string
)
Expand Down
56 changes: 56 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/api/resource"
)

// IsPVCBoundEventually checks if the pvc is bound or not eventually
Expand All @@ -47,6 +49,23 @@ func IsPVCBoundEventually(pvcName string) bool {
Should(BeTrue())
}

// IsPVCResizedEventually checks if the pvc is bound or not eventually
func IsPVCResizedEventually(pvcName string, newCapacity string) bool {
newStorage, err := resource.ParseQuantity(NewCapacity)
if err != nil {
return false
}
return Eventually(func() bool {
volume, err := PVCClient.
Get(pvcName, metav1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
pvcStorage := volume.Spec.Resources.Requests[corev1.ResourceName(corev1.ResourceStorage)]
return pvcStorage == newStorage
},
60, 5).
Should(BeTrue())
}

// IsPodRunningEventually return true if the pod comes to running state
func IsPodRunningEventually(namespace, podName string) bool {
return Eventually(func() bool {
Expand Down Expand Up @@ -122,6 +141,7 @@ func createZfsStorageClass() {
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)
Expand Down Expand Up @@ -302,6 +322,42 @@ func createAndVerifyPVC() {
)
}

func resizeAndVerifyPVC() {
var (
err error
pvcName = "zfspv-pvc"
)
By("updating the pvc with new size")
pvcObj, err = pvc.BuildFrom(pvcObj).
WithCapacity(NewCapacity).Build()
Expect(err).To(
BeNil(),
"while building pvc {%s} in namespace {%s}",
pvcName,
OpenEBSNamespace,
)
pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Update(pvcObj)
Expect(err).To(
BeNil(),
"while updating pvc {%s} in namespace {%s}",
pvcName,
OpenEBSNamespace,
)

By("verifying pvc size to be updated")

status := IsPVCResizedEventually(pvcName, NewCapacity)
Expect(status).To(Equal(true),
"while checking pvc resize")

pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Get(pvcObj.Name, metav1.GetOptions{})
Expect(err).To(
BeNil(),
"while retrieving pvc {%s} in namespace {%s}",
pvcName,
OpenEBSNamespace,
)
}
func createDeployVerifyApp() {
By("creating and deploying app pod", createAndDeployAppPod)
time.Sleep(30 * time.Second)
Expand Down