From 3151b4e8d4ed0f3c28d761777f8f349a4fafcbf3 Mon Sep 17 00:00:00 2001 From: Abhilash Shetty Date: Tue, 2 Jul 2024 06:33:19 +0000 Subject: [PATCH] test(ci): adding volgroup tets Signed-off-by: Abhilash Shetty --- tests/utils.go | 67 ++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/tests/utils.go b/tests/utils.go index db58f9fe..4b9e1a42 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -41,25 +41,27 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) -func IsPVCBoundEventually(pvcName string, timeoutSeconds int, intervalSeconds int) bool { - startTime := time.Now() - for { - volume, err := PVCClient.Get(pvcName, metav1.GetOptions{}) - if err != nil { - return false - } - - if pvc.NewForAPIObject(volume).IsBound() { - return true - } - - elapsed := time.Since(startTime) - if elapsed.Seconds() >= float64(timeoutSeconds) { - return false - } +// This checks if the pvc is bound eventually within the poll period. +func IsPVCBoundEventually(pvcName string) bool { + ginkgo.By("Verifying pvc status to be bound eventually\n") + return gomega.Eventually(func() bool { + volume, err := PVCClient. + Get(pvcName, metav1.GetOptions{}) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + return pvc.NewForAPIObject(volume).IsBound() + }, + 60, 5). + Should(gomega.BeTrue()) +} - time.Sleep(time.Duration(intervalSeconds) * time.Second) - } +// This checks if the pvc is Not bound consistently over polling period. +func IsPVCPendingConsistently(pvcName string) bool { + ginkgo.By("Verifying pvc status to be Pending consistently\n") + return gomega.Consistently(func() bool { + volume, err := PVCClient.Get(pvcName, metav1.GetOptions{}) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + return !pvc.NewForAPIObject(volume).IsBound() + }, 30, 5).Should(gomega.BeTrue()) } // IsPVCResizedEventually checks if the pvc is bound or not eventually @@ -316,12 +318,14 @@ func createAndVerifyPVC(expect_bound bool) { pvcName, OpenEBSNamespace, ) - - ginkgo.By("verifying pvc status as bound\n") - ok := IsPVCBoundEventually(pvcName, 30, 3) - - gomega.Expect(ok).To(gomega.Equal(expect_bound), - "while checking status equal to Not Bound") + ok := false + if !expect_bound { + ok = IsPVCPendingConsistently(pvcName) + } else { + ok = IsPVCBoundEventually(pvcName) + } + gomega.Expect(ok).To(gomega.Equal(true), + "while checking the pvc status") pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Get(pvcObj.Name, metav1.GetOptions{}) gomega.Expect(err).To( @@ -366,9 +370,14 @@ func createAndVerifyBlockPVC(expect_bound bool) { ginkgo.By("verifying pvc status as bound\n") - ok := IsPVCBoundEventually(pvcName, 15, 3) - gomega.Expect(ok).To(gomega.Equal(expect_bound), - "while checking status equal to bound") + ok := false + if !expect_bound { + ok = IsPVCPendingConsistently(pvcName) + } else { + ok = IsPVCBoundEventually(pvcName) + } + gomega.Expect(ok).To(gomega.Equal(true), + "while checking the pvc status") pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Get(pvcObj.Name, metav1.GetOptions{}) gomega.Expect(err).To( @@ -385,9 +394,7 @@ func VerifyBlockPVC() { pvcName = "lvmpv-pvc" ) - ginkgo.By("verifying pvc status as bound\n") - - ok := IsPVCBoundEventually(pvcName, 45, 5) + ok := IsPVCBoundEventually(pvcName) gomega.Expect(ok).To(gomega.Equal(true), "while checking status equal to bound")