From 883e499ab31d6d7ae5f8d1fb6df1a6100b53d226 Mon Sep 17 00:00:00 2001 From: Marius Cornea Date: Tue, 30 Jan 2024 14:44:24 +0200 Subject: [PATCH] Add initial ibu post upgrade validations structure --- .../internal/ibuclusterinfo/ibuclusterinfo.go | 34 +++++++++++++++++++ .../imagebasedupgradeparams/ibuvars.go | 15 ++++++++ .../tests/happy-path-upgrade.go | 13 +++++++ .../validations/post_ibu_validations.go | 28 +++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 tests/imagebasedupgrade/internal/ibuclusterinfo/ibuclusterinfo.go create mode 100644 tests/imagebasedupgrade/internal/imagebasedupgradeparams/ibuvars.go create mode 100644 tests/imagebasedupgrade/validations/post_ibu_validations.go diff --git a/tests/imagebasedupgrade/internal/ibuclusterinfo/ibuclusterinfo.go b/tests/imagebasedupgrade/internal/ibuclusterinfo/ibuclusterinfo.go new file mode 100644 index 00000000..4fe14ab8 --- /dev/null +++ b/tests/imagebasedupgrade/internal/ibuclusterinfo/ibuclusterinfo.go @@ -0,0 +1,34 @@ +package ibuclusterinfo + +import ( + "github.com/golang/glog" + . "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/internal/imagebasedupgradeinittools" + "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/internal/imagebasedupgradeparams" + "github.com/openshift-kni/eco-gosystem/tests/internal/cluster" +) + +// SaveClusterInfo is a dedicated func to save cluster info. +func SaveClusterInfo(upgradeVar *imagebasedupgradeparams.ClusterStruct) error { + clusterVersion, err := cluster.GetClusterVersion(TargetSNOAPIClient) + + if err != nil { + glog.V(100).Infof("Could not retrieve cluster version") + + return err + } + + clusterID, err := cluster.GetClusterID(TargetSNOAPIClient) + + if err != nil { + glog.V(100).Infof("Could not retrieve cluster id") + + return err + } + + *upgradeVar = imagebasedupgradeparams.ClusterStruct{ + Version: clusterVersion, + ID: clusterID, + } + + return nil +} diff --git a/tests/imagebasedupgrade/internal/imagebasedupgradeparams/ibuvars.go b/tests/imagebasedupgrade/internal/imagebasedupgradeparams/ibuvars.go new file mode 100644 index 00000000..e4eb6c90 --- /dev/null +++ b/tests/imagebasedupgrade/internal/imagebasedupgradeparams/ibuvars.go @@ -0,0 +1,15 @@ +package imagebasedupgradeparams + +// ClusterStruct is a struct that holds the cluster version and id. +type ClusterStruct struct { + Version string + ID string +} + +var ( + // PreUpgradeClusterInfo holds the cluster info pre upgrade. + PreUpgradeClusterInfo = ClusterStruct{} + + // PostUpgradeClusterInfo holds the cluster info post upgrade. + PostUpgradeClusterInfo = ClusterStruct{} +) diff --git a/tests/imagebasedupgrade/tests/happy-path-upgrade.go b/tests/imagebasedupgrade/tests/happy-path-upgrade.go index 88ad9f8e..043b5fa8 100644 --- a/tests/imagebasedupgrade/tests/happy-path-upgrade.go +++ b/tests/imagebasedupgrade/tests/happy-path-upgrade.go @@ -5,8 +5,10 @@ import ( . "github.com/onsi/gomega" "github.com/openshift-kni/eco-goinfra/pkg/lca" "github.com/openshift-kni/eco-goinfra/pkg/polarion" + "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/internal/ibuclusterinfo" "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/internal/imagebasedupgradeinittools" "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/internal/imagebasedupgradeparams" + ibuvalidations "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/validations" ) // IbuCr is a dedicated var to use and act on it. @@ -22,6 +24,11 @@ var _ = Describe( By("Generating seed image", func() { // Test Automation Code Implementation is to be done. }) + + By("Saving pre upgrade cluster info", func() { + err := ibuclusterinfo.SaveClusterInfo(&imagebasedupgradeparams.PreUpgradeClusterInfo) + Expect(err).ToNot(HaveOccurred(), "Failed to save pre upgrade cluster info") + }) }) AfterAll(func() { @@ -52,4 +59,10 @@ var _ = Describe( }) }) + + err := ibuclusterinfo.SaveClusterInfo(&imagebasedupgradeparams.PostUpgradeClusterInfo) + Expect(err).ToNot(HaveOccurred(), "Failed to save post upgrade cluster info") + + ibuvalidations.PostUpgradeValidations() + }) diff --git a/tests/imagebasedupgrade/validations/post_ibu_validations.go b/tests/imagebasedupgrade/validations/post_ibu_validations.go new file mode 100644 index 00000000..7411a3db --- /dev/null +++ b/tests/imagebasedupgrade/validations/post_ibu_validations.go @@ -0,0 +1,28 @@ +package ibuvalidations + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/openshift-kni/eco-goinfra/pkg/polarion" + "github.com/openshift-kni/eco-gosystem/tests/imagebasedupgrade/internal/imagebasedupgradeparams" +) + +// PostUpgradeValidations is a dedicated func to run post upgrade test validations. +func PostUpgradeValidations() { + Describe( + "PostIBUValidations", + Label("PostIBUValidations"), func() { + It("Validate Cluster version", polarion.ID("99998"), Label("ValidateClusterVersion"), func() { + By("Validate upgraded cluster version reports correct version", func() { + Expect(imagebasedupgradeparams.PreUpgradeClusterInfo.Version). + ToNot(Equal(imagebasedupgradeparams.PostUpgradeClusterInfo.Version), "Cluster version hasn't changed") + }) + }) + It("Validate Cluster ID", polarion.ID("99999"), Label("ValidateClusterID"), func() { + By("Validate cluster ID remains the same", func() { + Expect(imagebasedupgradeparams.PreUpgradeClusterInfo.ID). + To(Equal(imagebasedupgradeparams.PostUpgradeClusterInfo.ID), "Cluster ID has changed") + }) + }) + }) +}