Skip to content

Commit 090e99f

Browse files
Merge pull request #6116 from agullon/USHIFT-6491
USHIFT-6491: Improve gitops test
2 parents 0027601 + 63f72b2 commit 090e99f

4 files changed

Lines changed: 109 additions & 30 deletions

File tree

test/bin/pyutils/generate_common_versions.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import argparse
1111
import logging
1212
import pathlib
13+
import time
1314

1415
sys.path.append(str(pathlib.Path(__file__).resolve().parent / '../../../scripts/pyutils'))
1516
import gitutils # noqa: E402
@@ -24,9 +25,6 @@
2425
# The version of systemd-logs image included in the sonobuoy release.
2526
CNCF_SYSTEMD_LOGS_VERSION = "v0.4"
2627

27-
# The current version of the microshift-gitops package.
28-
GITOPS_VERSION = "1.19"
29-
3028

3129
logging.basicConfig(
3230
level=logging.INFO,
@@ -209,6 +207,38 @@ def get_release_version_string(repo, var_name):
209207
return None
210208

211209

210+
def get_gitops_version(minor_version):
211+
"""
212+
Get the version of the microshift-gitops package.
213+
Versions compatible with MicroShift: https://access.redhat.com/product-life-cycles?product=Red%20Hat%20OpenShift%20GitOps
214+
"""
215+
url = "https://access.redhat.com/product-life-cycles/api/v1/products"
216+
params = {"name": "Red Hat OpenShift GitOps"}
217+
resp = None
218+
for attempt in range(1, 4):
219+
try:
220+
resp = requests.get(url, params=params, timeout=10)
221+
resp.raise_for_status()
222+
break
223+
except Exception as e:
224+
logging.warning(f"Attempt {attempt} failed with error: {e}. Retrying...")
225+
time.sleep(2)
226+
continue
227+
228+
if resp is None:
229+
logging.error(f"Failed to fetch data from {url} after 3 attempts")
230+
return ""
231+
data = resp.json()
232+
for current_microshift_minor_version in range(minor_version, minor_version - 4, -1):
233+
for gitops_version_from_api_docs in data.get("data", [{}])[0].get("versions", []):
234+
gitops_version_ocp_compatibility = gitops_version_from_api_docs.get("openshift_compatibility") or ""
235+
gitops_version_number = gitops_version_from_api_docs.get("name")
236+
if f"4.{current_microshift_minor_version}" in gitops_version_ocp_compatibility:
237+
logging.info(f"Latest GitOps version: {gitops_version_number} which is compatible with OCP {gitops_version_ocp_compatibility}")
238+
return gitops_version_number
239+
return ""
240+
241+
212242
def generate_common_versions(minor_version):
213243
previous_minor_version = minor_version - 1
214244
yminus2_minor_version = minor_version - 2
@@ -256,6 +286,10 @@ def generate_common_versions(minor_version):
256286
# The 'rhocp_minor_y2' should always be the y-2 minor version number.
257287
rhocp_minor_y2 = yminus2_minor_version
258288

289+
# The current version of the microshift-gitops package.
290+
logging.info("Getting GITOPS_VERSION")
291+
gitops_version = get_gitops_version(minor_version)
292+
259293
template_path = pathlib.Path(__file__).resolve().parent / '../../assets/common_versions.sh.template'
260294

261295
with open(template_path, 'r') as f:
@@ -276,7 +310,7 @@ def generate_common_versions(minor_version):
276310
rhocp_minor_y2=rhocp_minor_y2,
277311
CNCF_SONOBUOY_VERSION=CNCF_SONOBUOY_VERSION,
278312
CNCF_SYSTEMD_LOGS_VERSION=CNCF_SYSTEMD_LOGS_VERSION,
279-
GITOPS_VERSION=GITOPS_VERSION,
313+
GITOPS_VERSION=gitops_version,
280314
ARCH=ARCH
281315
)
282316

test/suites/gitops/gitops.robot

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ Documentation MicroShift GitOps tests
33
44
Resource ../../resources/microshift-process.resource
55

6-
Suite Setup Setup Suite With Namespace
7-
Suite Teardown Teardown Suite With Namespace
6+
Suite Setup Setup Suite
7+
Suite Teardown Teardown Suite
8+
9+
10+
*** Variables ***
11+
${APPLICATION_MANIFEST_PATH} ${CURDIR}/spring-petclinic-app.yaml
12+
${APPLICATION_NAMESPACE} spring-petclinic
13+
${APPLICATION_NAME} spring-petclinic
14+
${GITOPS_NAMESPACE} openshift-gitops
815

916

1017
*** Test Cases ***
@@ -14,10 +21,32 @@ Verify GitOps Pods Start Correctly
1421
Wait Until Keyword Succeeds 2min 10s
1522
... All Pods Should Be Running openshift-gitops
1623

17-
Verify Workload Deployed Correctly
18-
[Documentation] Deploys workload and waits for ready status
24+
Verify Application Deployed Correctly
25+
[Documentation] Deploys an application and waits for it to be Healthy
26+
... 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
27+
[Setup] Setup Application Deployment
1928

20-
VAR ${manifest_path}= ${CURDIR}/test-deployment.yaml
21-
Oc Apply -f ${manifest_path} -n ${NAMESPACE}
29+
Wait Until Resource Exists applications ${APPLICATION_NAME} ${GITOPS_NAMESPACE} timeout=120s
30+
Oc Wait
31+
... -n ${GITOPS_NAMESPACE} application ${APPLICATION_NAME}
32+
... --for=jsonpath='{.status.sync.status}'=Synced --timeout=300s
2233
Wait Until Keyword Succeeds 5min 10s
23-
... Named Deployment Should Be Available test-app
34+
... Oc Wait
35+
... -n ${APPLICATION_NAMESPACE} pod --selector=app=${APPLICATION_NAME}
36+
... --for=condition=Ready --timeout=30s
37+
38+
[Teardown] Teardown Application Deployment
39+
40+
41+
*** Keywords ***
42+
Setup Application Deployment
43+
[Documentation] Skip if not x86_64 (application image is amd64-only),
44+
... then setup the application deployment.
45+
${arch}= Get System Architecture
46+
Skip If "${arch}" != "x86_64" Application image does not support ${arch}
47+
Oc Apply -f ${APPLICATION_MANIFEST_PATH}
48+
49+
Teardown Application Deployment
50+
[Documentation] Teardown the application deployment
51+
Run Keyword And Ignore Error Oc Delete -f ${APPLICATION_MANIFEST_PATH}
52+
Run Keyword And Ignore Error Oc Delete ns ${APPLICATION_NAMESPACE}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
kind: AppProject
2+
apiVersion: argoproj.io/v1alpha1
3+
metadata:
4+
name: default
5+
namespace: openshift-gitops
6+
spec:
7+
clusterResourceWhitelist:
8+
- group: '*'
9+
kind: '*'
10+
destinations:
11+
- namespace: '*'
12+
server: '*'
13+
sourceRepos:
14+
- '*'
15+
---
16+
kind: Application
17+
apiVersion: argoproj.io/v1alpha1
18+
metadata:
19+
name: spring-petclinic
20+
namespace: openshift-gitops
21+
spec:
22+
destination:
23+
namespace: spring-petclinic
24+
server: https://kubernetes.default.svc
25+
project: default
26+
source:
27+
directory:
28+
recurse: true
29+
path: app
30+
repoURL: https://github.com/siamaksade/openshift-gitops-getting-started
31+
syncPolicy:
32+
automated: {}
33+
syncOptions:
34+
- CreateNamespace=true
35+
- ServerSideApply=true

test/suites/gitops/test-deployment.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)