From b661f2985fa4a5b279b31e070f6d824777fecb4e Mon Sep 17 00:00:00 2001 From: Carlos Cardenosa Date: Mon, 2 Sep 2024 14:06:32 +0200 Subject: [PATCH 1/2] Dockerfile and test for Hub cluster part Signed-off-by: Carlos Cardenosa --- .../ztp-left-shifting/sno-hub/Dockerfile | 3 ++ .../sno-hub/check-hub-installation.py | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 openshift-ci/ztp-left-shifting/sno-hub/Dockerfile create mode 100644 tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py diff --git a/openshift-ci/ztp-left-shifting/sno-hub/Dockerfile b/openshift-ci/ztp-left-shifting/sno-hub/Dockerfile new file mode 100644 index 0000000..f4d63e0 --- /dev/null +++ b/openshift-ci/ztp-left-shifting/sno-hub/Dockerfile @@ -0,0 +1,3 @@ +FROM registry.ci.openshift.org/ci/telco-runner + +RUN pip3 install --no-cache-dir "pytest==8.2.2" "pytest-shell==0.3.2" "requests==2.32.3" diff --git a/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py b/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py new file mode 100644 index 0000000..c070790 --- /dev/null +++ b/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py @@ -0,0 +1,45 @@ +import os +import time +import requests +import pytest + +kubeconfig=os.getenv("KUBECONFIG") +ocp_hub_version=os.getenv("OCP_HUB_VERSION") +mch_ns=os.getenv("MCH_NAMESPACE") + +@pytest.mark.parametrize("endpoint", [ + {"cmd": f"oc --kubeconfig {kubeconfig} whoami --show-console", "response": 200}, + {"cmd": f"oc --kubeconfig {kubeconfig} get managedcluster local-cluster -ojsonpath='{{.spec.managedClusterClientConfigs[0].url}}'", "response": 403}, +]) +def test_http_endpoint(bash, endpoint): + if "url" in endpoint: + url = endpoint.url + else: + oc_cmd = endpoint['cmd'] + url = bash.run_script_inline([oc_cmd]) + response = requests.get(url, verify=False) + assert response.status_code == endpoint["response"], f"Endpoint {url} is not accessible. Status code: {response.status_code}" + +def test_cluster_version(bash): + oc_cmd = "oc get clusterversion version -ojsonpath='{.status.desired.version}'" + assert bash.run_script_inline([oc_cmd]).startswith(f"{ocp_hub_version}") + +@pytest.mark.parametrize("namespace", [ + "openshift-local-storage", + f"{mch_ns}", + "multicluster-engine", + "openshift-gitops", +]) +def test_ztp_namespaces(bash, namespace): + oc_cmd = f"oc get ns {namespace} " + "-ojsonpath='{.metadata.name}'" + assert bash.run_script_inline([oc_cmd]) == namespace + + count = 0 + attempts = 10 + while attempts > 0: + oc_cmd = f"oc -n {namespace} get po --no-headers | grep -v -E 'Running|Completed' | wc -l" + if bash.run_script_inline([oc_cmd]) == '0': + break + attempts -= 1 + time.sleep(60) + assert attempts > 0, f"Not all PODs in {namespace} namespace are ready yet" From 96675e7a4b1714b66fc0a99bd5187c4427f70d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Carde=C3=B1osa?= Date: Mon, 2 Sep 2024 15:19:30 +0200 Subject: [PATCH 2/2] Update tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py Co-authored-by: Nati Fridman --- .../ztp-left-shifting/sno-hub/check-hub-installation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py b/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py index c070790..6c5c397 100644 --- a/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py +++ b/tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py @@ -3,9 +3,9 @@ import requests import pytest -kubeconfig=os.getenv("KUBECONFIG") -ocp_hub_version=os.getenv("OCP_HUB_VERSION") -mch_ns=os.getenv("MCH_NAMESPACE") +kubeconfig = os.getenv("KUBECONFIG") +ocp_hub_version = os.getenv("OCP_HUB_VERSION") +mch_ns = os.getenv("MCH_NAMESPACE") @pytest.mark.parametrize("endpoint", [ {"cmd": f"oc --kubeconfig {kubeconfig} whoami --show-console", "response": 200},