Skip to content

Commit 00a213d

Browse files
committed
Updates for site_components tests
1 parent f80cd06 commit 00a213d

File tree

2 files changed

+21
-218
lines changed

2 files changed

+21
-218
lines changed

tests/interop/test_validate_edge_site_components.py

Lines changed: 10 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33

44
import pytest
55
from 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

138
from . import __loggername__
149

1510
logger = logging.getLogger(__loggername__)
1611

1712
oc = 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
2916
def test_validate_edge_site_components():
@@ -35,29 +22,8 @@ def test_validate_edge_site_components():
3522
@pytest.mark.validate_edge_site_reachable
3623
def 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
6834
def 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
10652
def 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
15763
def 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}")

tests/interop/test_validate_hub_site_components.py

Lines changed: 11 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@
55
import yaml
66
from ocp_resources.storage_class import StorageClass
77
from validatedpatterns_tests.interop import application, components
8-
from validatedpatterns_tests.interop.crd import ManagedCluster
98

109
from . import __loggername__
1110

1211
logger = logging.getLogger(__loggername__)
1312

1413
oc = os.environ["HOME"] + "/oc_client/oc"
1514

16-
"""
17-
Validate following multicloud-gitops components pods and endpoints on hub site (central server):
18-
19-
1) ACM (Advanced Cluster Manager) and self-registration
20-
2) argocd
21-
3) openshift operators
22-
4) applications health (Applications deployed through argocd)
23-
"""
24-
2515

2616
@pytest.mark.test_validate_hub_site_components
2717
def test_validate_hub_site_components(openshift_dyn_client):
@@ -40,19 +30,8 @@ def test_validate_hub_site_components(openshift_dyn_client):
4030
@pytest.mark.validate_hub_site_reachable
4131
def test_validate_hub_site_reachable(kube_config, openshift_dyn_client):
4232
logger.info("Check if hub site API end point is reachable")
43-
namespace = "openshift-gitops"
44-
sub_string = "argocd-dex-server-token"
45-
try:
46-
hub_api_url = application.get_site_api_url(kube_config)
47-
hub_api_response = application.get_site_api_response(
48-
openshift_dyn_client, hub_api_url, namespace, sub_string
49-
)
50-
except AssertionError as e:
51-
logger.error(f"FAIL: {e}")
52-
assert False, e
53-
54-
if hub_api_response.status_code != 200:
55-
err_msg = "Hub site is not reachable. Please check the deployment."
33+
err_msg = components.validate_site_reachable(kube_config, openshift_dyn_client)
34+
if err_msg:
5635
logger.error(f"FAIL: {err_msg}")
5736
assert False, err_msg
5837
else:
@@ -62,36 +41,14 @@ def test_validate_hub_site_reachable(kube_config, openshift_dyn_client):
6241
@pytest.mark.check_pod_status_hub
6342
def test_check_pod_status(openshift_dyn_client):
6443
logger.info("Checking pod status")
65-
66-
err_msg = []
6744
projects = [
6845
"openshift-operators",
6946
"open-cluster-management",
7047
"open-cluster-management-hub",
7148
"openshift-gitops",
7249
"vault",
7350
]
74-
75-
missing_projects = components.check_project_absense(openshift_dyn_client, projects)
76-
missing_pods = []
77-
failed_pods = []
78-
79-
for project in projects:
80-
logger.info(f"Checking pods in namespace '{project}'")
81-
missing_pods += components.check_pod_absence(openshift_dyn_client, project)
82-
failed_pods += components.check_pod_status(openshift_dyn_client, projects)
83-
84-
if missing_projects:
85-
err_msg.append(f"The following namespaces are missing: {missing_projects}")
86-
87-
if missing_pods:
88-
err_msg.append(
89-
f"The following namespaces have no pods deployed: {missing_pods}"
90-
)
91-
92-
if failed_pods:
93-
err_msg.append(f"The following pods are failed: {failed_pods}")
94-
51+
err_msg = components.check_pod_status(openshift_dyn_client, projects)
9552
if err_msg:
9653
logger.error(f"FAIL: {err_msg}")
9754
assert False, err_msg
@@ -102,59 +59,20 @@ def test_check_pod_status(openshift_dyn_client):
10259
@pytest.mark.validate_acm_self_registration_managed_clusters
10360
def test_validate_acm_self_registration_managed_clusters(openshift_dyn_client):
10461
logger.info("Check ACM self registration for edge site")
105-
106-
kubefile = os.getenv("KUBECONFIG_EDGE")
107-
kubefile_exp = os.path.expandvars(kubefile)
108-
with open(kubefile_exp) as stream:
109-
try:
110-
out = yaml.safe_load(stream)
111-
site_name = out["clusters"][0]["name"]
112-
except yaml.YAMLError:
113-
err_msg = "Failed to load kubeconfig file"
114-
logger.error(f"FAIL: {err_msg}")
115-
assert False, err_msg
116-
117-
clusters = ManagedCluster.get(dyn_client=openshift_dyn_client, name=site_name)
118-
cluster = next(clusters)
119-
is_managed_cluster_joined, managed_cluster_status = cluster.self_registered
120-
121-
logger.info(f"Cluster Managed : {is_managed_cluster_joined}")
122-
logger.info(f"Managed Cluster Status : {managed_cluster_status}")
123-
124-
if not is_managed_cluster_joined:
125-
err_msg = f"{site_name} is not self registered"
62+
kubefiles = [os.getenv("KUBECONFIG_EDGE")]
63+
err_msg = components.validate_acm_self_registration_managed_clusters(openshift_dyn_client, kubefiles)
64+
if err_msg:
12665
logger.error(f"FAIL: {err_msg}")
12766
assert False, err_msg
12867
else:
129-
logger.info(f"PASS: {site_name} is self registered")
68+
logger.info(f"PASS: Edge site is self registered")
13069

