|
42 | 42 | from elasticsearch_serverless._sync.client.utils import _base64_auth_header
|
43 | 43 | from elasticsearch_serverless.compat import string_types
|
44 | 44 |
|
45 |
| -from ..utils import es_api_key, es_url, parse_version |
| 45 | +from ..utils import es_api_key, es_url |
46 | 46 |
|
47 | 47 | # some params had to be changed in python, keep track of them so we can rename
|
48 | 48 | # those in the tests accordingly
|
|
135 | 135 |
|
136 | 136 |
|
137 | 137 | XPACK_FEATURES = None
|
138 |
| -ES_VERSION = None |
139 | 138 | RUN_ASYNC_REST_API_TESTS = (
|
140 | 139 | sys.version_info >= (3, 8)
|
141 | 140 | and os.environ.get("PYTHON_CONNECTION_CLASS") == "requests"
|
@@ -182,16 +181,6 @@ def teardown(self):
|
182 | 181 | self.section("teardown")
|
183 | 182 | self.run_code(self._teardown_code)
|
184 | 183 |
|
185 |
| - def es_version(self): |
186 |
| - global ES_VERSION |
187 |
| - if ES_VERSION is None: |
188 |
| - version_string = (self.client.info())["version"]["number"] |
189 |
| - if "." not in version_string: |
190 |
| - return () |
191 |
| - version = version_string.strip().split(".") |
192 |
| - ES_VERSION = tuple(int(v) if v.isdigit() else 999 for v in version) |
193 |
| - return ES_VERSION |
194 |
| - |
195 | 184 | def section(self, name):
|
196 | 185 | print(("=" * 10) + " " + name + " " + ("=" * 10))
|
197 | 186 |
|
@@ -340,16 +329,6 @@ def run_skip(self, skip):
|
340 | 329 | continue
|
341 | 330 | pytest.skip(f"feature '{feature}' is not supported")
|
342 | 331 |
|
343 |
| - if "version" in skip: |
344 |
| - version, reason = skip["version"], skip["reason"] |
345 |
| - if version == "all": |
346 |
| - pytest.skip(reason) |
347 |
| - min_version, _, max_version = version.partition("-") |
348 |
| - min_version = parse_version(min_version.strip()) or (0,) |
349 |
| - max_version = parse_version(max_version.strip()) or (999,) |
350 |
| - if min_version <= (self.es_version()) <= max_version: |
351 |
| - pytest.skip(reason) |
352 |
| - |
353 | 332 | def run_gt(self, action):
|
354 | 333 | for key, value in action.items():
|
355 | 334 | value = self._resolve(value)
|
@@ -553,55 +532,32 @@ def remove_implicit_resolver(cls, tag_to_remove):
|
553 | 532 |
|
554 | 533 | # Try loading the REST API test specs from the Elastic Artifacts API
|
555 | 534 | try:
|
| 535 | + github_token = os.environ.get("GITHUB_TOKEN") |
| 536 | + if github_token is None: |
| 537 | + raise RuntimeError("GITHUB_TOKEN environment variable is not set") |
| 538 | + |
556 | 539 | # Construct the HTTP and Elasticsearch client
|
557 | 540 | http = urllib3.PoolManager(retries=10)
|
558 | 541 | client = Elasticsearch(es_url(), api_key=es_api_key(), request_timeout=3)
|
559 | 542 |
|
560 |
| - # Make a request to Elasticsearch for the build hash, we'll be looking for |
561 |
| - # an artifact with this same hash to download test specs for. |
562 |
| - client_info = client.info() |
563 |
| - version_number = client_info["version"]["number"] |
564 |
| - build_hash = client_info["version"]["build_hash"] |
565 |
| - |
566 |
| - # Now talk to the artifacts API with the 'STACK_VERSION' environment variable |
567 |
| - resp = http.request( |
568 |
| - "GET", |
569 |
| - f"https://artifacts-api.elastic.co/v1/versions/{version_number}", |
570 |
| - ) |
571 |
| - resp = json.loads(resp.data.decode("utf-8")) |
572 |
| - |
573 |
| - # Look through every build and see if one matches the commit hash |
574 |
| - # we're looking for. If not it's okay, we'll just use the latest and |
575 |
| - # hope for the best! |
576 |
| - builds = resp["version"]["builds"] |
577 |
| - for build in builds: |
578 |
| - if build["projects"]["elasticsearch"]["commit_hash"] == build_hash: |
579 |
| - break |
580 |
| - else: |
581 |
| - build = builds[0] # Use the latest |
582 |
| - |
583 |
| - # Now we're looking for the 'rest-api-spec-<VERSION>-sources.jar' file |
584 |
| - # to download and extract in-memory. |
585 |
| - packages = build["projects"]["elasticsearch"]["packages"] |
586 |
| - for package in packages: |
587 |
| - if re.match(r"rest-resources-zip-.*\.zip", package): |
588 |
| - package_url = packages[package]["url"] |
589 |
| - break |
590 |
| - else: |
591 |
| - raise RuntimeError( |
592 |
| - f"Could not find the package 'rest-resources-zip-*.zip' in build {build!r}" |
593 |
| - ) |
| 543 | + yaml_tests_url = "https://api.github.com/repos/elastic/serverless-clients-tests/zipball/572c72b5b32f145e62a966563688e46401d3d28a" |
594 | 544 |
|
595 | 545 | # Download the zip and start reading YAML from the files in memory
|
596 | 546 | package_zip = zipfile.ZipFile(
|
597 | 547 | io.BytesIO(
|
598 | 548 | http.request(
|
599 |
| - "GET", package_url, headers={"content-type": "application/json"} |
| 549 | + "GET", |
| 550 | + yaml_tests_url, |
| 551 | + headers={ |
| 552 | + "Authorization": f"Bearer {github_token}", |
| 553 | + "Accept": "application/vnd.github+json", |
| 554 | + }, |
600 | 555 | ).data
|
601 | 556 | )
|
602 | 557 | )
|
| 558 | + |
603 | 559 | for yaml_file in package_zip.namelist():
|
604 |
| - if not re.match(r"^rest-api-spec/test/.*\.ya?ml$", yaml_file): |
| 560 | + if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file): |
605 | 561 | continue
|
606 | 562 | yaml_tests = list(
|
607 | 563 | yaml.load_all(package_zip.read(yaml_file), Loader=NoDatesSafeLoader)
|
@@ -660,7 +616,6 @@ def _pytest_param_sort_key(param: pytest.param) -> Tuple[Union[str, int], ...]:
|
660 | 616 | # Sort the tests by ID so they're grouped together nicely.
|
661 | 617 | YAML_TEST_SPECS = sorted(YAML_TEST_SPECS, key=_pytest_param_sort_key)
|
662 | 618 |
|
663 |
| - |
664 | 619 | if not RUN_ASYNC_REST_API_TESTS:
|
665 | 620 |
|
666 | 621 | @pytest.mark.parametrize("test_spec", YAML_TEST_SPECS)
|
|
0 commit comments