Skip to content

Commit 1681268

Browse files
committed
extend smoke test with opensearch-dashboards
1 parent e413e2b commit 1681268

9 files changed

Lines changed: 252 additions & 0 deletions

tests/templates/kuttl/smoke/10-install-opensearch.yaml.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ spec:
110110
---
111111
apiVersion: v1
112112
kind: Secret
113+
metadata:
114+
name: opensearch-credentials
115+
data:
116+
admin: QUpWRnNHSkJicFQ2bUNobg== # AJVFsGJBbpT6mChn
117+
kibanaserver: RTRrRU51RW1rcUgzanlIQw== # E4kENuEmkqH3jyHC
118+
---
119+
apiVersion: v1
120+
kind: Secret
113121
metadata:
114122
name: opensearch-security-config
115123
stringData:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 600
5+
---
6+
apiVersion: apps/v1
7+
kind: Deployment
8+
metadata:
9+
name: opensearch-dashboards
10+
status:
11+
readyReplicas: 1
12+
replicas: 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
- script: >
6+
helm install opensearch-dashboards opensearch-dashboards
7+
--repo https://opensearch-project.github.io/helm-charts
8+
--version "{{ test_scenario['values']['opensearch'].split(',')[0] }}"
9+
--values 30_opensearch-dashboards-values.yaml
10+
--namespace $NAMESPACE
11+
--wait
12+
timeout: 600
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
opensearchHosts: https://opensearch-nodes-cluster-manager:9200
2+
image:
3+
repository: oci.stackable.tech/sdp/opensearch-dashboards
4+
tag: {{ test_scenario['values']['opensearch'].split(',')[0] }}-stackable0.0.0-dev
5+
service:
6+
type: NodePort
7+
serviceAccount:
8+
# The Helm chart appends "-dashboards", so that the actual
9+
# ServiceAccount name is "opensearch-dashboards".
10+
# see https://github.com/opensearch-project/helm-charts/blob/opensearch-dashboards-2.27.1/charts/opensearch-dashboards/templates/_helpers.tpl#L58
11+
name: opensearch
12+
extraEnvs:
13+
- name: OPENSEARCH_PASSWORD
14+
valueFrom:
15+
secretKeyRef:
16+
name: opensearch-credentials
17+
key: kibanaserver
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: kubectl create cm test-script -n $NAMESPACE --from-file=test.py
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
metadata:
5+
name: install-test-container
6+
timeout: 300
7+
---
8+
apiVersion: apps/v1
9+
kind: StatefulSet
10+
metadata:
11+
name: python
12+
status:
13+
readyReplicas: 1
14+
replicas: 1
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: python
6+
---
7+
kind: Role
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
metadata:
10+
name: python
11+
{% if test_scenario['values']['openshift'] == 'true' %}
12+
rules:
13+
- apiGroups: ["security.openshift.io"]
14+
resources: ["securitycontextconstraints"]
15+
resourceNames: ["privileged"]
16+
verbs: ["use"]
17+
{% endif %}
18+
---
19+
kind: RoleBinding
20+
apiVersion: rbac.authorization.k8s.io/v1
21+
metadata:
22+
name: python
23+
subjects:
24+
- kind: ServiceAccount
25+
name: python
26+
roleRef:
27+
kind: Role
28+
name: python
29+
apiGroup: rbac.authorization.k8s.io
30+
---
31+
apiVersion: kuttl.dev/v1beta1
32+
kind: TestStep
33+
metadata:
34+
name: install-test-container
35+
timeout: 300
36+
---
37+
apiVersion: apps/v1
38+
kind: StatefulSet
39+
metadata:
40+
name: python
41+
labels:
42+
app: python
43+
spec:
44+
replicas: 1
45+
selector:
46+
matchLabels:
47+
app: python
48+
template:
49+
metadata:
50+
labels:
51+
app: python
52+
spec:
53+
serviceAccountName: python
54+
containers:
55+
- name: osd-test
56+
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
57+
stdin: true
58+
tty: true
59+
resources:
60+
requests:
61+
memory: "128Mi"
62+
cpu: "512m"
63+
limits:
64+
memory: "128Mi"
65+
cpu: "1"
66+
env:
67+
- name: NAMESPACE
68+
valueFrom:
69+
fieldRef:
70+
fieldPath: metadata.namespace
71+
- name: OPENSEARCH_USER
72+
value: admin
73+
- name: OPENSEARCH_PASSWORD
74+
valueFrom:
75+
secretKeyRef:
76+
name: opensearch-credentials
77+
key: admin
78+
volumeMounts:
79+
- name: test-script
80+
mountPath: /tmp/test-script
81+
terminationGracePeriodSeconds: 1
82+
volumes:
83+
- name: test-script
84+
configMap:
85+
name: test-script
86+
terminationGracePeriodSeconds: 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
metadata:
5+
name: test
6+
timeout: 300
7+
commands:
8+
- script: |-
9+
sleep 60 # After the OpenSearch Dashboards container has become ready it still takes some time until the application has completely started.
10+
kubectl exec -n $NAMESPACE python-0 -- python /tmp/test-script/test.py
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import logging
2+
import os
3+
import requests
4+
import sys
5+
import urllib3
6+
7+
# disable tls insecure warnings
8+
urllib3.disable_warnings()
9+
10+
logging.basicConfig(
11+
level="INFO", format="%(asctime)s %(levelname)s: %(message)s", stream=sys.stdout
12+
)
13+
14+
namespace = os.environ["NAMESPACE"]
15+
opensearch_user = os.environ["OPENSEARCH_USER"]
16+
opensearch_password = os.environ["OPENSEARCH_PASSWORD"]
17+
opensearch_dashboards_service = "http://opensearch-dashboards:5601"
18+
19+
session = requests.Session()
20+
session.headers.update({"osd-xsrf": "true"})
21+
22+
login_page = session.post(
23+
f"{opensearch_dashboards_service}/auth/login",
24+
data={"username": opensearch_user, "password": opensearch_password},
25+
)
26+
assert login_page.ok, "Failed to login to OpenSearch Dashboards"
27+
28+
api_status = session.get(f"{opensearch_dashboards_service}/api/status")
29+
assert api_status.ok, "Failed to get API status"
30+
31+
opensearch_version = api_status.json()["version"]["number"]
32+
33+
assert api_status.json()["status"]["overall"]["state"] == "green", (
34+
"Overall state of OpenSearch Dashboards is not green"
35+
)
36+
37+
# Check if all expected plugins are present and working
38+
expected_plugins = [
39+
"alertingDashboards",
40+
"anomalyDetectionDashboards",
41+
"assistantDashboards",
42+
"customImportMapDashboards",
43+
"flowFrameworkDashboards",
44+
"indexManagementDashboards",
45+
"mlCommonsDashboards",
46+
"notificationsDashboards",
47+
"observabilityDashboards",
48+
"queryInsightsDashboards",
49+
"queryWorkbenchDashboards",
50+
"reportsDashboards",
51+
"searchRelevanceDashboards",
52+
"securityAnalyticsDashboards",
53+
"securityDashboards",
54+
]
55+
56+
states = {}
57+
for status in api_status.json()["status"]["statuses"]:
58+
states[
59+
status["id"].removeprefix("plugin:").removesuffix(f"@{opensearch_version}")
60+
] = status["state"] == "green"
61+
for plugin in expected_plugins:
62+
assert plugin in states and states[plugin], (
63+
f"Expected plugin {plugin} not present or working."
64+
)
65+
66+
# Load Sample Data (web logs & flights)
67+
sample_web_logs = session.post(f"{opensearch_dashboards_service}/api/sample_data/logs")
68+
assert sample_web_logs.ok, "Failed to create sample data (logs)"
69+
70+
sample_flights = session.post(
71+
f"{opensearch_dashboards_service}/api/sample_data/flights"
72+
)
73+
assert sample_flights.ok, "Failed to create sample data (flights)"
74+
75+
# Check that the indices were created
76+
indices = session.get(
77+
f"{opensearch_dashboards_service}/api/saved_objects/_find?fields=title&per_page=10000&type=index-pattern"
78+
)
79+
assert indices.ok, "Failed to get indices"
80+
81+
logs_index = indices.json()["saved_objects"][0]
82+
assert logs_index["attributes"]["title"] == "opensearch_dashboards_sample_data_logs", (
83+
"First index should be sample logs"
84+
)
85+
86+
flights_index = indices.json()["saved_objects"][1]
87+
assert (
88+
flights_index["attributes"]["title"] == "opensearch_dashboards_sample_data_flights"
89+
), "Second index should be sample flights"

0 commit comments

Comments
 (0)