|
| 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