Skip to content

Commit ef8c3cf

Browse files
authored
Dynamically retrieve API spec yaml file from release asset (opensearch-project#5305)
Signed-off-by: Zelin Hao <[email protected]>
1 parent 4705455 commit ef8c3cf

File tree

3 files changed

+11461
-5118
lines changed

3 files changed

+11461
-5118
lines changed

src/test_workflow/smoke_test/smoke_test_runner_opensearch.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,30 @@ def __init__(self, args: TestArgs, test_manifest: TestManifest) -> None:
2828
super().__init__(args, test_manifest)
2929
logging.info("Entering Smoke test for OpenSearch Bundle.")
3030

31-
# TODO: Download the spec from https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml
32-
spec_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "smoke_tests_spec", "opensearch-openapi.yaml")
33-
self.spec_ = Spec.from_file_path(spec_file)
31+
# Below URL is for the pre-release latest. In the future may consider use formal released spec when available.
32+
self.spec_url = "https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml"
33+
self.spec_local_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "smoke_tests_spec", "opensearch-openapi-local.yaml")
34+
self.spec_download_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "smoke_tests_spec", "opensearch-openapi.yaml")
35+
self.spec_path = self.download_spec(self.spec_url, self.spec_local_path, self.spec_download_path)
36+
self.spec_ = Spec.from_file_path(self.spec_path)
3437
self.mimetype = {
3538
"Content-Type": "application/json"
3639
}
37-
# self.openapi = openapi_core.OpenAPI.from_file_path(spec_file)
40+
41+
def download_spec(self, url: str, local_path: str, download_path: str) -> str:
42+
try:
43+
response = requests.get(url, timeout=10)
44+
if response.status_code == 200:
45+
with open(download_path, "wb") as file:
46+
file.write(response.content)
47+
logging.info(f"Downloaded latest spec from {url}")
48+
return download_path
49+
else:
50+
logging.info(f"Failed to fetch remote API spec, using local file: {local_path}")
51+
return local_path
52+
except requests.RequestException:
53+
logging.info(f"Could not reach {url}, using local file: {local_path}")
54+
return local_path
3855

3956
def validate_request_swagger(self, request: Any) -> None:
4057
request = RequestsOpenAPIRequest(request)

0 commit comments

Comments
 (0)