Skip to content

Commit 86b43cb

Browse files
committed
Add initial OpenSearch tests
1 parent b5c9aba commit 86b43cb

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
opensearch-py==2.5.*
12
prometheus-api-client==0.5.*
23
pytest-testinfra==10.1.*
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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:
16+
# * Dashboard login
17+
# * Cluster health
18+
19+
from opensearchpy import OpenSearch
20+
import os
21+
import pytest
22+
23+
from stackhpc_openstack_tests import utils
24+
25+
26+
@pytest.fixture
27+
def opensearch() -> OpenSearch:
28+
"""Pytest fixture that creates an OpenSearch API client."""
29+
# https://opensearch.org/docs/latest/clients/python-low-level/
30+
opensearch_hosts = os.environ["OPENSEARCH_HOSTS"].split(",")
31+
opensearch_port = os.environ["OPENSEARCH_PORT"]
32+
opensearch_hosts = [
33+
{"host": host, "port": opensearch_port} for host in opensearch_hosts
34+
]
35+
opensearch_tls = utils.str_to_bool(os.environ["OPENSEARCH_TLS"])
36+
if opensearch_tls:
37+
opensearch_verify_certs = utils.str_to_bool(
38+
os.environ["OPENSEARCH_VERIFY_CERTS"]
39+
)
40+
else:
41+
opensearch_verify_certs = True
42+
return OpenSearch(
43+
hosts=opensearch_hosts,
44+
http_compress=True,
45+
use_ssl=opensearch_tls,
46+
verify_certs=opensearch_verify_certs,
47+
ssl_show_warn=False,
48+
)
49+
50+
51+
def test_opensearch_has_info_logs(opensearch):
52+
"""Check that OpenSearch has some INFO level logs."""
53+
query = {
54+
"query": {
55+
"match": {
56+
"log_level": "INFO",
57+
}
58+
}
59+
}
60+
# https://opensearch-project.github.io/opensearch-py/api-ref/clients/opensearch_client.html#opensearchpy.OpenSearch.search
61+
result = opensearch.search(body=query, index="flog-*", size=1)
62+
assert len(result["hits"]["hits"]) == 1

stackhpc_openstack_tests/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
16+
def str_to_bool(v):
17+
"""Convert a boolean true/false string to a bool."""
18+
return v.lower() == "true"

0 commit comments

Comments
 (0)