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

Issue:
MGMT-17764: Update the latest image search functionality in the RestAPI flow to correctly compare pre-release versions
Update the latest image search functionality in the `RestAPI` flow to correctly compare pre-release versions
<!--
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: -->

- [ ] 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 561a4e68931..8ec2a15e930 100644
--- a/internal/versions/rest_api_versions.go
+++ b/internal/versions/rest_api_versions.go
@@ -167,7 +167,10 @@ func getLatestReleaseImage(releaseImages models.ReleaseImages, ignoredOpenshiftV
 			continue
 		}
 
-		isLatest, err := common.BaseVersionLessThan(*releaseImage.Version, *latestReleaseImage.Version)
+		isLatest, err := common.VersionGreaterOrEqual(
+			strings.TrimSuffix(*releaseImage.Version, "-multi"),
+			strings.TrimSuffix(*latestReleaseImage.Version, "-multi"),
+		)
 		if err != nil {
 			return nil, err
 		}


Test patch:
diff --git a/internal/versions/rest_api_versions_test.go b/internal/versions/rest_api_versions_test.go
index 429e5f95dc9..1a2a7f9b14c 100644
--- a/internal/versions/rest_api_versions_test.go
+++ b/internal/versions/rest_api_versions_test.go
@@ -197,29 +197,47 @@ var _ = Describe("GetReleaseImage", func() {
 	It("gets the latest matching release image with major.minor openshiftVersion - all beta support level", func() {
 		releaseImages := models.ReleaseImages{
 			{
-				OpenshiftVersion: swag.String("4.16-multi"),
-				Version:          swag.String("4.16.1-multi"),
-				CPUArchitecture:  swag.String(common.MultiCPUArchitecture),
-				CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
-				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.1-multi"),
+				OpenshiftVersion: swag.String("4.16"),
+				Version:          swag.String("4.16.0-ec.2"),
+				CPUArchitecture:  swag.String(common.X86CPUArchitecture),
+				CPUArchitectures: []string{common.X86CPUArchitecture},
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.0-ec.2-x86_64"),
 				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
 				Default:          false,
 			},
 			{
 				OpenshiftVersion: swag.String("4.16"),
-				Version:          swag.String("4.16.1"),
+				Version:          swag.String("4.16.0-ec.3"),
 				CPUArchitecture:  swag.String(common.X86CPUArchitecture),
 				CPUArchitectures: []string{common.X86CPUArchitecture},
-				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.1-x86_64"),
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.0-ec.3-x86_64"),
+				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
+				Default:          false,
+			},
+			{
+				OpenshiftVersion: swag.String("4.16-multi"),
+				Version:          swag.String("4.16.0-ec.3-multi"),
+				CPUArchitecture:  swag.String(common.MultiCPUArchitecture),
+				CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.0-ec.3-multi"),
+				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
+				Default:          false,
+			},
+			{
+				OpenshiftVersion: swag.String("4.16-multi"),
+				Version:          swag.String("4.16.0-ec.1-multi"),
+				CPUArchitecture:  swag.String(common.MultiCPUArchitecture),
+				CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.0-ec.1-multi"),
 				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
 				Default:          false,
 			},
 			{
 				OpenshiftVersion: swag.String("4.16"),
-				Version:          swag.String("4.16.2"),
+				Version:          swag.String("4.16.0-ec.1"),
 				CPUArchitecture:  swag.String(common.X86CPUArchitecture),
 				CPUArchitectures: []string{common.X86CPUArchitecture},
-				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.2-x86_64"),
+				URL:              swag.String("quay.io/openshift-release-dev/ocp-release:4.16.0-ec.1-x86_64"),
 				SupportLevel:     models.OpenshiftVersionSupportLevelBeta,
 				Default:          false,
 			},
@@ -230,15 +248,15 @@ var _ = Describe("GetReleaseImage", func() {
 
 		releaseImage, err := handler.GetReleaseImage(ctx, "4.16", common.X86CPUArchitecture, pullSecret)
 		Expect(err).ShouldNot(HaveOccurred())
-		Expect(*releaseImage.Version).Should(Equal("4.16.2"))
+		Expect(*releaseImage.Version).Should(Equal("4.16.0-ec.3"))
 
 		releaseImage, err = handler.GetReleaseImage(ctx, "4.16-multi", common.X86CPUArchitecture, pullSecret)
 		Expect(err).ShouldNot(HaveOccurred())
-		Expect(*releaseImage.Version).Should(Equal("4.16.1-multi"))
+		Expect(*releaseImage.Version).Should(Equal("4.16.0-ec.3-multi"))
 
 		releaseImage, err = handler.GetReleaseImage(ctx, "4.16-multi", common.MultiCPUArchitecture, pullSecret)
 		Expect(err).ShouldNot(HaveOccurred())
-		Expect(*releaseImage.Version).Should(Equal("4.16.1-multi"))
+		Expect(*releaseImage.Version).Should(Equal("4.16.0-ec.3-multi"))
 	})
 
 	It("gets the exact matching release image with major.minor.patch / prerelease openshiftVersion", func() {