13170

13271
@pytest.mark.validate_argocd_reachable_hub_site
13372
def test_validate_argocd_reachable_hub_site(openshift_dyn_client):
134-
namespace = "openshift-gitops"
135-
name = "openshift-gitops-server"
136-
sub_string = "argocd-dex-server-token"
13773
logger.info("Check if argocd route/url on hub site is reachable")
138-
try:
139-
argocd_route_url = application.get_argocd_route_url(
140-
openshift_dyn_client, namespace, name
141-
)
142-
argocd_route_response = application.get_site_api_response(
143-
openshift_dyn_client, argocd_route_url, namespace, sub_string
144-
)
145-
except StopIteration:
146-
err_msg = "Argocd url/route is missing in open-cluster-management namespace"
147-
logger.error(f"FAIL: {err_msg}")
148-
assert False, err_msg
149-
except AssertionError:
150-
err_msg = "Bearer token is missing for argocd-dex-server"
151-
logger.error(f"FAIL: {err_msg}")
152-
assert False, err_msg
153-
154-
logger.info(f"Argocd route response : {argocd_route_response}")
155-
156-
if argocd_route_response.status_code != 200:
157-
err_msg = "Argocd is not reachable. Please check the deployment"
74+
err_msg = components.validate_argocd_reachable(openshift_dyn_client)
75+
if err_msg:
15876
logger.error(f"FAIL: {err_msg}")
15977
assert False, err_msg
16078
else:
@@ -163,12 +81,10 @@ def test_validate_argocd_reachable_hub_site(openshift_dyn_client):
16381

16482
@pytest.mark.validate_argocd_applications_health_hub_site
16583
def test_validate_argocd_applications_health_hub_site(openshift_dyn_client):
166-
unhealthy_apps = []
16784
logger.info("Get all applications deployed by argocd on hub site")
16885
projects = ["openshift-gitops", "multicloud-gitops-hub"]
169-
for project in projects:
170-
unhealthy_apps += application.get_argocd_application_status(
171-
openshift_dyn_client, project
86+
unhealthy_apps = application.get_argocd_application_status(
87+
openshift_dyn_client, projects
17288
)
17389
if unhealthy_apps:
17490
err_msg = "Some or all applications deployed on hub site are unhealthy"

0 commit comments

Comments
 (0)