Skip to content

Commit

Permalink
Merge pull request #5 from openshift-kni/left-shift-telco-hub
Browse files Browse the repository at this point in the history
Dockerfile and test for Hub cluster part
  • Loading branch information
ccardenosa authored Sep 2, 2024
2 parents fd2bebf + 96675e7 commit 511ba53
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openshift-ci/ztp-left-shifting/sno-hub/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 45 additions & 0 deletions tests/pytest/ztp-left-shifting/sno-hub/check-hub-installation.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 511ba53

Please sign in to comment.