From 94570df3cd2342376480e09ea426dae0ce9676ab Mon Sep 17 00:00:00 2001 From: riya-singhal31 Date: Tue, 19 Apr 2022 11:28:29 +0530 Subject: [PATCH] test: added test to validate the LVMO resources This test validates all the resources created by LVMO. Signed-off-by: riya-singhal31 --- Makefile | 4 +- e2e/config.go | 1 + e2e/lvm/lvm_suite_test.go | 11 +-- e2e/validation.go | 150 ++++++++++++++++++++++++++++++++++++ pkg/deploymanager/config.go | 1 + 5 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 e2e/validation.go diff --git a/Makefile b/Makefile index 67ccac84b..6c65e5380 100644 --- a/Makefile +++ b/Makefile @@ -311,9 +311,11 @@ lvm-must-gather: # Variables required to run and build LVM end to end tests. LVM_OPERATOR_INSTALL ?= true LVM_OPERATOR_UNINSTALL ?= true +SUBSCRIPTION_CHANNEL ?= alpha # Build and run lvm tests. e2e-test: ginkgo @echo "build and run e2e tests" cd e2e/lvm && $(GINKGO) build - cd e2e/lvm && ./lvm.test --lvm-catalog-image=$(CATALOG_IMG) --lvm-subscription-channel=$(CHANNELS) --lvm-operator-install=$(LVM_OPERATOR_INSTALL) --lvm-operator-uninstall=$(LVM_OPERATOR_UNINSTALL) + cd e2e/lvm && ./lvm.test --lvm-catalog-image=$(CATALOG_IMG) --lvm-subscription-channel=$(SUBSCRIPTION_CHANNEL) --lvm-operator-install=$(LVM_OPERATOR_INSTALL) --lvm-operator-uninstall=$(LVM_OPERATOR_UNINSTALL) -ginkgo.v + diff --git a/e2e/config.go b/e2e/config.go index 68db68746..0d8291e11 100644 --- a/e2e/config.go +++ b/e2e/config.go @@ -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 diff --git a/e2e/lvm/lvm_suite_test.go b/e2e/lvm/lvm_suite_test.go index 16a65f703..e42e5eb54 100644 --- a/e2e/lvm/lvm_suite_test.go +++ b/e2e/lvm/lvm_suite_test.go @@ -2,7 +2,6 @@ package lvm_test import ( "flag" - "fmt" "testing" . "github.com/onsi/ginkgo/v2" @@ -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 reconciliation", func() { + err := tests.ValidateResources() + Expect(err).To(BeNil()) }) }) }) diff --git a/e2e/validation.go b/e2e/validation.go new file mode 100644 index 000000000..e4e83b9f0 --- /dev/null +++ b/e2e/validation.go @@ -0,0 +1,150 @@ +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.Minute * 15 + interval = time.Second * 30 + lvmVolumeGroupName = "vg1" + storageClassName = "odf-lvm-vg1" + csiDriverName = "topolvm.cybozu.com" + topolvmNodeDaemonSetName = "topolvm-node" + topolvmCtrlDeploymentName = "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()) + + debug("VG found\n") + 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()) + + debug("SC found\n") + 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()) + + debug("CSI Driver found\n") + 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: topolvmNodeDaemonSetName, Namespace: InstallNamespace}, &ds) + return err == nil + }, timeout, interval).Should(BeTrue()) + debug("TopoLVM node found\n") + + /* // checking for the ready status + Eventually(func() bool { + err := DeployManagerObj.GetCrClient().Get(context.TODO(), types.NamespacedName{Name: topolvmNodeDaemonSetName, Namespace: InstallNamespace}, &ds) + if err != nil { + debug("topolvmNode : %s", err.Error()) + return + } + return ds.Status.DesiredNumberScheduled == ds.Status.NumberReady + }, timeout, interval).Should(BeTrue()) + debug("Status is ready\n") */ + + 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()) + debug("VG manager found\n") + + 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: topolvmCtrlDeploymentName, Namespace: InstallNamespace}, &dep) + return err == nil + }, timeout, interval).Should(BeTrue()) + + debug("depoloyment found\n") + return nil +} + +// Validate all the resources created by LVMO. +func ValidateResources() error { + + // Validate CSI Driver + err := ValidateCSIDriver() + 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 + } + // Validate LVMVg + err = ValidateLVMvg() + if err != nil { + return err + } + + // Validate Topolvm node + err = ValidateTopolvmNode() + if err != nil { + return err + } + // Validate Storage class + err = ValidateStorageClass() + if err != nil { + return err + } + return nil +} diff --git a/pkg/deploymanager/config.go b/pkg/deploymanager/config.go index a469192cf..ed8d1ca3e 100644 --- a/pkg/deploymanager/config.go +++ b/pkg/deploymanager/config.go @@ -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