Skip to content

Commit

Permalink
Merge pull request #2251 from jameszwang/ocm-9304
Browse files Browse the repository at this point in the history
OCM-9304 | test: Automate OCP-37499 Users can upgrade NON-STS rosa cluster across Y stream
  • Loading branch information
openshift-merge-bot[bot] committed Jul 23, 2024
2 parents bd912b3 + d0a8c98 commit 4d2071b
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/ci/data/profiles/rosa-classic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,30 @@ profiles:
admin_enabled: false
account-role:
path: "/test/"
permission_boundary: ""
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
64 changes: 64 additions & 0 deletions tests/e2e/test_rosacli_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package e2e

import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift-online/ocm-common/pkg/aws/aws_client"

"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"
Expand Down Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions tests/utils/common/constants/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
46 changes: 46 additions & 0 deletions tests/utils/exec/rosacli/cluster_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit 4d2071b

Please sign in to comment.