Skip to content

Commit e5789c7

Browse files
authored
Enhanced the Yaml test runner to utilize the rest-api-spec YAML tests from OpenSearch repo as the input source (opensearch-project#414)
Signed-off-by: saimedhi <saimedhi@amazon.com>
1 parent be57a4d commit e5789c7

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

.github/workflows/integration-unreleased.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
working-directory: opensearch/distribution/archives/linux-tar/build/distributions
5252
run: |
5353
tar xf opensearch-min-*
54-
./opensearch-*/bin/opensearch &
54+
./opensearch-*/bin/opensearch -E path.repo=/tmp &
5555
for attempt in {1..20}; do sleep 5; if curl -s localhost:9200; then echo '=====> ready'; break; fi; echo '=====> waiting...'; done
5656
5757
- name: Checkout Python Client

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010
- Added MacOS and Windows CI workflows ([#390](https://github.com/opensearch-project/opensearch-py/pull/390))
1111
- Compatibility with OpenSearch 2.1.0 - 2.6.0 ([#381](https://github.com/opensearch-project/opensearch-py/pull/381))
1212
- Added 'allow_redirects' parameter in perform_request function for RequestsHttpConnection ([#401](https://github.com/opensearch-project/opensearch-py/pull/401))
13+
- Enhanced YAML test runner to use OpenSearch rest-api-spec YAML tests ([#414](https://github.com/opensearch-project/opensearch-py/pull/414)
1314
### Changed
1415
- Upgrading pytest-asyncio to latest version - 0.21.0 ([#339](https://github.com/opensearch-project/opensearch-py/pull/339))
1516
- Fixed flaky CI tests by replacing httpbin with a simple http_server ([#395](https://github.com/opensearch-project/opensearch-py/pull/395))

test_opensearchpy/test_server/test_rest_api_spec.py

+23-37
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
clients.
3232
"""
3333
import io
34-
import json
3534
import os
3635
import re
3736
import sys
@@ -73,6 +72,23 @@
7372
# broken YAML tests on some releases
7473
SKIP_TESTS = {
7574
# Warning about date_histogram.interval deprecation is raised randomly
75+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search_pipeline/10_basic",
76+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic",
77+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/clone/40_wait_for_completion[0]",
78+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/forcemerge/20_wait_for_completion[0]",
79+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/open/30_wait_for_completion[0]",
80+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/shrink/50_wait_for_completion[0]",
81+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/split/40_wait_for_completion[0]",
82+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cat/nodes/10_basic[1]",
83+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cat/nodeattrs/10_basic[1]",
84+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/put_settings/10_basic[2]",
85+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/put_settings/10_basic[3]",
86+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cat/indices/10_basic[2]",
87+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/health/10_basic[6]",
88+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/cluster/health/20_request_timeout",
89+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search/aggregation/20_terms[4]",
90+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/tasks/list/10_basic[0]",
91+
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/index/90_unsigned_long[1]",
7692
"search/aggregation/250_moving_fn[1]",
7793
# body: null
7894
"indices/simulate_index_template/10_basic[2]",
@@ -171,7 +187,7 @@ def opensearch_version(self):
171187
if "." not in version_string:
172188
return ()
173189
version = version_string.strip().split(".")
174-
OPENSEARCH_VERSION = tuple(int(v) if v.isdigit() else 999 for v in version)
190+
OPENSEARCH_VERSION = tuple(int(v) if v.isdigit() else 99 for v in version)
175191
return OPENSEARCH_VERSION
176192

177193
def section(self, name):
@@ -458,45 +474,15 @@ def sync_runner(sync_client):
458474
http = urllib3.PoolManager(retries=10)
459475
client = get_client()
460476

461-
# Make a request to OpenSearch for the build hash, we'll be looking for
462-
# an artifact with this same hash to download test specs for.
463-
client_info = client.info()
464-
version_number = client_info["version"]["number"]
465-
build_hash = client_info["version"]["build_hash"]
466-
467-
# Now talk to the artifacts API with the 'STACK_VERSION' environment variable
468-
resp = http.request(
469-
"GET",
470-
"https://artifacts-api.elastic.co/v1/versions/%s" % (version_number,),
471-
)
472-
resp = json.loads(resp.data.decode("utf-8"))
473-
474-
# Look through every build and see if one matches the commit hash
475-
# we're looking for. If not it's okay, we'll just use the latest and
476-
# hope for the best!
477-
builds = resp["version"]["builds"]
478-
for build in builds:
479-
if build["projects"]["opensearch"]["commit_hash"] == build_hash:
480-
break
481-
else:
482-
build = builds[0] # Use the latest
483-
484-
# Now we're looking for the 'rest-api-spec-<VERSION>-sources.jar' file
485-
# to download and extract in-memory.
486-
packages = build["projects"]["opensearch"]["packages"]
487-
for package in packages:
488-
if re.match(r"rest-resources-zip-.*\.zip", package):
489-
package_url = packages[package]["url"]
490-
break
491-
else:
492-
raise RuntimeError(
493-
"Could not find the package 'rest-resources-zip-*.zip' in build %r" % build
494-
)
477+
package_url = "https://github.com/opensearch-project/OpenSearch/archive/main.zip"
495478

496479
# Download the zip and start reading YAML from the files in memory
497480
package_zip = zipfile.ZipFile(io.BytesIO(http.request("GET", package_url).data))
498481
for yaml_file in package_zip.namelist():
499-
if not re.match(r"^rest-api-spec/test/.*\.ya?ml$", yaml_file):
482+
if not re.match(
483+
r"^OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/.*\.ya?ml$",
484+
yaml_file,
485+
):
500486
continue
501487
yaml_tests = list(yaml.safe_load_all(package_zip.read(yaml_file)))
502488

0 commit comments

Comments
 (0)