Skip to content

Commit 5aa1595

Browse files
committed
directly create cm with test script
1 parent c77ed2f commit 5aa1595

2 files changed

Lines changed: 92 additions & 90 deletions

File tree

tests/templates/kuttl/opensearch-dashboards/30-test-opensearch-dashboards.yaml.j2

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
apiVersion: kuttl.dev/v1beta1
2-
kind: TestStep
3-
commands:
4-
- script: kubectl create cm test-opensearch-dashboards -n $NAMESPACE --from-file=test.py
5-
---
61
apiVersion: batch/v1
72
kind: Job
83
metadata:
@@ -53,3 +48,95 @@ spec:
5348
securityContext:
5449
fsGroup: 1000
5550
restartPolicy: OnFailure
51+
---
52+
apiVersion: v1
53+
kind: ConfigMap
54+
metadata:
55+
name: test-opensearch-dashboards
56+
data:
57+
test.py: |
58+
import logging
59+
import os
60+
import requests
61+
import sys
62+
63+
logging.basicConfig(
64+
level="DEBUG", format="%(asctime)s %(levelname)s: %(message)s", stream=sys.stdout
65+
)
66+
67+
namespace = os.environ["NAMESPACE"]
68+
opensearch_user = os.environ["OPENSEARCH_USER"]
69+
opensearch_password = os.environ["OPENSEARCH_PASSWORD"]
70+
opensearch_dashboards_service = "http://opensearch-dashboards:5601"
71+
72+
session = requests.Session()
73+
session.headers.update({"osd-xsrf": "true"})
74+
75+
login_page = session.post(
76+
f"{opensearch_dashboards_service}/auth/login",
77+
data={"username": opensearch_user, "password": opensearch_password},
78+
)
79+
assert login_page.ok, "Failed to login to OpenSearch Dashboards"
80+
81+
api_status = session.get(f"{opensearch_dashboards_service}/api/status")
82+
assert api_status.ok, "Failed to get API status"
83+
84+
opensearch_version = api_status.json()["version"]["number"]
85+
86+
assert api_status.json()["status"]["overall"]["state"] == "green", (
87+
"Overall state of OpenSearch Dashboards is not green"
88+
)
89+
90+
# Check if all expected plugins are present and working
91+
expected_plugins = [
92+
"alertingDashboards",
93+
"anomalyDetectionDashboards",
94+
"assistantDashboards",
95+
"customImportMapDashboards",
96+
"flowFrameworkDashboards",
97+
"indexManagementDashboards",
98+
"mlCommonsDashboards",
99+
"notificationsDashboards",
100+
"observabilityDashboards",
101+
"queryInsightsDashboards",
102+
"queryWorkbenchDashboards",
103+
"reportsDashboards",
104+
"searchRelevanceDashboards",
105+
"securityAnalyticsDashboards",
106+
"securityDashboards",
107+
]
108+
109+
states = {}
110+
for status in api_status.json()["status"]["statuses"]:
111+
states[
112+
status["id"].removeprefix("plugin:").removesuffix(f"@{opensearch_version}")
113+
] = status["state"] == "green"
114+
for plugin in expected_plugins:
115+
assert plugin in states and states[plugin], (
116+
f"Expected plugin {plugin} not present or working."
117+
)
118+
119+
# Load Sample Data (web logs & flights)
120+
sample_web_logs = session.post(f"{opensearch_dashboards_service}/api/sample_data/logs")
121+
assert sample_web_logs.ok, "Failed to create sample data (logs)"
122+
123+
sample_flights = session.post(
124+
f"{opensearch_dashboards_service}/api/sample_data/flights"
125+
)
126+
assert sample_flights.ok, "Failed to create sample data (flights)"
127+
128+
# Check that the indices were created
129+
indices = session.get(
130+
f"{opensearch_dashboards_service}/api/saved_objects/_find?fields=title&per_page=10000&type=index-pattern"
131+
)
132+
assert indices.ok, "Failed to get indices"
133+
134+
logs_index = indices.json()["saved_objects"][0]
135+
assert logs_index["attributes"]["title"] == "opensearch_dashboards_sample_data_logs", (
136+
"First index should be sample logs"
137+
)
138+
139+
flights_index = indices.json()["saved_objects"][1]
140+
assert (
141+
flights_index["attributes"]["title"] == "opensearch_dashboards_sample_data_flights"
142+
), "Second index should be sample flights"

tests/templates/kuttl/opensearch-dashboards/test.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)