Skip to content

Commit 966d426

Browse files
committed
Add support file for QE tests
1 parent 09b97a3 commit 966d426

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

tests/interop/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Running tests
2+
3+
## Prerequisites
4+
5+
* Openshift cluster with coco-pattern installed
6+
* kubeconfig file for Openshift cluster
7+
* oc client installed at ~/oc_client/oc
8+
9+
## Steps
10+
11+
* create python3 venv, clone multicloud-gitops repository
12+
* export KUBECONFIG=\<path to hub kubeconfig file>
13+
* export INFRA_PROVIDER=azure
14+
* (optional) export WORKSPACE=\<dir to save test results to> (defaults to /tmp)
15+
* cd coco-pattern/tests/interop
16+
* pip install -r requirements.txt
17+
* ./run_tests.sh
18+
19+
## Results
20+
21+
* results .xml files will be placed at $WORKSPACE
22+
* test logs will be placed at $WORKSPACE/.results/test_execution_logs/
23+
* CI badge file will be placed at $WORKSPACE

tests/interop/create_ci_badge.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import json
2+
import os
3+
import subprocess
4+
from datetime import datetime
5+
6+
from junitparser import JUnitXml
7+
8+
oc = os.environ["HOME"] + "/oc_client/oc"
9+
10+
ci_badge = {
11+
"schemaVersion": 1,
12+
"label": "Community test",
13+
"message": "",
14+
"color": "red",
15+
"openshiftVersion": "",
16+
"infraProvider": os.environ.get("INFRA_PROVIDER"),
17+
"patternName": os.environ.get("PATTERN_NAME"),
18+
"patternRepo": "",
19+
"patternBranch": "",
20+
"date": datetime.today().strftime("%Y-%m-%d"),
21+
"testSource": "Community",
22+
"debugInfo": None,
23+
}
24+
25+
26+
def get_openshift_version():
27+
try:
28+
version_ret = subprocess.run([oc, "version", "-o", "json"], capture_output=True)
29+
version_out = version_ret.stdout.decode("utf-8")
30+
openshift_version = json.loads(version_out)["openshiftVersion"]
31+
major_minor = ".".join(openshift_version.split(".")[:-1])
32+
return openshift_version, major_minor
33+
except KeyError as e:
34+
print("KeyError:" + str(e))
35+
return None
36+
37+
38+
if __name__ == "__main__":
39+
versions = get_openshift_version()
40+
ci_badge["openshiftVersion"] = versions[0]
41+
42+
pattern_repo = subprocess.run(
43+
["git", "config", "--get", "remote.origin.url"], capture_output=True, text=True
44+
)
45+
pattern_branch = subprocess.run(
46+
["git", "branch", "--show-current"], capture_output=True, text=True
47+
)
48+
49+
ci_badge["patternRepo"] = pattern_repo.stdout.strip()
50+
ci_badge["patternBranch"] = pattern_branch.stdout.strip()
51+
52+
# Check each xml file for failures
53+
results_dir = os.environ.get("WORKSPACE")
54+
failures = 0
55+
56+
for file in os.listdir(results_dir):
57+
if file.startswith("test_") and file.endswith(".xml"):
58+
with open(os.path.join(results_dir, file), "r") as result_file: # type: ignore
59+
xml = JUnitXml.fromfile(result_file) # type: ignore
60+
for suite in xml:
61+
for case in suite:
62+
if case.result:
63+
failures += 1
64+
65+
# Determine badge color from results
66+
if failures == 0:
67+
ci_badge["color"] = "green"
68+
69+
# For now we assume `message` is the same as patternBranch
70+
ci_badge["message"] = ci_badge["patternBranch"]
71+
72+
ci_badge_json_basename = (
73+
os.environ.get("PATTERN_SHORTNAME") # type: ignore
74+
+ "-"
75+
+ os.environ.get("INFRA_PROVIDER")
76+
+ "-"
77+
+ versions[1]
78+
+ "-stable-badge.json"
79+
)
80+
ci_badge_json_filename = os.path.join(results_dir, ci_badge_json_basename) # type: ignore
81+
print(f"Creating CI badge file at: {ci_badge_json_filename}")
82+
83+
with open(ci_badge_json_filename, "w") as ci_badge_file:
84+
json.dump(ci_badge, ci_badge_file)

tests/interop/requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pytest
2+
kubernetes
3+
openshift
4+
openshift-python-wrapper
5+
junitparser
6+
git+https://github.com/validatedpatterns/vp-qe-test-common.git@development#egg=vp-qe-test-common

tests/interop/run_tests.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/bash
2+
3+
export EXTERNAL_TEST="true"
4+
export PATTERN_NAME="CoCoPattern"
5+
export PATTERN_SHORTNAME="coco"
6+
7+
if [ -z "${KUBECONFIG}" ]; then
8+
echo "No kubeconfig file set for hub cluster"
9+
exit 1
10+
fi
11+
12+
if [ -z "${INFRA_PROVIDER}" ]; then
13+
echo "INFRA_PROVIDER is not defined"
14+
exit 1
15+
fi
16+
17+
if [ -z "${WORKSPACE}" ]; then
18+
export WORKSPACE=/tmp
19+
fi
20+
21+
pytest -lv --disable-warnings test_subscription_status_hub.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_subscription_status_hub.xml
22+
23+
pytest -lv --disable-warnings test_validate_hub_site_components.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_validate_hub_site_components.xml
24+
25+
python3 create_ci_badge.py

0 commit comments

Comments
 (0)