Skip to content

Commit

Permalink
test(ci): adding volgroup tets
Browse files Browse the repository at this point in the history
Signed-off-by: Abhilash Shetty <[email protected]>
  • Loading branch information
abhilashshetty04 committed Jul 2, 2024
1 parent 6348722 commit 3151b4e
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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")

Expand Down

0 comments on commit 3151b4e

Please sign in to comment.