Skip to content

Commit 96eb5dd

Browse files
committed
Buildkite test runner for REST test suite
With fixes for several test breakages. Integration tests will always run against a real serverless instance that has its own certs.
1 parent 105add6 commit 96eb5dd

File tree

9 files changed

+170
-331
lines changed

9 files changed

+170
-331
lines changed

.buildkite/rest-tests.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
steps:
3+
- label: ":elasticsearch: :python: ES Serverless ({{ matrix.python }}/{{ matrix.connection_class }}) Python Test Suite: {{ matrix.suite }}"
4+
agents:
5+
provider: gcp
6+
env:
7+
PYTHON_VERSION: "{{ matrix.python }}"
8+
TEST_SUITE: "{{ matrix.suite }}"
9+
PYTHON_CONNECTION_CLASS: "{{ matrix.connection_class }}"
10+
matrix:
11+
setup:
12+
suite:
13+
- free
14+
- platinum
15+
python:
16+
- "3.7"
17+
- "3.8"
18+
- "3.9"
19+
- "3.10"
20+
- "3.11"
21+
connection_class:
22+
- urrlib3
23+
- requests
24+
command: ./.buildkite/run-tests
25+
artifact_paths: "junit/*-junit.xml"
26+
- wait: ~
27+
continue_on_failure: true
28+
- label: ":junit: Test results"
29+
agents:
30+
provider: gcp
31+
image: family/core-ubuntu-2204
32+
plugins:
33+
- junit-annotate#v2.4.1:
34+
artifacts: "junit/*-junit.xml"
35+
job-uuid-file-pattern: "(.*)-junit.xml"
36+
fail-build-on-error: true
37+
failure-format: file

.buildkite/run-tests

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Default environment variables
4+
export TEST_SUITE="${TEST_SUITE:=platinum}"
5+
export PYTHON_VERSION="${PYTHON_VERSION:=3.9}"
6+
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
7+
8+
set -euo pipefail
9+
10+
echo -e "--- :elasticsearch: Start serverless instance"
11+
# TODO
12+
13+
echo -e "--- :computer: Environment variables"
14+
echo -e "ELASTICSEARCH_URL $ELASTICSEARCH_URL"
15+
echo -e "STACK_VERSION $STACK_VERSION"
16+
echo -e "TEST_SUITE $TEST_SUITE"
17+
echo -e "PYTHON_VERSION $PYTHON_VERSION"
18+
echo -e "PYTHON_CONNECTION_CLASS $PYTHON_CONNECTION_CLASS"
19+
20+
echo -e "--- :docker: Build elasticsearch-serverless-python container"
21+
22+
docker build \
23+
--file .ci/Dockerfile \
24+
--tag elasticsearch-serverless-python \
25+
--build-arg "PYTHON_VERSION=$PYTHON_VERSION" \
26+
.
27+
28+
echo -e "--- :docker: :python: Run integration tests for Python $PYTHON_VERSION"
29+
30+
docker run \
31+
--env STACK_VERSION \
32+
--env ELASTICSEARCH_URL \
33+
--env TEST_SUITE \
34+
--env PYTHON_CONNECTION_CLASS \
35+
--env ES_API_KEY \
36+
--name elasticsearch-serverless-python-tests \
37+
--volume "$(pwd)/junit:/code/elasticsearch-serverless-python/junit" \
38+
--rm \
39+
elasticsearch-serverless-python \
40+
nox -s "test-$PYTHON_VERSION"
41+
42+
echo -e "--- :elasticsearch: Tear down serverless instance"
43+
echo "TODO"

.ci/run-elasticsearch.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

catalog-info.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
# yaml-language-server: $schema=https://json.schemastore.org/catalog-info.json
3+
apiVersion: backstage.io/v1alpha1
4+
kind: Component
5+
metadata:
6+
name: elasticsearch-serverless-python
7+
spec:
8+
type: library
9+
owner: group:clients-team
10+
lifecycle: production
11+
12+
---
13+
# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/e57ee3bed7a6f73077a3f55a38e76e40ec87a7cf/rre.schema.json
14+
apiVersion: backstage.io/v1alpha1
15+
kind: Resource
16+
metadata:
17+
name: elasticsearch-serverless-python-rest-tests
18+
description: elasticsearch-serverless-python - rest tests
19+
spec:
20+
type: buildkite-pipeline
21+
owner: group:clients-team
22+
system: buildkite
23+
implementation:
24+
apiVersion: buildkite.elastic.dev/v1
25+
kind: Pipeline
26+
metadata:
27+
name: elasticsearch-serverless-python - rest tests
28+
spec:
29+
repository: elastic/elasticsearch-serverless-python
30+
pipeline_file: .buildkite/rest-tests.yaml
31+
teams:
32+
clients-team:
33+
access_level: MANAGE_BUILD_AND_READ
34+
provider_settings:
35+
build_pull_requests: true
36+
build_branches: true
37+
cancel_intermediate_builds: true
38+
cancel_intermediate_builds_branch_filter: '!main'
39+
schedules:
40+
main_semi_daily:
41+
branch: 'main'
42+
cronline: '0 */12 * * *'

