Skip to content

Commit

Permalink
OCM-9778 | test: Automate OCP-57094 Describe/List rosa upgrade via ro…
Browse files Browse the repository at this point in the history
…sacli
  • Loading branch information
jameszwang committed Jul 24, 2024
1 parent 2431a23 commit b0ff521
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 2 deletions.
117 changes: 115 additions & 2 deletions tests/e2e/test_rosacli_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path"
"strconv"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -592,7 +593,7 @@ var _ = Describe("Classic cluster creation validation",
clusterName := "cluster-45161"
operatorPrefix := "cluster-45161-asdf"

By("Create cluster with one Y-1 version")
By("Create cluster with one Y - 1 version")
ocmResourceService := rosaClient.OCMResource
versionService := rosaClient.Version
accountRoleList, _, err := ocmResourceService.ListAccountRole()
Expand All @@ -614,7 +615,7 @@ var _ = Describe("Classic cluster creation validation",
Expect(err).To(BeNil())
var clusterVersion string
if foundVersion == nil {
Skip("No cluster version < y-1 found for compatibility testing")
Skip("No cluster version < y - 1 found for compatibility testing")
}
clusterVersion = foundVersion.Version

Expand Down Expand Up @@ -1746,3 +1747,115 @@ var _ = Describe("create/delete operator-roles and oidc-provider to cluster",
}
})
})

var _ = Describe("Describe/List rosa upgrade",
labels.Feature.Cluster, func() {
defer GinkgoRecover()
var (
rosaClient *rosacli.Client
clusterService rosacli.ClusterService
clusterID string
profile *profilehandler.Profile
)

BeforeEach(func() {
By("Get the cluster")
clusterID = config.GetClusterID()
Expect(clusterID).ToNot(Equal(""), "ClusterID is required. Please export CLUSTER_ID")

By("Init the client")
rosaClient = rosacli.NewClient()
clusterService = rosaClient.Cluster

By("Load the profile")
profile = profilehandler.LoadProfileYamlFileByENV()
})

AfterEach(func() {
By("Delete cluster upgrade")
output, err := clusterService.DeleteUpgrade("-c", clusterID, "-y")
Expect(err).ToNot(HaveOccurred())
Expect(output.String()).To(ContainSubstring("Successfully canceled scheduled upgrade on cluster '%s'", clusterID))

By("Clean remaining resources")
err = rosaClient.CleanResources(clusterID)
Expect(err).ToNot(HaveOccurred())
})

It("to list/describe rosa upgrade via ROSA CLI - [id:57094]",
labels.High, labels.Runtime.Day2,
func() {
By("Check the help message of 'rosa describe upgrade -h'")
output, err := clusterService.DescribeUpgrade(clusterID, "-h")
Expect(err).To(BeNil())
Expect(output.String()).To(ContainSubstring("rosa describe upgrade [flags]"))
Expect(output.String()).To(ContainSubstring("-c, --cluster"))
Expect(output.String()).To(ContainSubstring("--machinepool"))
Expect(output.String()).To(ContainSubstring("-y, --yes"))

By("Check list upgrade for the cluster with latest version")
if profile.Version == "latest" {
output, err = clusterService.ListUpgrade(clusterID)
Expect(err).To(BeNil())
Expect(output.String()).To(ContainSubstring("There are no available upgrades for cluster '%s'", clusterID))
}

By("Upgrade cluster and check list/describe upgrade")
if profile.Version == "y-1" {
scheduledDate := time.Now().Format("2006-01-02")
scheduledTime := time.Now().Add(20 * time.Minute).UTC().Format("15:04")

jsonData, err := clusterService.GetJSONClusterDescription(clusterID)
Expect(err).To(BeNil())
clusterVersion := jsonData.DigString("version", "raw_id")

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")
if profile.ClusterConfig.STS {
output, err = clusterService.Upgrade(
"-c", clusterID,
"--version", upgradingVersion,
"--schedule-date", scheduledDate,
"--schedule-time", scheduledTime,
"-m", "auto",
"-y",
)
} else {
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 '%s'", clusterID))

time.Sleep(2 * time.Minute)
By("Check list upgrade")
output, err = clusterService.ListUpgrade(clusterID)
Expect(err).To(BeNil())
Expect(output.String()).To(ContainSubstring("%s scheduled for %s %s UTC", upgradingVersion,
scheduledDate, scheduledTime))

By("Check describe upgrade")
UD, err := clusterService.DescribeUpgradeAndReflect(clusterID)
Expect(err).To(BeNil())
Expect(UD.ClusterID).To(Equal(clusterID))
Expect(UD.NextRun).To(Equal(fmt.Sprintf("%s %s UTC", scheduledDate, scheduledTime)))
Expect(UD.UpgradeState).To(Equal("scheduled"))
}
})
})
9 changes: 9 additions & 0 deletions tests/utils/exec/rosacli/cluster_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ClusterService interface {
Upgrade(flags ...string) (bytes.Buffer, error)
DescribeUpgrade(clusterID string, flags ...string) (bytes.Buffer, error)
DescribeUpgradeAndReflect(clusterID string) (*UpgradeDescription, error)
ListUpgrade(clusterID string, flags ...string) (bytes.Buffer, error)
InstallLog(clusterID string, flags ...string) (bytes.Buffer, error)
UnInstallLog(clusterID string, flags ...string) (bytes.Buffer, error)

Expand Down Expand Up @@ -307,6 +308,14 @@ func (c *clusterService) ReflectUpgradeDescription(result bytes.Buffer) (res *Up
return res, err
}

func (c *clusterService) ListUpgrade(clusterID string, flags ...string) (bytes.Buffer, error) {
combflags := append([]string{"-c", clusterID}, flags...)
describe := c.client.Runner.
Cmd("list", "upgrade").
CmdFlags(combflags...)
return describe.Run()
}

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 b0ff521

Please sign in to comment.