Skip to content

Commit a9c6a5f

Browse files
authored
Merge pull request #3 from stackhpc/opensearch-dashboards-grafana
Add OpenSearch Dashboards and Grafana tests
2 parents b3cb409 + 6e034c3 commit a9c6a5f

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

.github/workflows/pr-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
ssh_username: cloud-user
1313
neutron_plugin: ovs
1414
OS_CLOUD: openstack
15-
stackhpc_cloud_tests_version: ${{ github.ref }}
15+
stackhpc_cloud_tests_version: ${{ github.head_ref || github.ref_name }}
1616
repository: stackhpc/stackhpc-kayobe-config
1717
github_ref: stackhpc/2024.1
1818
runner: arc-aio-cloud-tests-runner
@@ -28,7 +28,7 @@ jobs:
2828
ssh_username: ubuntu
2929
neutron_plugin: ovn
3030
OS_CLOUD: openstack
31-
stackhpc_cloud_tests_version: ${{ github.ref }}
31+
stackhpc_cloud_tests_version: ${{ github.head_ref || github.ref_name }}
3232
repository: stackhpc/stackhpc-kayobe-config
3333
github_ref: stackhpc/2024.1
3434
runner: arc-aio-cloud-tests-runner

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
grafana-client==4.1.*
12
opensearch-py==2.5.*
23
prometheus-api-client==0.5.*
3-
pytest-testinfra==10.1.*
44
pylint==3.3.*
5+
pytest-testinfra==10.1.*
6+
requests==2.31.*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2024 StackHPC Ltd.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2024 StackHPC Ltd.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
# TODO: Check if we can validate that dashboards load correctly.
16+
17+
from grafana_client import GrafanaApi
18+
import os
19+
import pytest
20+
21+
22+
@pytest.fixture
23+
def grafana() -> GrafanaApi:
24+
"""Pytest fixture that creates a Grafana API client."""
25+
# https://github.com/grafana-toolbox/grafana-client
26+
grafana_url = os.environ["GRAFANA_URL"]
27+
grafana_username = os.environ["GRAFANA_USERNAME"]
28+
grafana_password = os.environ["GRAFANA_PASSWORD"]
29+
return GrafanaApi.from_url(
30+
grafana_url,
31+
credential=(grafana_username, grafana_password),
32+
)
33+
34+
35+
def test_grafana_api_stats(grafana):
36+
"""Test that Grafana API stats are accessible."""
37+
# https://grafana.com/docs/grafana/latest/developers/http_api/admin/#grafana-stats
38+
result = grafana.admin.stats()
39+
assert result["dashboards"] > 0
40+
assert result["datasources"] > 0

stackhpc_cloud_tests/test_opensearch.py renamed to stackhpc_cloud_tests/monitoring/test_opensearch.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# under the License.
1414

1515
# TODO:
16-
# * Dashboard login
1716
# * Cluster health
1817

1918
from opensearchpy import OpenSearch
2019
import os
2120
import pytest
21+
import requests
2222

2323
from stackhpc_cloud_tests import utils
2424

@@ -60,3 +60,15 @@ def test_opensearch_has_info_logs(opensearch):
6060
# https://opensearch-project.github.io/opensearch-py/api-ref/clients/opensearch_client.html#opensearchpy.OpenSearch.search
6161
result = opensearch.search(body=query, index="flog-*", size=1)
6262
assert len(result["hits"]["hits"]) == 1
63+
64+
65+
def test_opensearch_dashboards_status():
66+
"""Check that OpenSearch Dashboards is accessible and is in a green state."""
67+
dashboard_url = os.environ["OPENSEARCH_DASHBOARDS_URL"]
68+
dashboard_username = os.environ["OPENSEARCH_DASHBOARDS_USERNAME"]
69+
dashboard_password = os.environ["OPENSEARCH_DASHBOARDS_PASSWORD"]
70+
dashboard_url += "/api/status"
71+
result = requests.get(dashboard_url, auth=(dashboard_username, dashboard_password))
72+
assert result.ok
73+
result = result.json()
74+
assert result["status"]["overall"]["state"] == "green"
File renamed without changes.

0 commit comments

Comments
 (0)