Skip to content

Commit 03cc93f

Browse files
authored
Merge pull request #121 from validatedpatterns/add_qe_tests
Add QE tests
2 parents 0d7d334 + 6e2d1ab commit 03cc93f

8 files changed

Lines changed: 758 additions & 0 deletions

tests/interop/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__version__ = "0.1.0"
2+
__loggername__ = "css_logger"

tests/interop/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from validatedpatterns_tests.interop.conftest_logger import * # noqa: F401, F403
2+
from validatedpatterns_tests.interop.conftest_openshift import * # noqa: F401, F403
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import logging
2+
3+
import pytest
4+
from validatedpatterns_tests.interop import subscription
5+
6+
from . import __loggername__
7+
8+
logger = logging.getLogger(__loggername__)
9+
10+
11+
@pytest.mark.subscription_status_devel
12+
def test_subscription_status_devel(openshift_dyn_client):
13+
# These are the operator subscriptions and their associated namespaces
14+
expected_subs = {
15+
"openshift-gitops-operator": ["openshift-operators"],
16+
"openshift-pipelines-operator-rh": ["openshift-operators"],
17+
"quay-bridge-operator": ["openshift-operators"],
18+
"rhacs-operator": ["openshift-operators"],
19+
}
20+
21+
(
22+
operator_versions,
23+
missing_subs,
24+
unhealthy_subs,
25+
missing_installplans,
26+
upgrades_pending,
27+
) = subscription.subscription_status(openshift_dyn_client, expected_subs)
28+
29+
if missing_subs:
30+
logger.error(f"FAIL: The following subscriptions are missing: {missing_subs}")
31+
if unhealthy_subs:
32+
logger.error(
33+
f"FAIL: The following subscriptions are unhealthy: {unhealthy_subs}"
34+
)
35+
if missing_installplans:
36+
logger.error(
37+
f"FAIL: The install plan for the following subscriptions is missing: {missing_installplans}"
38+
)
39+
if upgrades_pending:
40+
logger.error(
41+
f"FAIL: The following subscriptions are in UpgradePending state: {upgrades_pending}"
42+
)
43+
44+
cluster_version = subscription.openshift_version(openshift_dyn_client)
45+
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")
46+
47+
for line in operator_versions:
48+
logger.info(line)
49+
50+
if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
51+
err_msg = "Subscription status check failed"
52+
logger.error(f"FAIL: {err_msg}")
53+
assert False, err_msg
54+
else:
55+
logger.info("PASS: Subscription status check passed")
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import difflib
2+
import logging
3+
import os
4+
import re
5+
import subprocess
6+
7+
import pytest
8+
from validatedpatterns_tests.interop import subscription
9+
10+
from . import __loggername__
11+
12+
logger = logging.getLogger(__loggername__)
13+
14+
15+
@pytest.mark.subscription_status_hub
16+
def test_subscription_status_hub(openshift_dyn_client):
17+
# These are the operator subscriptions and their associated namespaces
18+
expected_subs = {
19+
"openshift-gitops-operator": ["openshift-operators"],
20+
"advanced-cluster-management": ["open-cluster-management"],
21+
"odf-operator": ["openshift-storage"],
22+
"multicluster-engine": ["multicluster-engine"],
23+
"quay-operator": ["openshift-operators"],
24+
"rhacs-operator": ["openshift-operators"],
25+
}
26+
27+
(
28+
operator_versions,
29+
missing_subs,
30+
unhealthy_subs,
31+
missing_installplans,
32+
upgrades_pending,
33+
) = subscription.subscription_status(openshift_dyn_client, expected_subs)
34+
35+
if missing_subs:
36+
logger.error(f"FAIL: The following subscriptions are missing: {missing_subs}")
37+
if unhealthy_subs:
38+
logger.error(
39+
f"FAIL: The following subscriptions are unhealthy: {unhealthy_subs}"
40+
)
41+
if missing_installplans:
42+
logger.error(
43+
f"FAIL: The install plan for the following subscriptions is missing: {missing_installplans}"
44+
)
45+
if upgrades_pending:
46+
logger.error(
47+
f"FAIL: The following subscriptions are in UpgradePending state: {upgrades_pending}"
48+
)
49+
50+
cluster_version = subscription.openshift_version(openshift_dyn_client)
51+
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")
52+
53+
if os.getenv("EXTERNAL_TEST") != "true":
54+
shortversion = re.sub("(.[0-9]+$)", "", os.getenv("OPENSHIFT_VER"))
55+
currentfile = os.getcwd() + "/operators_hub_current"
56+
sourceFile = open(currentfile, "w")
57+
for line in operator_versions:
58+
logger.info(line)
59+
print(line, file=sourceFile)
60+
sourceFile.close()
61+
62+
logger.info("Clone operator-versions repo")
63+
try:
64+
operator_versions_repo = (
65+
"git@gitlab.cee.redhat.com:mpqe/mps/vp/operator-versions.git"
66+
)
67+
clone = subprocess.run(
68+
["git", "clone", operator_versions_repo], capture_output=True, text=True
69+
)
70+
logger.info(clone.stdout)
71+
logger.info(clone.stderr)
72+
except Exception:
73+
pass
74+
75+
previouspath = os.getcwd() + f"/operator-versions/devsecops_hub_{shortversion}"
76+
previousfile = f"devsecops_hub_{shortversion}"
77+
78+
logger.info("Ensure previous file exists")
79+
checkpath = os.path.exists(previouspath)
80+
logger.info(checkpath)
81+
82+
if checkpath is True:
83+
logger.info("Diff current operator list with previous file")
84+
diff = opdiff(open(previouspath).readlines(), open(currentfile).readlines())
85+
diffstring = "".join(diff)
86+
logger.info(diffstring)
87+
88+
logger.info("Write diff to file")
89+
sourceFile = open("operator_diffs_hub.log", "w")
90+
print(diffstring, file=sourceFile)
91+
sourceFile.close()
92+
else:
93+
logger.info("Skipping operator diff - previous file not found")
94+
95+
if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
96+
err_msg = "Subscription status check failed"
97+
logger.error(f"FAIL: {err_msg}")
98+
assert False, err_msg
99+
else:
100+
# Only push the new operarator list if the test passed
101+
# and we are not testing a pre-release operator nor
102+
# running externally
103+
if os.getenv("EXTERNAL_TEST") != "true":
104+
if checkpath is True and not os.environ["INDEX_IMAGE"]:
105+
os.remove(previouspath)
106+
os.rename(currentfile, previouspath)
107+
108+
cwd = os.getcwd() + "/operator-versions"
109+
logger.info(f"CWD: {cwd}")
110+
111+
logger.info("Push new operator list")
112+
subprocess.run(["git", "add", previousfile], cwd=cwd)
113+
subprocess.run(
114+
["git", "commit", "-m", "Update operator versions list"],
115+
cwd=cwd,
116+
)
117+
subprocess.run(["git", "push"], cwd=cwd)
118+
119+
logger.info("PASS: Subscription status check passed")
120+
121+
122+
def opdiff(*args):
123+
return filter(lambda x: not x.startswith(" "), difflib.ndiff(*args))
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import logging
2+
3+
import pytest
4+
from validatedpatterns_tests.interop import subscription
5+
6+
from . import __loggername__
7+
8+
logger = logging.getLogger(__loggername__)
9+
10+
11+
@pytest.mark.subscription_status_prod
12+
def test_subscription_status_prod(openshift_dyn_client):
13+
# These are the operator subscriptions and their associated namespaces
14+
expected_subs = {
15+
"openshift-gitops-operator": ["openshift-operators"],
16+
"quay-bridge-operator": ["openshift-operators"],
17+
"rhacs-operator": ["openshift-operators"],
18+
}
19+
20+
(
21+
operator_versions,
22+
missing_subs,
23+
unhealthy_subs,
24+
missing_installplans,
25+
upgrades_pending,
26+
) = subscription.subscription_status(openshift_dyn_client, expected_subs)
27+
28+
if missing_subs:
29+
logger.error(f"FAIL: The following subscriptions are missing: {missing_subs}")
30+
if unhealthy_subs:
31+
logger.error(
32+
f"FAIL: The following subscriptions are unhealthy: {unhealthy_subs}"
33+
)
34+
if missing_installplans:
35+
logger.error(
36+
f"FAIL: The install plan for the following subscriptions is missing: {missing_installplans}"
37+
)
38+
if upgrades_pending:
39+
logger.error(
40+
f"FAIL: The following subscriptions are in UpgradePending state: {upgrades_pending}"
41+
)
42+
43+
cluster_version = subscription.openshift_version(openshift_dyn_client)
44+
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")
45+
46+
for line in operator_versions:
47+
logger.info(line)
48+
49+
if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
50+
err_msg = "Subscription status check failed"
51+
logger.error(f"FAIL: {err_msg}")
52+
assert False, err_msg
53+
else:
54+
logger.info("PASS: Subscription status check passed")
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import logging
2+
import os
3+
4+
import pytest
5+
from validatedpatterns_tests.interop import application, components
6+
7+
from . import __loggername__
8+
9+
logger = logging.getLogger(__loggername__)
10+
11+
oc = os.environ["HOME"] + "/oc_client/oc"
12+
13+
"""
14+
Validate following multicluster-devsecops components pods and
15+
endpoints on edge site (line server):
16+
17+
1) argocd
18+
2) ACM agents
19+
3) applications health (Applications deployed through argocd)
20+
"""
21+
22+
23+
@pytest.mark.test_validate_devel_site_components
24+
def test_validate_devel_site_components():
25+
logger.info("Checking Openshift version on devel site")
26+
version_out = components.dump_openshift_version()
27+
logger.info(f"Openshift version:\n{version_out}")
28+
29+
30+
@pytest.mark.validate_devel_site_reachable
31+
def test_validate_devel_site_reachable(kube_config, openshift_dyn_client):
32+
logger.info("Check if devel site API end point is reachable")
33+
namespace = "openshift-gitops"
34+
sub_string = "argocd-dex-server-token"
35+
try:
36+
devel_api_url = application.get_site_api_url(kube_config)
37+
devel_api_response = application.get_site_api_response(
38+
openshift_dyn_client, devel_api_url, namespace, sub_string
39+
)
40+
except AssertionError as e:
41+
logger.error(f"FAIL: {e}")
42+
assert False, e
43+
44+
if devel_api_response.status_code != 200:
45+
err_msg = "Devel site is not reachable. Please check the deployment."
46+
logger.error(f"FAIL: {err_msg}")
47+
assert False, err_msg
48+
else:
49+
logger.info("PASS: Devel site is reachable")
50+
51+
52+
@pytest.mark.check_pod_status_devel
53+
def test_check_pod_status(openshift_dyn_client):
54+
logger.info("Checking pod status")
55+
56+
err_msg = []
57+
projects = [
58+
"openshift-operators",
59+
"openshift-gitops",
60+
"multicluster-devsecops-development",
61+
"open-cluster-management-agent",
62+
"open-cluster-management-agent-addon",
63+
]
64+
65+
missing_projects = components.check_project_absense(openshift_dyn_client, projects)
66+
missing_pods = []
67+
failed_pods = []
68+
69+
for project in projects:
70+
logger.info(f"Checking pods in namespace '{project}'")
71+
missing_pods += components.check_pod_absence(openshift_dyn_client, project)
72+
failed_pods += components.check_pod_status(openshift_dyn_client, projects)
73+
74+
if missing_projects:
75+
err_msg.append(f"The following namespaces are missing: {missing_projects}")
76+
77+
if missing_pods:
78+
err_msg.append(
79+
f"The following namespaces have no pods deployed: {missing_pods}"
80+
)
81+
82+
if failed_pods:
83+
err_msg.append(f"The following pods are failed: {failed_pods}")
84+
85+
if err_msg:
86+
logger.error(f"FAIL: {err_msg}")
87+
assert False, err_msg
88+
else:
89+
logger.info("PASS: Pod status check succeeded.")
90+
91+
92+
@pytest.mark.validate_argocd_reachable_devel_site
93+
def test_validate_argocd_reachable_devel_site(openshift_dyn_client):
94+
namespace = "openshift-gitops"
95+
name = "openshift-gitops-server"
96+
sub_string = "argocd-dex-server-token"
97+
logger.info("Check if argocd route/url on devel site is reachable")
98+
try:
99+
argocd_route_url = application.get_argocd_route_url(
100+
openshift_dyn_client, namespace, name
101+
)
102+
argocd_route_response = application.get_site_api_response(
103+
openshift_dyn_client, argocd_route_url, namespace, sub_string
104+
)
105+
except StopIteration:
106+
err_msg = "Argocd url/route is missing in open-cluster-management namespace"
107+
logger.error(f"FAIL: {err_msg}")
108+
assert False, err_msg
109+
except AssertionError:
110+
err_msg = "Bearer token is missing for argocd-dex-server"
111+
logger.error(f"FAIL: {err_msg}")
112+
assert False, err_msg
113+
114+
logger.info(f"Argocd route response : {argocd_route_response}")
115+
116+
if argocd_route_response.status_code != 200:
117+
err_msg = "Argocd is not reachable. Please check the deployment"
118+
logger.error(f"FAIL: {err_msg}")
119+
assert False, err_msg
120+
else:
121+
logger.info("PASS: Argocd is reachable")
122+
123+
124+
@pytest.mark.validate_argocd_applications_health_devel_site
125+
def test_validate_argocd_applications_health_devel_site(openshift_dyn_client):
126+
unhealthy_apps = []
127+
logger.info("Get all applications deployed by argocd on devel site")
128+
projects = ["openshift-gitops"]
129+
for project in projects:
130+
unhealthy_apps += application.get_argocd_application_status(
131+
openshift_dyn_client, project
132+
)
133+
if unhealthy_apps:
134+
err_msg = "Some or all applications deployed on devel site are unhealthy"
135+
logger.error(f"FAIL: {err_msg}:\n{unhealthy_apps}")
136+
assert False, err_msg
137+
else:
138+
logger.info("PASS: All applications deployed on devel site are healthy.")

0 commit comments

Comments
 (0)