Skip to content

Commit

Permalink
OCM-9376 | ci: Fix latest version has no z-stream upgrade issue
Browse files Browse the repository at this point in the history
Fix y-stream upgrade issue

Fix lint issue
  • Loading branch information
xueli181114 committed Jul 4, 2024
1 parent ff38673 commit 1321770
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
83 changes: 82 additions & 1 deletion tests/utils/exec/rosacli/version_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Masterminds/semver"

"github.com/openshift/rosa/tests/utils/common"
"github.com/openshift/rosa/tests/utils/log"
)

Expand Down Expand Up @@ -208,9 +209,10 @@ func (vl *OpenShiftVersionTableList) FindNearestBackwardOptionalVersion(
}

}
if len(results) >= optionalsub-1 {
if len(results) > optionalsub-1 {
vs = results[optionalsub-1]
}

return

}
Expand Down Expand Up @@ -352,3 +354,82 @@ func (vl *OpenShiftVersionTableList) FindYStreamUpgradeVersions(
}
return foundVersions, err
}

// FindZStreamUpgradableVersion will find a z-stream upgradable version for the upgrade testing
// throttleVersion can be set to empty, it will use the lastest one who has availabel versions
// when throttleVersion set will find the versions who can be upgraded to a version and not higher than it
// For example, there is a cluster with version 4.15.19, but there is lower version can be upgraded to 4.15.19.
// A case need to test nodepool upgrade, a lower and upgradable version is needed which is no higher than 4.15.19
func (vl *OpenShiftVersionTableList) FindZStreamUpgradableVersion(throttleVersion string, step int) (
vs *OpenShiftVersionTableOutput, err error) {
if step <= 0 {
log.Logger.Errorf("optionsub must be equal or greater than 1")
return
}
vl, _ = vl.Sort(true)
versionScopes := vl.OpenShiftVersions
if throttleVersion != "" {
vl, err := vl.FilterVersionsLowerThan(throttleVersion)
if err != nil {
return nil, err
}
vl, _ = vl.Sort(true)
versionScopes = vl.OpenShiftVersions
}
for _, version := range versionScopes {
semVersion, err := semver.NewVersion(version.Version)
if err != nil {
return nil, err
}
for _, availableUpgradeVersion := range common.ParseCommaSeparatedStrings(version.AvailableUpgrades) {
semAV, err := semver.NewVersion(availableUpgradeVersion)
if err != nil {
return nil, err
}
if semAV.Patch()-semVersion.Patch() == int64(step) {
vs = version
return vs, nil
}
}
}
return
}

// FindYStreamUpgradableVersion will find a y-stream upgradable version testing
// throttleVersion can be empty, will use the lastest one who has availabel versions
// when throttleVersion not empty will find the versions who can be upgraded to a version which
// is not higher than throttleVersion
// For example, there is a cluster with version 4.15.19,
// but there is lower version can be upgraded to 4.15.19.
// There is a case need to test nodepool upgrade,
// a lower and upgradable version is needed which is no higher than 4.15.19
func (vl *OpenShiftVersionTableList) FindYStreamUpgradableVersion(throttleVersion string) (
vs *OpenShiftVersionTableOutput, err error) {
vl, _ = vl.Sort(true)
versionScopes := vl.OpenShiftVersions
if throttleVersion != "" {
vl, err := vl.FilterVersionsLowerThan(throttleVersion)
if err != nil {
return nil, err
}
vl, _ = vl.Sort(true)
versionScopes = vl.OpenShiftVersions
}
for _, version := range versionScopes {
semVersion, err := semver.NewVersion(version.Version)
if err != nil {
return nil, err
}
for _, availableUpgradeVersion := range common.ParseCommaSeparatedStrings(version.AvailableUpgrades) {
semAV, err := semver.NewVersion(availableUpgradeVersion)
if err != nil {
return nil, err
}
if semAV.Minor() != semVersion.Minor() {
vs = version
return vs, nil
}
}
}
return
}
4 changes: 2 additions & 2 deletions tests/utils/profilehandler/data_preparation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func PrepareVersion(client *rosacli.Client, versionRequirement string, channelGr
log.Logger.Infof("Going to prepare version for %s stream %v versions lower", stream, versionStep)
switch stream {
case "y":
version, err := versionList.FindNearestBackwardMinorVersion(latestVersion.Version, int64(versionStep), true, true)
version, err := versionList.FindYStreamUpgradableVersion("")
return version, err
case "z":
version, err := versionList.FindNearestBackwardOptionalVersion(latestVersion.Version, versionStep, true)
version, err := versionList.FindZStreamUpgradableVersion("", versionStep)
return version, err
default:
return nil, fmt.Errorf("not supported stream configuration %s", stream)
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/profilehandler/profile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ func GenerateClusterCreateFlags(profile *Profile, client *rosacli.Client) ([]str

if profile.Version != "" {
version, err := PrepareVersion(client, profile.Version, profile.ChannelGroup, profile.ClusterConfig.HCP)

if err != nil {
return flags, err
}
if version == nil {
err = fmt.Errorf("cannot find a version match the condition %s", profile.Version)
return flags, err
}
profile.Version = version.Version
flags = append(flags, "--version", version.Version)

Expand Down

0 comments on commit 1321770

Please sign in to comment.