From 6cc3082edd4deac1f580ccd477e7f5b8b60aefd6 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 3 Jul 2024 15:41:59 -0400 Subject: [PATCH] Fix: /{index}/_open can return a task. Signed-off-by: dblock --- CHANGELOG.md | 3 +- SPECIFICATION_TESTING.md | 2 +- spec/namespaces/indices.yaml | 25 +++++++---- tests/indices/close.yaml | 38 ++++++++++++++++ tests/indices/{_doc.yaml => doc.yaml} | 0 tests/indices/open.yaml | 63 +++++++++++++++++++++++++++ tools/src/tester/ChapterReader.ts | 2 +- 7 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 tests/indices/close.yaml rename tests/indices/{_doc.yaml => doc.yaml} (100%) create mode 100644 tests/indices/open.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d8ffb13..ab8da74ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,7 +61,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed `text/plain` response in `/_cat` ([#357](https://github.com/opensearch-project/opensearch-api-specification/pull/357)) - Fixed `/_cat/cluster_manager`, `/_cat/allocation`, `/_cat/shards`, and `/_cat/thread_pool` ([#373](https://github.com/opensearch-project/opensearch-api-specification/pull/373)) - Fixed optional field in `/_nodes` ([#365](https://github.com/opensearch-project/opensearch-api-specification/pull/365)) - +- Fixed `/{index}/_open` can return a `task` ([#376](https://github.com/opensearch-project/opensearch-api-specification/pull/376)) + ### Security [Unreleased]: https://github.com/opensearch-project/opensearch-api-specification/commits/main/ diff --git a/SPECIFICATION_TESTING.md b/SPECIFICATION_TESTING.md index 15afa704b..b40283e4c 100644 --- a/SPECIFICATION_TESTING.md +++ b/SPECIFICATION_TESTING.md @@ -40,7 +40,7 @@ Note: Remember to set the `OPENSEARCH_PASSWORD` environment variable everytime y ## Writing Spec Tests -The spec tests reside in the [tests/](tests) directory. Tests are organized in folders that match [namespaces](spec/namespaces). For example, tests for APIs defined in [spec/namespaces/indices.yaml](spec/namespaces/indices.yaml) can be found in [tests/indices/index.yaml](tests/indices/index.yaml) (for `/{index}`), and [tests/indices/_doc.yaml](tests/indices/_doc.yaml) (for `/{index}/_doc`). +The spec tests reside in the [tests/](tests) directory. Tests are organized in folders that match [namespaces](spec/namespaces). For example, tests for APIs defined in [spec/namespaces/indices.yaml](spec/namespaces/indices.yaml) can be found in [tests/indices/index.yaml](tests/indices/index.yaml) (for `/{index}`), and [tests/indices/doc.yaml](tests/indices/doc.yaml) (for `/{index}/_doc`). Each yaml file in the tests directory represents a test story that tests a collection of related operations. diff --git a/spec/namespaces/indices.yaml b/spec/namespaces/indices.yaml index 9c524871c..2bda325dc 100644 --- a/spec/namespaces/indices.yaml +++ b/spec/namespaces/indices.yaml @@ -2393,15 +2393,22 @@ components: content: application/json: schema: - type: object - properties: - acknowledged: - type: boolean - shards_acknowledged: - type: boolean - required: - - acknowledged - - shards_acknowledged + oneOf: + - type: object + properties: + task: + $ref: '../schemas/_common.yaml#/components/schemas/TaskId' + additionalProperties: false + - type: object + properties: + acknowledged: + type: boolean + shards_acknowledged: + type: boolean + required: + - acknowledged + - shards_acknowledged + additionalProperties: false indices.put_alias@200: description: '' content: diff --git a/tests/indices/close.yaml b/tests/indices/close.yaml new file mode 100644 index 000000000..0766f3085 --- /dev/null +++ b/tests/indices/close.yaml @@ -0,0 +1,38 @@ +$schema: ../../json_schemas/test_story.schema.yaml + +description: Test closing an index. +prologues: + - path: /movies + method: PUT + status: [200] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Close an index. + path: /{index}/_close + method: POST + parameters: + index: movies + allow_no_indices: true + expand_wildcards: all + ignore_unavailable: true + wait_for_active_shards: 0 + cluster_manager_timeout: 30s + timeout: 30s + response: + status: 200 + payload: + indices: + movies: + closed: true + - synopsis: Close an already closed index. + path: /{index}/_close + method: POST + parameters: + index: movies + response: + status: 200 + payload: + indices: {} diff --git a/tests/indices/_doc.yaml b/tests/indices/doc.yaml similarity index 100% rename from tests/indices/_doc.yaml rename to tests/indices/doc.yaml diff --git a/tests/indices/open.yaml b/tests/indices/open.yaml new file mode 100644 index 000000000..dbcade065 --- /dev/null +++ b/tests/indices/open.yaml @@ -0,0 +1,63 @@ +$schema: ../../json_schemas/test_story.schema.yaml + +description: Test opening an index. +prologues: + - path: /movies + method: PUT + status: [200] + - path: /games + method: PUT + status: [200] + - path: /movies/_close + method: POST + status: [200] + - path: /games/_close + method: POST + status: [200] +epilogues: + - path: /movies,games + method: DELETE + status: [200, 404] +chapters: + - synopsis: Open a closed index. + path: /{index}/_open + method: POST + parameters: + index: movies + allow_no_indices: true + expand_wildcards: all + ignore_unavailable: true + wait_for_active_shards: 0 + cluster_manager_timeout: 30s + timeout: 30s + wait_for_completion: true + response: + status: 200 + payload: + shards_acknowledged: true + acknowledged: true + - synopsis: Open a closed index (wait_for_completion=false). + path: /{index}/_open + method: POST + parameters: + index: movies + allow_no_indices: true + expand_wildcards: all + ignore_unavailable: true + wait_for_active_shards: 0 + cluster_manager_timeout: 30s + timeout: 30s + wait_for_completion: false + task_execution_timeout: 1m + response: + status: 200 + - synopsis: Open an already opened index. + path: /{index}/_open + method: POST + parameters: + index: movies + response: + status: 200 + payload: + shards_acknowledged: true + acknowledged: true diff --git a/tools/src/tester/ChapterReader.ts b/tools/src/tester/ChapterReader.ts index 7cb5219e7..2b4b64729 100644 --- a/tools/src/tester/ChapterReader.ts +++ b/tools/src/tester/ChapterReader.ts @@ -61,7 +61,7 @@ export default class ChapterReader { response.message = payload.error?.reason ?? e.response.statusText response.error = e - this.logger.info(`<= ${response.status} (${response.content_type}) | ${response.payload ?? response.message}`) + this.logger.info(`<= ${response.status} (${response.content_type}) | ${response.payload ? to_json(response.payload) : response.message}`) }) return response as ActualResponse }