Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile and test for Hub cluster part #5

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
natifridman marked this conversation as resolved.
Show resolved Hide resolved
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")
ccardenosa marked this conversation as resolved.
Show resolved Hide resolved

@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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's missing bash fixture?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not so clear why you need to use parameterize here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said before, I just moved the code that was previously in the Openshift-CI step here for a conceptual test. At the moment I'm not that interested in this test being really very comprehensive, just that it works.

When we have the Openshift-CI part integrated, we can come back to this and discuss what tests to run to ensure that the Hub cluster and its components have been correctly installed.

My idea is that, later on, we can adjust the tests to run from eco-ci-cd.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

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"