Repository: openshift/assisted-service (language: python)

Issue:
MGMT-17513: Change the latest release image retrieved in GetReleaseImage using major.minor OpenShift version to latest non-beta release image if exists, or latest beta release image otherwise
Currently `GetReleaseImage` function retrieves the latest matching release image found if when the `OpenShift` version specified is in the form of major.minor. This PR Changes the latest release image retrieved in `GetReleaseImage` using major.minor `OpenShift` version to latest non-beta release image if exists, or latest beta release image otherwise.

<!--
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

You can refer to [Kubernetes community documentation] on writing good commit messages, which provides good tips and ideas.

Some PRs address specific issues. Please, refer to the [CONTRIBUTING] documentation for more
information on how to link a PR to an existing issue.

It's recommended to take a few extra minutes to provide more information about
how this code was tested. Here are some questions that may be worth answering:

- Should this PR be tested by the reviewer?
- Is this PR relying on CI for an e2e test run?
- Should this PR be tested in a specific environment?
- Any logs, screenshots, etc that can help with the review process?

-->

## List all the issues related to this PR

- [ ] New Feature <!-- new functionality -->
- [ ] Enhancement <!-- refactor, code changes, improvement, that won't add new features -->
- [x] Bug fix
- [ ] Tests
- [ ] Documentation
- [ ] CI/CD <!-- Notice that changes for Dockerfiles/Jenkinsfiles aren't tested in CI due to a known bug. -->

## What environments does this code impact?

- [ ] Automation (CI, tools, etc)
- [x] Cloud
- [ ] Operator Managed Deployments
- [ ] None

## How was this code tested?

<!-- Please, select one or more if needed: -->

- [x] assisted-test-infra environment
- [ ] dev-scripts environment
- [ ] Reviewer's test appreciated
- [x] Waiting for CI to do a full test run
- [ ] Manual (Elaborate on how it was tested)
- [ ] No tests needed

## Checklist

- [x] Title and description added to both, commit and PR.
- [x] Relevant issues have been associated (see [CONTRIBUTING] guide)
- [x] This change does not require a documentation update (docstring, `docs`, README, etc)
- [x] Does this change include unit-tests (note that code changes require unit-tests)

## Reviewers Checklist

- Are the title and description (in both PR and commit) meaningful and clear?
- Is there a bug required (and linked) for this change?
- Should this PR be backported?

[Kubernetes community documentation]: https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#commit-message-guidelines
[CONTRIBUTING]: https://github.com/openshift/assisted-service/blob/master/CONTRIBUTING.md



Discussion / hints:

Fix patch:
diff --git a/internal/versions/rest_api_versions.go b/internal/versions/rest_api_versions.go
index 51a76812934..8c188399bdc 100644
--- a/internal/versions/rest_api_versions.go
+++ b/internal/versions/rest_api_versions.go
@@ -163,6 +163,9 @@ func validateCPUArchitecture(cpuArchitecture string) error {
 	return releaseImage.Validate(strfmt.Default)
 }
 
+// getLatestReleaseImage returns the latest release image among a list of release images not included in ignore list,
+// or error if none of the release images match. The latest release image is considered the latest none beta release image,
+// or if all matching release images are beta then just the latest.
 func getLatestReleaseImage(releaseImages models.ReleaseImages, ignoredOpenshiftVersions []string) (*models.ReleaseImage, error) {
 	var latestReleaseImage *models.ReleaseImage
 
@@ -176,13 +179,20 @@ func getLatestReleaseImage(releaseImages models.ReleaseImages, ignoredOpenshiftV
 			continue
 		}
 
-		lessThan, err := common.BaseVersionLessThan(*releaseImage.Version, *latestReleaseImage.Version)
+		isLatest, err := common.BaseVersionLessThan(*releaseImage.Version, *latestReleaseImage.Version)
 		if err != nil {
 			return nil, err
 		}
 
-		if lessThan {
-			latestReleaseImage = releaseImage
+		// none-beta > beta, later-beta > beta
+		if latestReleaseImage.SupportLevel == models.OpenshiftVersionSupportLevelBeta {
+			if isLatest || releaseImage.SupportLevel != models.OpenshiftVersionSupportLevelBeta {
+				latestReleaseImage = releaseImage
+			}
+		} else { // non-beta-later > non-beta
+			if isLatest && releaseImage.SupportLevel != models.OpenshiftVersionSupportLevelBeta {
+				latestReleaseImage = releaseImage
+			}
 		}
 	}
 


Test patch:
diff --git a/internal/versions/rest_api_versions_test.go b/internal/versions/rest_api_versions_test.go
index c819945a338..b552d7c77dc 100644
--- a/internal/versions/rest_api_versions_test.go
+++ b/internal/versions/rest_api_versions_test.go
@@ -85,6 +85,15 @@ var _ = Describe("GetReleaseImage", func() {
 				SupportLevel:     models.ReleaseImageSupportLevelProduction,
 				Default:          false,
 			},
+			{
+				OpenshiftVersion: swag.String("4.14"),
+				Version:          swag.String("4.14.3"),
+				CPUArchitecture:  swag.String(common.X86CPUArchitecture),
+				CPUArchitectures: []string{common.X86CPUArchitecture},
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.14.3-x86_64"),
+				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
+				Default:          false,
+			},
 			{
 				OpenshiftVersion: swag.String("4.14"),
 				Version:          swag.String("4.14.3"),
@@ -94,13 +103,23 @@ var _ = Describe("GetReleaseImage", func() {
 				SupportLevel:     models.ReleaseImageSupportLevelProduction,
 				Default:          false,
 			},
+
 			{
 				OpenshiftVersion: swag.String("4.15"),
 				Version:          swag.String("4.15.1"),
 				CPUArchitecture:  swag.String(common.X86CPUArchitecture),
 				CPUArchitectures: []string{common.X86CPUArchitecture},
 				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.15.1-x86_64"),
-				SupportLevel:     models.ReleaseImageSupportLevelProduction,
+				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
+				Default:          false,
+			},
+			{
+				OpenshiftVersion: swag.String("4.15"),
+				Version:          swag.String("4.15.2"),
+				CPUArchitecture:  swag.String(common.X86CPUArchitecture),
+				CPUArchitectures: []string{common.X86CPUArchitecture},
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.15.2-x86_64"),
+				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
 				Default:          false,
 			},
 		}
@@ -111,6 +130,10 @@ var _ = Describe("GetReleaseImage", func() {
 		releaseImage, err := handler.GetReleaseImage(ctx, "4.14", common.X86CPUArchitecture, pullSecret)
 		Expect(err).ShouldNot(HaveOccurred())
 		Expect(*releaseImage.Version).Should(Equal("4.14.2"))
+
+		releaseImage, err = handler.GetReleaseImage(ctx, "4.15", common.X86CPUArchitecture, pullSecret)
+		Expect(err).ShouldNot(HaveOccurred())
+		Expect(*releaseImage.Version).Should(Equal("4.15.2"))
 	})
 
 	It("gets the exact matching release image with major.minor.patch / prerelease openshiftVersion", func() {