Skip to content

Commit ee33419

Browse files
committed
Add QE tests
1 parent 0d7d334 commit ee33419

8 files changed

Lines changed: 770 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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import logging
2+
import os
3+
import re
4+
import subprocess
5+
6+
import pytest
7+
from validatedpatterns_tests.interop import subscription
8+
9+
from . import __loggername__
10+
11+
logger = logging.getLogger(__loggername__)
12+
13+
14+
@pytest.mark.subscription_status_devel
15+
def test_subscription_status_devel(openshift_dyn_client):
16+
# These are the operator subscriptions and their associated namespaces
17+
expected_subs = {
18+
"openshift-gitops-operator": ["openshift-operators"],
19+
"openshift-pipelines-operator-rh": ["openshift-operators"],
20+
"quay-bridge-operator": ["openshift-operators"],
21+
"rhacs-operator": ["openshift-operators"],
22+
}
23+
24+
(
25+
operator_versions,
26+
missing_subs,
27+
unhealthy_subs,
28+
missing_installplans,
29+
upgrades_pending,
30+
) = subscription.subscription_status(openshift_dyn_client, expected_subs)
31+
32+
if missing_subs:
33+
logger.error(f"FAIL: The following subscriptions are missing: {missing_subs}")
34+
if unhealthy_subs:
35+
logger.error(
36+
f"FAIL: The following subscriptions are unhealthy: {unhealthy_subs}"
37+
)
38+
if missing_installplans:
39+
logger.error(
40+
f"FAIL: The install plan for the following subscriptions is missing: {missing_installplans}"
41+
)
42+
if upgrades_pending:
43+
logger.error(
44+
f"FAIL: The following subscriptions are in UpgradePending state: {upgrades_pending}"
45+
)
46+
47+
cluster_version = subscription.openshift_version(openshift_dyn_client)
48+
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")
49+
50+
for line in operator_versions:
51+
logger.info(line)
52+
53+
if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
54+
err_msg = "Subscription status check failed"
55+
logger.error(f"FAIL: {err_msg}")
56+
assert False, err_msg
57+
else:
58+
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import logging
2+
import os
3+
import re
4+
import subprocess
5+
6+
import pytest
7+
from validatedpatterns_tests.interop import subscription
8+
9+
from . import __loggername__
10+
11+
logger = logging.getLogger(__loggername__)
12+
13+
14+
@pytest.mark.subscription_status_prod
15+
def test_subscription_status_prod(openshift_dyn_client):
16+
# These are the operator subscriptions and their associated namespaces
17+
expected_subs = {
18+
"openshift-gitops-operator": ["openshift-operators"],
19+
"quay-bridge-operator": ["openshift-operators"],
20+
"rhacs-operator": ["openshift-operators"],
21+
}
22+
23+
(
24+
operator_versions,
25+
missing_subs,
26+
unhealthy_subs,
27+
missing_installplans,
28+
upgrades_pending,
29+
) = subscription.subscription_status(openshift_dyn_client, expected_subs)
30+
31+
if missing_subs:
32+
logger.error(f"FAIL: The following subscriptions are missing: {missing_subs}")
33+
if unhealthy_subs:
34+
logger.error(
35+
f"FAIL: The following subscriptions are unhealthy: {unhealthy_subs}"
36+
)
37+
if missing_installplans:
38+
logger.error(
39+
f"FAIL: The install plan for the following subscriptions is missing: {missing_installplans}"
40+
)
41+
if upgrades_pending:
42+
logger.error(
43+
f"FAIL: The following subscriptions are in UpgradePending state: {upgrades_pending}"
44+
)
45+
46+
cluster_version = subscription.openshift_version(openshift_dyn_client)
47+
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")
48+
49+
for line in operator_versions:
50+
logger.info(line)
51+
52+
if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
53+
err_msg = "Subscription status check failed"
54+
logger.error(f"FAIL: {err_msg}")
55+
assert False, err_msg
56+
else:
57+
logger.info("PASS: Subscription status check passed")
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import logging
2+
import os
3+
4+
import pytest
5+
import yaml
6+
from ocp_resources.storage_class import StorageClass
7+
from validatedpatterns_tests.interop import application, components
8+
from validatedpatterns_tests.interop.crd import ManagedCluster
9+
10+
from . import __loggername__
11+
12+
logger = logging.getLogger(__loggername__)
13+
14+
oc = os.environ["HOME"] + "/oc_client/oc"
15+
16+
"""
17+
Validate following multicluster-devsecops components pods and
18+
endpoints on edge site (line server):
19+
20+
1) argocd
21+
2) ACM agents
22+
3) applications health (Applications deployed through argocd)
23+
"""
24+
25+
26+
@pytest.mark.test_validate_devel_site_components
27+
def test_validate_devel_site_components():
28+
logger.info("Checking Openshift version on devel site")
29+
version_out = components.dump_openshift_version()
30+
logger.info(f"Openshift version:\n{version_out}")
31+
32+
33+
@pytest.mark.validate_devel_site_reachable
34+
def test_validate_devel_site_reachable(kube_config, openshift_dyn_client):
35+
logger.info("Check if devel site API end point is reachable")
36+
namespace = "openshift-gitops"
37+
sub_string = "argocd-dex-server-token"
38+
try:
39+
devel_api_url = application.get_site_api_url(kube_config)
40+
devel_api_response = application.get_site_api_response(
41+
openshift_dyn_client, devel_api_url, namespace, sub_string
42+
)
43+
except AssertionError as e:
44+
logger.error(f"FAIL: {e}")
45+
assert False, e
46+
47+
if devel_api_response.status_code != 200:
48+
err_msg = "Devel site is not reachable. Please check the deployment."
49+
logger.error(f"FAIL: {err_msg}")
50+
assert False, err_msg
51+
else:
52+
logger.info("PASS: Devel site is reachable")
53+
54+
55+
@pytest.mark.check_pod_status_devel
56+
def test_check_pod_status(openshift_dyn_client):
57+
logger.info("Checking pod status")
58+
59+
err_msg = []
60+
projects = [
61+
"openshift-operators",
62+
"openshift-gitops",
63+
"multicluster-devsecops-development",
64+
"open-cluster-management-agent",
65+
"open-cluster-management-agent-addon",
66+
]
67+
68+
missing_projects = components.check_project_absense(openshift_dyn_client, projects)
69+
missing_pods = []
70+
failed_pods = []
71+
72+
for project in projects:
73+
logger.info(f"Checking pods in namespace '{project}'")
74+
missing_pods += components.check_pod_absence(openshift_dyn_client, project)
75+
failed_pods += components.check_pod_status(openshift_dyn_client, projects)
76+
77+
if missing_projects:
78+
err_msg.append(f"The following namespaces are missing: {missing_projects}")
79+
80+
if missing_pods:
81+
err_msg.append(
82+
f"The following namespaces have no pods deployed: {missing_pods}"
83+
)
84+
85+
if failed_pods:
86+
err_msg.append(f"The following pods are failed: {failed_pods}")
87+
88+
if err_msg:
89+
logger.error(f"FAIL: {err_msg}")
90+
assert False, err_msg
91+
else:
92+
logger.info("PASS: Pod status check succeeded.")
93+
94+
95+
@pytest.mark.validate_argocd_reachable_devel_site
96+
def test_validate_argocd_reachable_devel_site(openshift_dyn_client):
97+
namespace = "openshift-gitops"
98+
name = "openshift-gitops-server"
99+
sub_string = "argocd-dex-server-token"
100+
logger.info("Check if argocd route/url on devel site is reachable")
101+
try:
102+
argocd_route_url = application.get_argocd_route_url(
103+
openshift_dyn_client, namespace, name
104+
)
105+
argocd_route_response = application.get_site_api_response(
106+
openshift_dyn_client, argocd_route_url, namespace, sub_string
107+
)
108+
except StopIteration:
109+
err_msg = "Argocd url/route is missing in open-cluster-management namespace"
110+
logger.error(f"FAIL: {err_msg}")
111+
assert False, err_msg
112+
except AssertionError:
113+
err_msg = "Bearer token is missing for argocd-dex-server"
114+
logger.error(f"FAIL: {err_msg}")
115+
assert False, err_msg
116+
117+
logger.info(f"Argocd route response : {argocd_route_response}")
118+
119+
if argocd_route_response.status_code != 200:
120+
err_msg = "Argocd is not reachable. Please check the deployment"
121+
logger.error(f"FAIL: {err_msg}")
122+
assert False, err_msg
123+
else:
124+
logger.info("PASS: Argocd is reachable")
125+
126+
127+
@pytest.mark.validate_argocd_applications_health_devel_site
128+
def test_validate_argocd_applications_health_devel_site(openshift_dyn_client):
129+
unhealthy_apps = []
130+
logger.info("Get all applications deployed by argocd on devel site")
131+
projects = ["openshift-gitops"]
132+
for project in projects:
133+
unhealthy_apps += application.get_argocd_application_status(
134+
openshift_dyn_client, project
135+
)
136+
if unhealthy_apps:
137+
err_msg = "Some or all applications deployed on devel site are unhealthy"
138+
logger.error(f"FAIL: {err_msg}:\n{unhealthy_apps}")
139+
assert False, err_msg
140+
else:
141+
logger.info("PASS: All applications deployed on devel site are healthy.")

0 commit comments

Comments
 (0)