Skip to content

Commit

Permalink
test: added test to validate the LVMO resources
Browse files Browse the repository at this point in the history
This test validates all the resources created by LVMO

Signed-off-by: riya-singhal31 <riyasinghalji@gmail.com>
  • Loading branch information
riya-singhal31 committed Apr 13, 2022
1 parent 2a5c5cd commit 54adb4b
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 5 deletions.
1 change: 1 addition & 0 deletions e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// TestNamespace is the namespace we run all the tests in.
const TestNamespace = "lvm-endtoendtest"
const InstallNamespace = "openshift-storage"

var lvmOperatorInstall bool
var lvmOperatorUninstall bool
Expand Down
11 changes: 6 additions & 5 deletions e2e/lvm/lvm_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package lvm_test

import (
"flag"
"fmt"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -25,10 +24,12 @@ var _ = AfterSuite(func() {
tests.AfterTestSuiteCleanup()
})

var _ = Describe("lvmtest", func() {
Context("Run a dummy test", func() {
It("Should do nothing", func() {
fmt.Println("Do nothing")
// Test to validate all the resources created by LVMO.
var _ = Describe("Validation test", func() {
Context("Validate LVMCluster reconciliation", func() {
It("Should validate LVMCluster reconcilation", func() {
err := tests.ValidateResources()
Expect(err).To(BeNil())
})
})
})
137 changes: 137 additions & 0 deletions e2e/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package e2e

import (
"context"
"time"

. "github.com/onsi/gomega"
lvmv1alpha1 "github.com/red-hat-storage/lvm-operator/api/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/types"
)

const (
timeout = time.Second * 10
interval = time.Millisecond * 100
lvmVolumeGroupName = "vg1"
storageClassName = "odf-lvm-vg1"
csiDriverName = "topolvm.cybozu.com"
daemonSetName = "topolvm-node"
deploymentName = "topolvm-controller"
vgManagerDaemonsetName = "vg-manager"
)

// function to validate LVMVolume group.
func ValidateLVMvg() error {
lvmVG := lvmv1alpha1.LVMVolumeGroup{}

Eventually(func() bool {
err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: lvmVolumeGroupName, Namespace: InstallNamespace}, &lvmVG)
return err == nil
}, timeout, interval).Should(BeTrue())

return nil
}

// function to validate storage class.
func ValidateStorageClass() error {
sc := storagev1.StorageClass{}

Eventually(func() bool {
err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: storageClassName, Namespace: InstallNamespace}, &sc)
return err == nil
}, timeout, interval).Should(BeTrue())

return nil
}

// function to validate CSI Driver.
func ValidateCSIDriver() error {
cd := storagev1.CSIDriver{}

Eventually(func() bool {
err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: csiDriverName, Namespace: InstallNamespace}, &cd)
return err == nil
}, timeout, interval).Should(BeTrue())

return nil
}

// function to validate TopoLVM node.
func ValidateTopolvmNode() error {
ds := appsv1.DaemonSet{}

Eventually(func() bool {
err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: daemonSetName, Namespace: InstallNamespace}, &ds)
return err == nil
}, timeout, interval).Should(BeTrue())

return nil
}

// function to validate vg manager resource.
func ValidateVGManager() error {
ds := appsv1.DaemonSet{}

Eventually(func() bool {
err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: vgManagerDaemonsetName, Namespace: InstallNamespace}, &ds)
return err == nil
}, timeout, interval).Should(BeTrue())

return nil
}

// function to validate TopoLVM Deployment.
func ValidateTopolvmController() error {
dep := appsv1.Deployment{}

Eventually(func() bool {
err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: deploymentName, Namespace: InstallNamespace}, &dep)
return err == nil
}, timeout, interval).Should(BeTrue())

return nil
}

// Validate all the resources created by LVMO.
func ValidateResources() error {

// Validate Storage class
err := ValidateStorageClass()
if err != nil {
return err
}

// Validate LVMVg
err = ValidateLVMvg()
if err != nil {
return err
}

// Validate CSI Driver
err = ValidateCSIDriver()
if err != nil {
return err
}

// Validate Topolvm node
err = ValidateTopolvmNode()
if err != nil {
return err
}

//Validate TopoLVM Controller
err = ValidateTopolvmController()
if err != nil {
return err
}

// Validate VG Manager Daemonset
err = ValidateVGManager()
if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions pkg/deploymanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewDeployManager() (*DeployManager, error) {
// controller-runtime client
myScheme := runtime.NewScheme()
utilruntime.Must(lvmv1.AddToScheme(myScheme))
utilruntime.Must(scheme.AddToScheme(myScheme))
crClient, err := crclient.New(config, crclient.Options{Scheme: myScheme})
if err != nil {
return nil, err
Expand Down

0 comments on commit 54adb4b

Please sign in to comment.