33
44import pytest
55from ocp_resources .route import Route
6- from validatedpatterns_tests .interop import components
7- from validatedpatterns_tests .interop .crd import ArgoCD
8- from validatedpatterns_tests .interop .edge_util import (
9- get_long_live_bearer_token ,
10- get_site_response ,
11- )
6+ from validatedpatterns_tests .interop import application , components
127
138from . import __loggername__
149
1510logger = logging .getLogger (__loggername__ )
1611
1712oc = os .environ ["HOME" ] + "/oc_client/oc"
1813
19- """
20- Validate following multicloud-gitops components pods and endpoints on edge site (line server):
21-
22- 1) argocd
23- 2) ACM agents
24- 3) applications health (Applications deployed through argocd)
25- """
26-
2714
2815@pytest .mark .test_validate_edge_site_components
2916def test_validate_edge_site_components ():
@@ -35,29 +22,8 @@ def test_validate_edge_site_components():
3522@pytest .mark .validate_edge_site_reachable
3623def test_validate_edge_site_reachable (kube_config , openshift_dyn_client ):
3724 logger .info ("Check if edge site API end point is reachable" )
38- edge_api_url = kube_config .host
39- if not edge_api_url :
40- err_msg = "Edge site url is missing in kubeconfig file"
41- logger .error (f"FAIL: { err_msg } " )
42- assert False , err_msg
43- else :
44- logger .info (f"EDGE api url : { edge_api_url } " )
45-
46- bearer_token = get_long_live_bearer_token (
47- dyn_client = openshift_dyn_client ,
48- namespace = "openshift-gitops" ,
49- sub_string = "argocd-dex-server-token" ,
50- )
51-
52- if not bearer_token :
53- assert False , "Bearer token is missing for argocd-dex-server"
54-
55- edge_api_response = get_site_response (
56- site_url = edge_api_url , bearer_token = bearer_token
57- )
58-
59- if edge_api_response .status_code != 200 :
60- err_msg = "Edge site is not reachable. Please check the deployment."
25+ err_msg = components .validate_site_reachable (kube_config , openshift_dyn_client )
26+ if err_msg :
6127 logger .error (f"FAIL: { err_msg } " )
6228 assert False , err_msg
6329 else :
@@ -67,34 +33,14 @@ def test_validate_edge_site_reachable(kube_config, openshift_dyn_client):
6733@pytest .mark .check_pod_status_edge
6834def test_check_pod_status (openshift_dyn_client ):
6935 logger .info ("Checking pod status" )
70-
71- err_msg = []
7236 projects = [
7337 "openshift-operators" ,
7438 "open-cluster-management-agent" ,
7539 "open-cluster-management-agent-addon" ,
7640 "openshift-gitops" ,
7741 ]
7842
79- missing_projects = components .check_project_absense (openshift_dyn_client , projects )
80- missing_pods = []
81- failed_pods = []
82-
83- for project in projects :
84- missing_pods += components .check_pod_absence (openshift_dyn_client , project )
85- failed_pods += components .check_pod_status (openshift_dyn_client , project )
86-
87- if missing_projects :
88- err_msg .append (f"The following namespaces are missing: { missing_projects } " )
89-
90- if missing_pods :
91- err_msg .append (
92- f"The following namespaces have no pods deployed: { missing_pods } "
93- )
94-
95- if failed_pods :
96- err_msg .append (f"The following pods are failed: { failed_pods } " )
97-
43+ err_msg = components .check_pod_status (openshift_dyn_client , projects )
9844 if err_msg :
9945 logger .error (f"FAIL: { err_msg } " )
10046 assert False , err_msg
@@ -104,49 +50,9 @@ def test_check_pod_status(openshift_dyn_client):
10450
10551@pytest .mark .validate_argocd_reachable_edge_site
10652def test_validate_argocd_reachable_edge_site (openshift_dyn_client ):
107- namespace = "openshift-gitops"
108-
109- try :
110- for route in Route .get (
111- dyn_client = openshift_dyn_client ,
112- namespace = namespace ,
113- name = "openshift-gitops-server" ,
114- ):
115- argocd_route_url = route .instance .spec .host
116- except StopIteration :
117- err_msg = f"Argocd url/route is missing in { namespace } namespace"
118- logger .error (f"FAIL: { err_msg } " )
119- assert False , err_msg
120-
121- logger .info ("Check if argocd route/url on hub site is reachable" )
122- if not argocd_route_url :
123- err_msg = f"Argocd url/route is missing in { namespace } namespace"
124- logger .error (f"FAIL: { err_msg } " )
125- assert False , err_msg
126- else :
127- final_argocd_url = f"{ 'https://' } { argocd_route_url } "
128- logger .info (f"Argocd route/url : { final_argocd_url } " )
129-
130- bearer_token = get_long_live_bearer_token (
131- dyn_client = openshift_dyn_client ,
132- namespace = namespace ,
133- sub_string = "argocd-dex-server-token" ,
134- )
135- if not bearer_token :
136- err_msg = "Bearer token is missing for argocd-dex-server"
137- logger .error (f"FAIL: { err_msg } " )
138- assert False , err_msg
139- else :
140- logger .debug (f"Argocd bearer token : { bearer_token } " )
141-
142- argocd_route_response = get_site_response (
143- site_url = final_argocd_url , bearer_token = bearer_token
144- )
145-
146- logger .info (f"Argocd route response : { argocd_route_response } " )
147-
148- if argocd_route_response .status_code != 200 :
149- err_msg = "Argocd is not reachable. Please check the deployment."
53+ logger .info ("Check if argocd route/url on edge site is reachable" )
54+ err_msg = components .validate_argocd_reachable (openshift_dyn_client )
55+ if err_msg :
15056 logger .error (f"FAIL: { err_msg } " )
15157 assert False , err_msg
15258 else :
@@ -155,30 +61,11 @@ def test_validate_argocd_reachable_edge_site(openshift_dyn_client):
15561
15662@pytest .mark .validate_argocd_applications_health_edge_site
15763def test_validate_argocd_applications_health_edge_site (openshift_dyn_client ):
158- unhealthy_apps = []
15964 logger .info ("Get all applications deployed by argocd on edge site" )
16065 projects = ["openshift-gitops" ]
161- for project in projects :
162- logger .info (f"PROJECT: { project } " )
163- for app in ArgoCD .get (dyn_client = openshift_dyn_client , namespace = project ):
164- app_name = app .instance .metadata .name
165- app_health = app .instance .status .health .status
166- app_sync = app .instance .status .sync .status
167-
168- logger .info (f"Status for { app_name } : { app_health } : { app_sync } " )
169-
170- if "Healthy" != app_health or "Synced" != app_sync :
171- logger .info (f"Dumping failed resources for app: { app_name } " )
172- unhealthy_apps .append (app_name )
173- try :
174- for res in app .instance .status .resources :
175- if (
176- res .health and res .health .status != "Healthy"
177- ) or res .status != "Synced" :
178- logger .info (f"\n { res } " )
179- except TypeError :
180- logger .info (f"No resources found for app: { app_name } " )
181-
66+ unhealthy_apps = application .get_argocd_application_status (
67+ openshift_dyn_client , projects
68+ )
18269 if unhealthy_apps :
18370 err_msg = "Some or all applications deployed on edge site are unhealthy"
18471 logger .error (f"FAIL: { err_msg } :\n { unhealthy_apps } " )
0 commit comments