From 9b4dc889408ca860c6b67424367b568b80bf2bfe Mon Sep 17 00:00:00 2001 From: Alejandro Gullon Date: Mon, 16 Mar 2026 11:17:10 +0100 Subject: [PATCH] USHIFT-6491: update gitops RF test to target latest available gitop version and exercise documentation app pre-commit.check-secrets: ENABLED --- test/bin/pyutils/generate_common_versions.py | 44 ++++++++++++++++++-- test/suites/gitops/gitops.robot | 43 +++++++++++++++---- test/suites/gitops/spring-petclinic-app.yaml | 35 ++++++++++++++++ test/suites/gitops/test-deployment.yaml | 19 --------- 4 files changed, 111 insertions(+), 30 deletions(-) create mode 100644 test/suites/gitops/spring-petclinic-app.yaml delete mode 100644 test/suites/gitops/test-deployment.yaml diff --git a/test/bin/pyutils/generate_common_versions.py b/test/bin/pyutils/generate_common_versions.py index b51f4162b8..289750c457 100755 --- a/test/bin/pyutils/generate_common_versions.py +++ b/test/bin/pyutils/generate_common_versions.py @@ -10,6 +10,7 @@ import argparse import logging import pathlib +import time sys.path.append(str(pathlib.Path(__file__).resolve().parent / '../../../scripts/pyutils')) import gitutils # noqa: E402 @@ -24,9 +25,6 @@ # The version of systemd-logs image included in the sonobuoy release. CNCF_SYSTEMD_LOGS_VERSION = "v0.4" -# The current version of the microshift-gitops package. -GITOPS_VERSION = "1.19" - logging.basicConfig( level=logging.INFO, @@ -209,6 +207,40 @@ def get_release_version_string(repo, var_name): return None +def get_gitops_version(minor_version): + """ + Get the version of the microshift-gitops package. + Versions compatible with MicroShift: https://access.redhat.com/product-life-cycles?product=Red%20Hat%20OpenShift%20GitOps + """ + url = "https://access.redhat.com/product-life-cycles/api/v1/products" + params = {"name": "Red Hat OpenShift GitOps"} + resp = None + for attempt in range(1, 4): + try: + resp = requests.get(url, params=params, timeout=10) + resp.raise_for_status() + break + except Exception as e: + logging.warning(f"Attempt {attempt} failed with error: {e}. Retrying...") + time.sleep(2) + continue + + if resp is None: + logging.error(f"Failed to fetch data from {url} after 3 attempts") + return "" + data = resp.json() + for current_microshift_minor_version in range(minor_version, minor_version - 4, -1): + for gitops_version_from_api_docs in data.get("data", [{}])[0].get("versions", []): + gitops_version_ocp_compatibility = gitops_version_from_api_docs.get("openshift_compatibility") or [] + if isinstance(gitops_version_ocp_compatibility, str): + gitops_version_ocp_compatibility = [gitops_version_ocp_compatibility] + gitops_version_number = gitops_version_from_api_docs.get("name") + if f"4.{current_microshift_minor_version}" in gitops_version_ocp_compatibility: + logging.info(f"Latest GitOps version: {gitops_version_number} which is compatible with OCP {gitops_version_ocp_compatibility}") + return gitops_version_number + return "" + + def generate_common_versions(minor_version): previous_minor_version = minor_version - 1 yminus2_minor_version = minor_version - 2 @@ -256,6 +288,10 @@ def generate_common_versions(minor_version): # The 'rhocp_minor_y2' should always be the y-2 minor version number. rhocp_minor_y2 = yminus2_minor_version + # The current version of the microshift-gitops package. + logging.info("Getting GITOPS_VERSION") + gitops_version = get_gitops_version(minor_version) + template_path = pathlib.Path(__file__).resolve().parent / '../../assets/common_versions.sh.template' with open(template_path, 'r') as f: @@ -276,7 +312,7 @@ def generate_common_versions(minor_version): rhocp_minor_y2=rhocp_minor_y2, CNCF_SONOBUOY_VERSION=CNCF_SONOBUOY_VERSION, CNCF_SYSTEMD_LOGS_VERSION=CNCF_SYSTEMD_LOGS_VERSION, - GITOPS_VERSION=GITOPS_VERSION, + GITOPS_VERSION=gitops_version, ARCH=ARCH ) diff --git a/test/suites/gitops/gitops.robot b/test/suites/gitops/gitops.robot index edd453e57f..3dce66b65d 100644 --- a/test/suites/gitops/gitops.robot +++ b/test/suites/gitops/gitops.robot @@ -3,8 +3,15 @@ Documentation MicroShift GitOps tests Resource ../../resources/microshift-process.resource -Suite Setup Setup Suite With Namespace -Suite Teardown Teardown Suite With Namespace +Suite Setup Setup Suite +Suite Teardown Teardown Suite + + +*** Variables *** +${APPLICATION_MANIFEST_PATH} ${CURDIR}/spring-petclinic-app.yaml +${APPLICATION_NAMESPACE} spring-petclinic +${APPLICATION_NAME} spring-petclinic +${GITOPS_NAMESPACE} openshift-gitops *** Test Cases *** @@ -14,10 +21,32 @@ Verify GitOps Pods Start Correctly Wait Until Keyword Succeeds 2min 10s ... All Pods Should Be Running openshift-gitops -Verify Workload Deployed Correctly - [Documentation] Deploys workload and waits for ready status +Verify Application Deployed Correctly + [Documentation] Deploys an application and waits for it to be Healthy + ... using the example from official docs: https://docs.redhat.com/en/documentation/red_hat_build_of_microshift/4.20/html/running_applications/microshift-gitops#microshift-gitops-adding-apps_microshift-gitops + [Setup] Setup Application Deployment - VAR ${manifest_path}= ${CURDIR}/test-deployment.yaml - Oc Apply -f ${manifest_path} -n ${NAMESPACE} + Wait Until Resource Exists applications ${APPLICATION_NAME} ${GITOPS_NAMESPACE} timeout=120s + Oc Wait + ... -n ${GITOPS_NAMESPACE} application ${APPLICATION_NAME} + ... --for=jsonpath='{.status.sync.status}'=Synced --timeout=300s Wait Until Keyword Succeeds 5min 10s - ... Named Deployment Should Be Available test-app + ... Oc Wait + ... -n ${APPLICATION_NAMESPACE} pod --selector=app=${APPLICATION_NAME} + ... --for=condition=Ready --timeout=30s + + [Teardown] Teardown Application Deployment + + +*** Keywords *** +Setup Application Deployment + [Documentation] Skip if not x86_64 (application image is amd64-only), + ... then setup the application deployment. + ${arch}= Get System Architecture + Skip If "${arch}" != "x86_64" Application image does not support ${arch} + Oc Apply -f ${APPLICATION_MANIFEST_PATH} + +Teardown Application Deployment + [Documentation] Teardown the application deployment + Run Keyword And Ignore Error Oc Delete -f ${APPLICATION_MANIFEST_PATH} + Run Keyword And Ignore Error Oc Delete ns ${APPLICATION_NAMESPACE} diff --git a/test/suites/gitops/spring-petclinic-app.yaml b/test/suites/gitops/spring-petclinic-app.yaml new file mode 100644 index 0000000000..f00e491fc0 --- /dev/null +++ b/test/suites/gitops/spring-petclinic-app.yaml @@ -0,0 +1,35 @@ +kind: AppProject +apiVersion: argoproj.io/v1alpha1 +metadata: + name: default + namespace: openshift-gitops +spec: + clusterResourceWhitelist: + - group: '*' + kind: '*' + destinations: + - namespace: '*' + server: '*' + sourceRepos: + - '*' +--- +kind: Application +apiVersion: argoproj.io/v1alpha1 +metadata: + name: spring-petclinic + namespace: openshift-gitops +spec: + destination: + namespace: spring-petclinic + server: https://kubernetes.default.svc + project: default + source: + directory: + recurse: true + path: app + repoURL: https://github.com/siamaksade/openshift-gitops-getting-started + syncPolicy: + automated: {} + syncOptions: + - CreateNamespace=true + - ServerSideApply=true diff --git a/test/suites/gitops/test-deployment.yaml b/test/suites/gitops/test-deployment.yaml deleted file mode 100644 index 17c72fc397..0000000000 --- a/test/suites/gitops/test-deployment.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: test-app -spec: - replicas: 1 - selector: - matchLabels: - app: test-app - template: - metadata: - labels: - app: test-app - spec: - containers: - - name: test-app - image: registry.redhat.io/ubi8/httpd-24:latest - ports: - - containerPort: 8080