Index State Management support (#398)

* feat(plugins): add index management client plugin

Signed-off-by: florian <[email protected]>

* chore(CHANGELOG): added entry for ISM api support in changelog

Signed-off-by: florian <[email protected]>

* test(plugins): use assertEqual to compare call parameters

Signed-off-by: florian <[email protected]>

* test(plugins): edit policy to support older versions of opensearch

Signed-off-by: florian <[email protected]>

* test(plugins): ignore plugin tests when opensearch is unreleased

Signed-off-by: florian <[email protected]>

* test(plugins): move plugin tests into separate files

Signed-off-by: florian <[email protected]>

* test(plugins): fix import of OpenSearchTestCase

Signed-off-by: florian <[email protected]>

* chore(USER_GUIDE): add a index management plugin part

Signed-off-by: florian <[email protected]>

---------

Signed-off-by: florian <[email protected]>
This commit is contained in:
florianvazelle
2023-06-28 16:56:00 -04:00
committed by GitHub
parent bc6a50b0b9
commit 2e8d5ce1a5
19 changed files with 770 additions and 5 deletions
+9
View File
@@ -148,6 +148,15 @@ def run_all(argv=None):
]
)
# There are no plugins for unreleased versions of opensearch
if environ.get("OPENSEARCH_VERSION") == "SNAPSHOT":
ignores.extend(
[
"test_opensearchpy/test_server/test_plugins/",
"test_opensearchpy/test_async/test_server/test_plugins/",
]
)
if ignores:
argv.extend(["--ignore=%s" % ignore for ignore in ignores])
@@ -0,0 +1,25 @@
# 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.
@@ -0,0 +1,56 @@
# 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 test_opensearchpy.test_cases import OpenSearchTestCase
class TestIndexManagement(OpenSearchTestCase):
def test_create_policy(self):
self.client.index_management.put_policy("...")
self.assert_url_called("PUT", "/_plugins/_ism/policies/...")
def test_update_policy(self):
self.client.index_management.put_policy(
"...", params={"if_seq_no": 7, "if_primary_term": 1}
)
self.assertEqual(
[({"if_seq_no": 7, "if_primary_term": 1}, {}, None)],
self.assert_url_called("PUT", "/_plugins/_ism/policies/..."),
)
def test_add_policy(self):
self.client.index_management.add_policy("...")
self.assert_url_called("POST", "/_plugins/_ism/add/...")
def test_get_policy(self):
self.client.index_management.get_policy("...")
self.assert_url_called("GET", "/_plugins/_ism/policies/...")
def test_remove_policy_from_index(self):
self.client.index_management.remove_policy_from_index("...")
self.assert_url_called("POST", "/_plugins/_ism/remove/...")
def test_change_policy(self):
self.client.index_management.change_policy("...")
self.assert_url_called("POST", "/_plugins/_ism/change_policy/...")
def test_retry(self):
self.client.index_management.retry("...")
self.assert_url_called("POST", "/_plugins/_ism/retry/...")
def test_explain_index(self):
self.client.index_management.explain_index("...", show_policy=True)
self.assertEqual(
[({"show_policy": b"true"}, {}, None)],
self.assert_url_called("GET", "/_plugins/_ism/explain/..."),
)
def test_delete_policy(self):
self.client.index_management.delete_policy("...")
self.assert_url_called("DELETE", "/_plugins/_ism/policies/...")
@@ -0,0 +1,25 @@
# 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.
@@ -15,7 +15,7 @@ import unittest
from opensearchpy.helpers.test import OPENSEARCH_VERSION
from . import OpenSearchTestCase
from .. import OpenSearchTestCase
class TestAlertingPlugin(OpenSearchTestCase):
@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-
# 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": "<URL>"}},
"message_template": {
"source": "The index {{ctx.index}} is being deleted"
},
}
},
{"delete": {}},
],
},
],
"ism_template": {"index_patterns": ["log*"], "priority": 100},
}
}
def test_create_policy(self):
# 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):
# 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):
# 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):
# 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)