From d0a8c98a400707ad98fec083acada32afa0baf7f Mon Sep 17 00:00:00 2001 From: zhewang Date: Fri, 19 Jul 2024 08:49:43 +0800 Subject: [PATCH] OCM-9304 | test: Automate OCP-37499 Users can upgrade NON-STS rosa cluster across Y stream --- tests/ci/data/profiles/rosa-classic.yaml | 28 ++++++++- tests/e2e/test_rosacli_upgrade.go | 64 +++++++++++++++++++++ tests/utils/common/constants/cluster.go | 7 +++ tests/utils/exec/rosacli/cluster_service.go | 46 +++++++++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) diff --git a/tests/ci/data/profiles/rosa-classic.yaml b/tests/ci/data/profiles/rosa-classic.yaml index ca9bb446e7..0cf32c8df8 100644 --- a/tests/ci/data/profiles/rosa-classic.yaml +++ b/tests/ci/data/profiles/rosa-classic.yaml @@ -188,4 +188,30 @@ profiles: admin_enabled: false account-role: path: "/test/" - permission_boundary: "" \ No newline at end of file + permission_boundary: "" +- as: rosa-non-sts-upgrade-y-stream + version: "y-1" + channel_group: candidate + region: "us-east-1" + cluster: + multi_az: false + instance_type: "r5.xlarge" + hcp: false + sts: false + byo_vpc: false + private_link: false + private: false + etcd_encryption: false + autoscale: false + kms_key: false + networking: false + proxy_enabled: false + label_enabled: false + zones: "" + tag_enabled: true + etcd_kms: false + fips: false + oidc_config: "" + shared_vpc: false + imdsv2: "optional" + admin_enabled: false \ No newline at end of file diff --git a/tests/e2e/test_rosacli_upgrade.go b/tests/e2e/test_rosacli_upgrade.go index 53ff0bb563..b795cee140 100644 --- a/tests/e2e/test_rosacli_upgrade.go +++ b/tests/e2e/test_rosacli_upgrade.go @@ -2,6 +2,7 @@ package e2e import ( "fmt" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -9,6 +10,7 @@ import ( "github.com/openshift/rosa/tests/ci/labels" "github.com/openshift/rosa/tests/utils/common" + con "github.com/openshift/rosa/tests/utils/common/constants" "github.com/openshift/rosa/tests/utils/config" "github.com/openshift/rosa/tests/utils/exec/rosacli" "github.com/openshift/rosa/tests/utils/profilehandler" @@ -259,4 +261,66 @@ var _ = Describe("Cluster Upgrade testing", Expect(output.String()).To(ContainSubstring("are compatible with upgrade")) Expect(output.String()).To(ContainSubstring("Upgrade successfully scheduled for cluster")) }) + + It("to upgrade NON-STS rosa cluster across Y stream - [id:37499]", labels.Critical, labels.Runtime.Upgrade, func() { + + By("Check the cluster version and compare with the profile to decide if skip this case") + jsonData, err := clusterService.GetJSONClusterDescription(clusterID) + Expect(err).To(BeNil()) + clusterVersion := jsonData.DigString("version", "raw_id") + + scheduledDate := time.Now().Format("2006-01-02") + scheduledTime := time.Now().Add(10 * time.Minute).UTC().Format("15:04") + + if profile.Version != "y-1" || profile.ClusterConfig.STS { + Skip("Skip this case as the version defined in profile is not y-1 for non-sts cluster upgrading testing") + } + + By("Find updating version") + versionService := rosaClient.Version + clusterVersionList, err := versionService.ListAndReflectVersions(profile.ChannelGroup, false) + Expect(err).ToNot(HaveOccurred()) + + versions, err := clusterVersionList.FindYStreamUpgradeVersions(clusterVersion) + Expect(err).To(BeNil()) + Expect(len(versions)). + To( + BeNumerically(">", 0), + fmt.Sprintf("No available upgrade version is found for the cluster version %s", clusterVersion)) + upgradingVersion := versions[0] + + By("Upgrade cluster") + output, err := clusterService.Upgrade( + "-c", clusterID, + "--version", upgradingVersion, + "--schedule-date", scheduledDate, + "--schedule-time", scheduledTime, + "-y", + ) + Expect(err).To(BeNil()) + Expect(output.String()).To(ContainSubstring("Upgrade successfully scheduled for cluster")) + + By("Check upgrade state") + err = WaitForUpgradeToState(clusterService, clusterID, con.Scheduled, 4) + Expect(err).To(BeNil()) + err = WaitForUpgradeToState(clusterService, clusterID, con.Started, 70) + Expect(err).To(BeNil()) + }) }) + +func WaitForUpgradeToState(c rosacli.ClusterService, clusterID string, state string, timeout int) error { + startTime := time.Now() + for time.Now().Before(startTime.Add(time.Duration(timeout) * time.Minute)) { + UD, err := c.DescribeUpgradeAndReflect(clusterID) + if err != nil { + return err + } else { + if UD.UpgradeState == state { + return nil + } + time.Sleep(1 * time.Minute) + } + } + return fmt.Errorf("ERROR!Timeout after %d minutes to wait for the upgrade into status %s of cluster %s", + timeout, state, clusterID) +} diff --git a/tests/utils/common/constants/cluster.go b/tests/utils/common/constants/cluster.go index 2bd375dbcc..9f24c74611 100644 --- a/tests/utils/common/constants/cluster.go +++ b/tests/utils/common/constants/cluster.go @@ -37,6 +37,13 @@ const ( Validating = "validating" ) +// cluster upgrade status +const ( + Scheduled = "scheduled" + Started = "started" + Delayed = "delayed" +) + // version pattern supported for the CI var ( VersionLatestPattern = regexp.MustCompile("latest") diff --git a/tests/utils/exec/rosacli/cluster_service.go b/tests/utils/exec/rosacli/cluster_service.go index 5d22431281..6f65711d2c 100644 --- a/tests/utils/exec/rosacli/cluster_service.go +++ b/tests/utils/exec/rosacli/cluster_service.go @@ -29,6 +29,8 @@ type ClusterService interface { EditCluster(clusterID string, flags ...string) (bytes.Buffer, error) DeleteUpgrade(flags ...string) (bytes.Buffer, error) Upgrade(flags ...string) (bytes.Buffer, error) + DescribeUpgrade(clusterID string, flags ...string) (bytes.Buffer, error) + DescribeUpgradeAndReflect(clusterID string) (*UpgradeDescription, error) InstallLog(clusterID string, flags ...string) (bytes.Buffer, error) UnInstallLog(clusterID string, flags ...string) (bytes.Buffer, error) @@ -70,6 +72,14 @@ type ClusterList struct { Clusters []ClusterListItem `yaml:"Clusters,omitempty"` } +// Struct for the 'rosa describe upgrade' output +type UpgradeDescription struct { + ID string `yaml:"ID,omitempty"` + ClusterID string `yaml:"Cluster ID,omitempty"` + NextRun string `yaml:"Next Run,omitempty"` + UpgradeState string `yaml:"Upgrade State,omitempty"` +} + // Struct for the 'rosa describe cluster' output type ClusterDescription struct { Name string `yaml:"Name,omitempty"` @@ -261,6 +271,42 @@ func (c *clusterService) Upgrade(flags ...string) (bytes.Buffer, error) { return upgrade.Run() } +func (c *clusterService) DescribeUpgrade(clusterID string, flags ...string) (bytes.Buffer, error) { + combflags := append([]string{"-c", clusterID}, flags...) + describe := c.client.Runner. + Cmd("describe", "upgrade"). + CmdFlags(combflags...) + return describe.Run() +} + +func (c *clusterService) DescribeUpgradeAndReflect(clusterID string) (res *UpgradeDescription, err error) { + output, err := c.DescribeUpgrade(clusterID) + if err != nil { + return nil, err + } + return c.ReflectUpgradeDescription(output) +} + +func (c *clusterService) ReflectUpgradeDescription(result bytes.Buffer) (res *UpgradeDescription, err error) { + var data []byte + res = new(UpgradeDescription) + theMap, err := c.client. + Parser. + TextData. + Input(result). + Parse(). + YamlToMap() + if err != nil { + return + } + data, err = yaml.Marshal(&theMap) + if err != nil { + return + } + err = yaml.Unmarshal(data, res) + return res, err +} + func (c *clusterService) InstallLog(clusterID string, flags ...string) (bytes.Buffer, error) { installLog := c.client.Runner. Cmd("logs", "install", "-c", clusterID).