test_elasticsearch_serverless/conftest.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from elasticsearch_serverless import Elasticsearch
2323

24-
from .utils import CA_CERTS, es_url, es_version
24+
from .utils import es_url, es_version
2525

2626

2727
@pytest.fixture(scope="session")
@@ -33,11 +33,6 @@ def elasticsearch_url():
3333

3434

3535
@pytest.fixture(scope="session")
36-
def ca_certs():
37-
return CA_CERTS
38-
39-
40-
@pytest.fixture(scope="session")
41-
def elasticsearch_version(elasticsearch_url, ca_certs) -> Tuple[int, ...]:
36+
def elasticsearch_version(elasticsearch_url) -> Tuple[int, ...]:
4237
"""Returns the version of the current Elasticsearch cluster"""
43-
return es_version(Elasticsearch(elasticsearch_url, ca_certs=ca_certs))
38+
return es_version(Elasticsearch(elasticsearch_url))

test_elasticsearch_serverless/test_async/test_server/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import elasticsearch_serverless
2121

22-
from ...utils import CA_CERTS, wipe_cluster
22+
from ...utils import wipe_cluster
2323

2424
pytestmark = pytest.mark.asyncio
2525

@@ -38,7 +38,7 @@ async def async_client(elasticsearch_url):
3838
client = None
3939
try:
4040
client = elasticsearch_serverless.AsyncElasticsearch(
41-
elasticsearch_url, request_timeout=3, ca_certs=CA_CERTS
41+
elasticsearch_url, request_timeout=3
4242
)
4343
yield client
4444
finally:

test_elasticsearch_serverless/test_server/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import elasticsearch_serverless
2323

24-
from ..utils import CA_CERTS, wipe_cluster
24+
from ..utils import wipe_cluster, es_api_key
2525

2626
# Information about the Elasticsearch instance running, if any
2727
# Used for
@@ -34,15 +34,15 @@
3434
def sync_client_factory(elasticsearch_url):
3535
client = None
3636
try:
37-
# Configure the client with certificates and optionally
37+
# Configure the client with API key and optionally
3838
# an HTTP conn class depending on 'PYTHON_CONNECTION_CLASS' envvar
39-
kw = {"ca_certs": CA_CERTS}
39+
kw = {}
4040
if "PYTHON_CONNECTION_CLASS" in os.environ:
4141
kw["node_class"] = os.environ["PYTHON_CONNECTION_CLASS"]
4242

4343
# We do this little dance with the URL to force
4444
# Requests to respect 'headers: None' within rest API spec tests.
45-
client = elasticsearch_serverless.Elasticsearch(elasticsearch_url, **kw)
45+
client = elasticsearch_serverless.Elasticsearch(elasticsearch_url, api_key=es_api_key(), **kw)
4646

4747
# Wipe the cluster before we start testing just in case it wasn't wiped
4848
# cleanly from the previous run of pytest?

test_elasticsearch_serverless/test_server/test_rest_api_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from elasticsearch_serverless._sync.client.utils import _base64_auth_header
4343
from elasticsearch_serverless.compat import string_types
4444

45-
from ..utils import CA_CERTS, es_url, parse_version
45+
from ..utils import es_url, es_api_key, parse_version
4646

4747
# some params had to be changed in python, keep track of them so we can rename
4848
# those in the tests accordingly
@@ -555,7 +555,7 @@ def remove_implicit_resolver(cls, tag_to_remove):
555555
try:
556556
# Construct the HTTP and Elasticsearch client
557557
http = urllib3.PoolManager(retries=10)
558-
client = Elasticsearch(es_url(), request_timeout=3, ca_certs=CA_CERTS)
558+
client = Elasticsearch(es_url(), api_key=es_api_key(), request_timeout=3)
559559

560560
# Make a request to Elasticsearch for the build hash, we'll be looking for
561561
# an artifact with this same hash to download test specs for.

0 commit comments

Comments
 (0)