Skip to content

Commit 05bd694

Browse files
committed
Updates for code consolidation
1 parent d0eacb7 commit 05bd694

6 files changed

+49
-421
lines changed

tests/interop/test_subscription_status_devel.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,10 @@ def test_subscription_status_devel(openshift_dyn_client):
1818
"rhacs-operator": ["openshift-operators"],
1919
}
2020

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"
21+
err_msg = subscription.subscription_status(
22+
openshift_dyn_client, expected_subs, diff=False
23+
)
24+
if err_msg:
5225
logger.error(f"FAIL: {err_msg}")
5326
assert False, err_msg
5427
else:
Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import difflib
21
import logging
3-
import os
4-
import re
5-
import subprocess
62

73
import pytest
84
from validatedpatterns_tests.interop import subscription
@@ -24,100 +20,11 @@ def test_subscription_status_hub(openshift_dyn_client):
2420
"rhacs-operator": ["openshift-operators"],
2521
}
2622

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-
"[email protected]: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"
23+
err_msg = subscription.subscription_status(
24+
openshift_dyn_client, expected_subs, diff=True
25+
)
26+
if err_msg:
9727
logger.error(f"FAIL: {err_msg}")
9828
assert False, err_msg
9929
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-
11930
logger.info("PASS: Subscription status check passed")
120-
121-
122-
def opdiff(*args):
123-
return filter(lambda x: not x.startswith(" "), difflib.ndiff(*args))

tests/interop/test_subscription_status_prod.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,10 @@ def test_subscription_status_prod(openshift_dyn_client):
1717
"rhacs-operator": ["openshift-operators"],
1818
}
1919

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"
20+
err_msg = subscription.subscription_status(
21+
openshift_dyn_client, expected_subs, diff=False
22+
)
23+
if err_msg:
5124
logger.error(f"FAIL: {err_msg}")
5225
assert False, err_msg
5326
else:

tests/interop/test_validate_devel_site_components.py

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010

1111
oc = os.environ["HOME"] + "/oc_client/oc"
1212

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-
2213

2314
@pytest.mark.test_validate_devel_site_components
2415
def test_validate_devel_site_components():
@@ -30,19 +21,8 @@ def test_validate_devel_site_components():
3021
@pytest.mark.validate_devel_site_reachable
3122
def test_validate_devel_site_reachable(kube_config, openshift_dyn_client):
3223
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."
24+
err_msg = components.validate_site_reachable(kube_config, openshift_dyn_client)
25+
if err_msg:
4626
logger.error(f"FAIL: {err_msg}")
4727
assert False, err_msg
4828
else:
@@ -52,36 +32,14 @@ def test_validate_devel_site_reachable(kube_config, openshift_dyn_client):
5232
@pytest.mark.check_pod_status_devel
5333
def test_check_pod_status(openshift_dyn_client):
5434
logger.info("Checking pod status")
55-
56-
err_msg = []
5735
projects = [
5836
"openshift-operators",
5937
"openshift-gitops",
6038
"multicluster-devsecops-development",
6139
"open-cluster-management-agent",
6240
"open-cluster-management-agent-addon",
6341
]
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-
42+
err_msg = components.check_pod_status(openshift_dyn_client, projects)
8543
if err_msg:
8644
logger.error(f"FAIL: {err_msg}")
8745
assert False, err_msg
@@ -91,30 +49,9 @@ def test_check_pod_status(openshift_dyn_client):
9149

9250
@pytest.mark.validate_argocd_reachable_devel_site
9351
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"
9752
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"
53+
err_msg = components.validate_argocd_reachable(openshift_dyn_client)
54+
if err_msg:
11855
logger.error(f"FAIL: {err_msg}")
11956
assert False, err_msg
12057
else:
@@ -123,13 +60,11 @@ def test_validate_argocd_reachable_devel_site(openshift_dyn_client):
12360

12461
@pytest.mark.validate_argocd_applications_health_devel_site
12562
def test_validate_argocd_applications_health_devel_site(openshift_dyn_client):
126-
unhealthy_apps = []
12763
logger.info("Get all applications deployed by argocd on devel site")
12864
projects = ["openshift-gitops"]
129-
for project in projects:
130-
unhealthy_apps += application.get_argocd_application_status(
131-
openshift_dyn_client, project
132-
)
65+
unhealthy_apps = application.get_argocd_application_status(
66+
openshift_dyn_client, projects
67+
)
13368
if unhealthy_apps:
13469
err_msg = "Some or all applications deployed on devel site are unhealthy"
13570
logger.error(f"FAIL: {err_msg}:\n{unhealthy_apps}")

0 commit comments

Comments
 (0)