diff --git a/tests/utils/exec/rosacli/version_service.go b/tests/utils/exec/rosacli/version_service.go index 998edf7dd9..e8e622a6de 100644 --- a/tests/utils/exec/rosacli/version_service.go +++ b/tests/utils/exec/rosacli/version_service.go @@ -8,6 +8,7 @@ import ( "github.com/Masterminds/semver" + "github.com/openshift/rosa/tests/utils/common" "github.com/openshift/rosa/tests/utils/log" ) @@ -208,9 +209,10 @@ func (vl *OpenShiftVersionTableList) FindNearestBackwardOptionalVersion( } } - if len(results) >= optionalsub-1 { + if len(results) > optionalsub-1 { vs = results[optionalsub-1] } + return } @@ -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 +} diff --git a/tests/utils/profilehandler/data_preparation.go b/tests/utils/profilehandler/data_preparation.go index f7f3f6495c..70ea60b2c3 100644 --- a/tests/utils/profilehandler/data_preparation.go +++ b/tests/utils/profilehandler/data_preparation.go @@ -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) diff --git a/tests/utils/profilehandler/profile_handler.go b/tests/utils/profilehandler/profile_handler.go index d7e12fdebb..8488a3293a 100644 --- a/tests/utils/profilehandler/profile_handler.go +++ b/tests/utils/profilehandler/profile_handler.go @@ -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)