diff --git a/test_opensearchpy/test_server/test_plugins/__init__.py b/test_opensearchpy/test_server/test_plugins/__init__.py deleted file mode 100644 index 7e52ae22..00000000 --- a/test_opensearchpy/test_server/test_plugins/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. -# -# Licensed to Elasticsearch B.V. under one or more contributor -# license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright -# ownership. Elasticsearch B.V. licenses this file to you under -# the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. diff --git a/test_opensearchpy/test_server/test_plugins/test_alerting.py b/test_opensearchpy/test_server/test_plugins/test_alerting.py deleted file mode 100644 index 6ecac372..00000000 --- a/test_opensearchpy/test_server/test_plugins/test_alerting.py +++ /dev/null @@ -1,182 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. - - -from __future__ import unicode_literals - -import unittest - -from opensearchpy.helpers.test import OPENSEARCH_VERSION - -from .. import OpenSearchTestCase - - -class TestAlertingPlugin(OpenSearchTestCase): - @unittest.skipUnless( - (OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)), - "Plugin not supported for opensearch version", - ) - def test_create_destination(self) -> None: - # Test to create alert destination - dummy_destination = { - "name": "my-destination", - "type": "slack", - "slack": {"url": "http://www.example.com"}, - } - response = self.client.alerting.create_destination(dummy_destination) - - self.assertNotIn("errors", response) - self.assertIn("_id", response) - - @unittest.skipUnless( - (OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)), - "Plugin not supported for opensearch version", - ) - def test_get_destination(self) -> None: - # Create a dummy destination - self.test_create_destination() - - # Try fetching the destination - response = self.client.alerting.get_destination() - - self.assertNotIn("errors", response) - self.assertGreaterEqual(response["totalDestinations"], 1) - self.assertEqual(response["totalDestinations"], len(response["destinations"])) - - @unittest.skipUnless( - (OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)), - "Plugin not supported for opensearch version", - ) - def test_create_monitor(self) -> None: - # Create a dummy destination - self.test_create_destination() - - # Try fetching the destination - destination = self.client.alerting.get_destination() - self.assertGreaterEqual( - destination["totalDestinations"], - 1, - "No destination entries found in the database.", - ) - - # Select the first destination available - destination = destination["destinations"][0] - - # A dummy schedule for 1 minute interval - schedule = {"period": {"interval": 1, "unit": "MINUTES"}} - - # A dummy query fetching everything - query = {"query": {"query_string": {"query": "*"}}} - - # A dummy action with the dummy destination - action = { - "name": "test-action", - "destination_id": destination["id"], - "message_template": {"source": "This is my message body."}, - "throttle_enabled": True, - "throttle": {"value": 27, "unit": "MINUTES"}, - "subject_template": {"source": "TheSubject"}, - } - - # A dummy trigger with the dummy action - triggers = { - "name": "test-trigger", - "severity": "1", - "condition": { - "script": { - "source": "ctx.results[0].hits.total.value > 0", - "lang": "painless", - } - }, - "actions": [action], - } - - # A dummy monitor with the dummy schedule, dummy query, dummy trigger - monitor = { - "type": "monitor", - "name": "test-monitor", - "monitor_type": "query_level_monitor", - "enabled": True, - "schedule": schedule, - "inputs": [{"search": {"indices": ["*"], "query": query}}], - "triggers": [triggers], - } - - response = self.client.alerting.create_monitor(monitor) - - self.assertNotIn("errors", response) - self.assertIn("_id", response) - self.assertIn("monitor", response) - - @unittest.skipUnless( - (OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)), - "Plugin not supported for opensearch version", - ) - def test_search_monitor(self) -> None: - # Create a dummy monitor - self.test_create_monitor() - - # Create a monitor search query by its name - query = {"query": {"match": {"monitor.name": "test-monitor"}}} - - # Perform the search with the above query - response = self.client.alerting.search_monitor(query) - - self.assertNotIn("errors", response) - self.assertIn("hits", response) - self.assertEqual(response["hits"]["total"]["value"], 1, "No monitor found.") - - @unittest.skipUnless( - (OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)), - "Plugin not supported for opensearch version", - ) - def test_get_monitor(self) -> None: - # Create a dummy monitor - self.test_create_monitor() - - # Create a monitor search query by its name - query = {"query": {"match": {"monitor.name": "test-monitor"}}} - - # Perform the search with the above query - response = self.client.alerting.search_monitor(query) - - # Select the first monitor - monitor = response["hits"]["hits"][0] - - # Fetch the monitor by id - response = self.client.alerting.get_monitor(monitor["_id"]) - - self.assertNotIn("errors", response) - self.assertIn("_id", response) - self.assertIn("monitor", response) - - @unittest.skipUnless( - (OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)), - "Plugin not supported for opensearch version", - ) - def test_run_monitor(self) -> None: - # Create a dummy monitor - self.test_create_monitor() - - # Create a monitor search query by its name - query = {"query": {"match": {"monitor.name": "test-monitor"}}} - - # Perform the search with the above query - response = self.client.alerting.search_monitor(query) - - # Select the first monitor - monitor = response["hits"]["hits"][0] - - # Run the monitor by id - response = self.client.alerting.run_monitor(monitor["_id"]) - - self.assertEqual(response["error"], None) - self.assertIn("monitor_name", response) - self.assertIn("period_start", response) - self.assertIn("period_end", response) diff --git a/test_opensearchpy/test_server/test_plugins/test_index_management.py b/test_opensearchpy/test_server/test_plugins/test_index_management.py deleted file mode 100644 index 1d2b696f..00000000 --- a/test_opensearchpy/test_server/test_plugins/test_index_management.py +++ /dev/null @@ -1,119 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# -# Modifications Copyright OpenSearch Contributors. See -# GitHub history for details. - - -from __future__ import unicode_literals - -from opensearchpy.exceptions import NotFoundError - -from .. import OpenSearchTestCase - - -class TestIndexManagementPlugin(OpenSearchTestCase): - POLICY_NAME = "example-policy" - POLICY_CONTENT = { - "policy": { - "description": "hot warm delete workflow", - "default_state": "hot", - "schema_version": 1, - "states": [ - { - "name": "hot", - "actions": [ - { - "rollover": { - "min_index_age": "1d", - } - } - ], - "transitions": [{"state_name": "warm"}], - }, - { - "name": "warm", - "actions": [{"replica_count": {"number_of_replicas": 5}}], - "transitions": [ - { - "state_name": "delete", - "conditions": {"min_index_age": "30d"}, - } - ], - }, - { - "name": "delete", - "actions": [ - { - "notification": { - "destination": {"chime": {"url": ""}}, - "message_template": { - "source": "The index {{ctx.index}} is being deleted" - }, - } - }, - {"delete": {}}, - ], - }, - ], - "ism_template": {"index_patterns": ["log*"], "priority": 100}, - } - } - - def test_create_policy(self) -> None: - # Test to create policy - response = self.client.index_management.put_policy( - policy=self.POLICY_NAME, body=self.POLICY_CONTENT - ) - - self.assertNotIn("errors", response) - self.assertIn("_id", response) - - def test_get_policy(self) -> None: - # Create a policy - self.test_create_policy() - - # Test to fetch the policy - response = self.client.index_management.get_policy(self.POLICY_NAME) - - self.assertNotIn("errors", response) - self.assertIn("_id", response) - self.assertEqual(response["_id"], self.POLICY_NAME) - - def test_update_policy(self) -> None: - # Create a policy - self.test_create_policy() - - # Fetch the policy - response = self.client.index_management.get_policy(self.POLICY_NAME) - params = { - "if_seq_no": response["_seq_no"], - "if_primary_term": response["_primary_term"], - } - - policy_content = self.POLICY_CONTENT.copy() - policy_content["policy"]["description"] = "example workflow" - - # Test to update policy - response = self.client.index_management.put_policy( - policy=self.POLICY_NAME, body=policy_content, params=params - ) - - self.assertNotIn("errors", response) - self.assertIn("_id", response) - - def test_delete_policy(self) -> None: - # Create a policy - self.test_create_policy() - - # Test to delete the policy - response = self.client.index_management.delete_policy(self.POLICY_NAME) - - self.assertNotIn("errors", response) - - # Try fetching the policy - with self.assertRaises(NotFoundError): - response = self.client.index_management.get_policy(self.POLICY_NAME)