22import os
33
44import pytest
5- from ocp_resources .route import Route
65from ocp_resources .storage_class import StorageClass
7- from openshift .dynamic .exceptions import NotFoundError
8- from validatedpatterns_tests .interop import components
9- from validatedpatterns_tests .interop .crd import ArgoCD
10- from validatedpatterns_tests .interop .edge_util import (
11- get_long_live_bearer_token ,
12- get_site_response ,
13- )
6+ from validatedpatterns_tests .interop import application , components
147
158from . import __loggername__
169
1710logger = logging .getLogger (__loggername__ )
1811
1912oc = os .environ ["HOME" ] + "/oc_client/oc"
2013
21- """
22- Validate following manuela components pods and endpoints
23- on hub site (central server):
24-
25-
26- 1) argocd
27- 2) openshift-operators
28- 3) pods
29- 4) applications health (Applications deployed through argocd)
30- """
31-
3214
3315@pytest .mark .test_validate_hub_site_components
3416def test_validate_hub_site_components (openshift_dyn_client ):
@@ -47,29 +29,8 @@ def test_validate_hub_site_components(openshift_dyn_client):
4729@pytest .mark .validate_hub_site_reachable
4830def test_validate_hub_site_reachable (kube_config , openshift_dyn_client ):
4931 logger .info ("Check if hub site API end point is reachable" )
50- hub_api_url = kube_config .host
51- if not hub_api_url :
52- err_msg = "Hub site url is missing in kubeconfig file"
53- logger .error (f"FAIL: { err_msg } " )
54- assert False , err_msg
55- else :
56- logger .info (f"HUB api url : { hub_api_url } " )
57-
58- bearer_token = get_long_live_bearer_token (
59- dyn_client = openshift_dyn_client ,
60- namespace = "openshift-gitops" ,
61- sub_string = "argocd-dex-server-token" ,
62- )
63-
64- if not bearer_token :
65- assert False , "Bearer token is missing for argocd-dex-server"
66-
67- hub_api_response = get_site_response (
68- site_url = hub_api_url , bearer_token = bearer_token
69- )
70-
71- if hub_api_response .status_code != 200 :
72- err_msg = "Hub site is not reachable. Please check the deployment."
32+ err_msg = components .validate_site_reachable (kube_config , openshift_dyn_client )
33+ if err_msg :
7334 logger .error (f"FAIL: { err_msg } " )
7435 assert False , err_msg
7536 else :
@@ -79,11 +40,6 @@ def test_validate_hub_site_reachable(kube_config, openshift_dyn_client):
7940@pytest .mark .check_pod_status_hub
8041def test_check_pod_status (openshift_dyn_client ):
8142 logger .info ("Checking pod status" )
82-
83- err_msg = []
84- failed_pods = []
85- missing_pods = []
86- missing_projects = []
8743 projects = [
8844 "openshift-operators" ,
8945 "ansible-automation-platform" ,
@@ -92,27 +48,7 @@ def test_check_pod_status(openshift_dyn_client):
9248 "edge-gitops-vms" ,
9349 "vault" ,
9450 ]
95-
96- missing_projects = components .check_project_absense (openshift_dyn_client , projects )
97- missing_pods = []
98- failed_pods = []
99-
100- for project in projects :
101- logger .info (f"Checking pods in namespace '{ project } '" )
102- missing_pods += components .check_pod_absence (openshift_dyn_client , project )
103- failed_pods += components .check_pod_status (openshift_dyn_client , projects )
104-
105- if missing_projects :
106- err_msg .append (f"The following namespaces are missing: { missing_projects } " )
107-
108- if missing_pods :
109- err_msg .append (
110- f"The following namespaces have no pods deployed: { missing_pods } "
111- )
112-
113- if failed_pods :
114- err_msg .append (f"The following pods are failed: { failed_pods } " )
115-
51+ err_msg = components .check_pod_status (openshift_dyn_client , projects )
11652 if err_msg :
11753 logger .error (f"FAIL: { err_msg } " )
11854 assert False , err_msg
@@ -122,43 +58,9 @@ def test_check_pod_status(openshift_dyn_client):
12258
12359@pytest .mark .validate_argocd_reachable_hub_site
12460def test_validate_argocd_reachable_hub_site (openshift_dyn_client ):
125- namespace = "openshift-gitops"
12661 logger .info ("Check if argocd route/url on hub site is reachable" )
127- try :
128- for route in Route .get (
129- dyn_client = openshift_dyn_client ,
130- namespace = namespace ,
131- name = "openshift-gitops-server" ,
132- ):
133- argocd_route_url = route .instance .spec .host
134- except NotFoundError :
135- err_msg = "Argocd url/route is missing in open-cluster-management namespace"
136- logger .error (f"FAIL: { err_msg } " )
137- assert False , err_msg
138-
139- final_argocd_url = f"{ 'http://' } { argocd_route_url } "
140- logger .info (f"ACM route/url : { final_argocd_url } " )
141-
142- bearer_token = get_long_live_bearer_token (
143- dyn_client = openshift_dyn_client ,
144- namespace = namespace ,
145- sub_string = "argocd-dex-server-token" ,
146- )
147- if not bearer_token :
148- err_msg = "Bearer token is missing for argocd-dex-server"
149- logger .error (f"FAIL: { err_msg } " )
150- assert False , err_msg
151- else :
152- logger .debug (f"Argocd bearer token : { bearer_token } " )
153-
154- argocd_route_response = get_site_response (
155- site_url = final_argocd_url , bearer_token = bearer_token
156- )
157-
158- logger .info (f"Argocd route response : { argocd_route_response } " )
159-
160- if argocd_route_response .status_code != 200 :
161- err_msg = "Argocd is not reachable. Please check the deployment"
62+ err_msg = components .validate_argocd_reachable (openshift_dyn_client )
63+ if err_msg :
16264 logger .error (f"FAIL: { err_msg } " )
16365 assert False , err_msg
16466 else :
@@ -167,26 +69,11 @@ def test_validate_argocd_reachable_hub_site(openshift_dyn_client):
16769
16870@pytest .mark .validate_argocd_applications_health_hub_site
16971def test_validate_argocd_applications_health_hub_site (openshift_dyn_client ):
170- unhealthy_apps = []
17172 logger .info ("Get all applications deployed by argocd on hub site" )
17273 projects = ["openshift-gitops" , "ansible-edge-gitops-hub" ]
173- for project in projects :
174- for app in ArgoCD .get (dyn_client = openshift_dyn_client , namespace = project ):
175- app_name = app .instance .metadata .name
176- app_health = app .instance .status .health .status
177- app_sync = app .instance .status .sync .status
178-
179- logger .info (f"Status for { app_name } : { app_health } : { app_sync } " )
180-
181- if "Healthy" != app_health or "Synced" != app_sync :
182- logger .info (f"Dumping failed resources for app: { app_name } " )
183- unhealthy_apps .append (app_name )
184- for res in app .instance .status .resources :
185- if (
186- res .health and res .health .status != "Healthy"
187- ) or res .status != "Synced" :
188- logger .info (f"\n { res } " )
189-
74+ unhealthy_apps = application .get_argocd_application_status (
75+ openshift_dyn_client , projects
76+ )
19077 if unhealthy_apps :
19178 err_msg = "Some or all applications deployed on hub site are unhealthy"
19279 logger .error (f"FAIL: { err_msg } :\n { unhealthy_apps } " )
0 commit comments