Skip to content

Commit 215b54e

Browse files
authored
Integration test runner (#12)
1 parent 105add6 commit 215b54e

24 files changed

+306
-498
lines changed

.buildkite/rest-tests.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
# TEMPORARY for 3.11
11+
# https://github.com/aio-libs/aiohttp/issues/6600
12+
AIOHTTP_NO_EXTENSIONS: 1
13+
# https://github.com/aio-libs/frozenlist/issues/285
14+
FROZENLIST_NO_EXTENSIONS: 1
15+
# https://github.com/aio-libs/yarl/issues/680
16+
YARL_NO_EXTENSIONS: 1
17+
EC_REGISTER_BACKEND: "appex-qa-team-cluster"
18+
EC_ENV: "qa"
19+
EC_REGION: "aws-eu-west-1"
20+
EC_PROJECT_NAME: "esv-client-python-test-{{ matrix.python }}-{{ matrix.suite }}-{{ matrix.connection_class }}-{{ key }}"
21+
matrix:
22+
setup:
23+
suite:
24+
- free
25+
- platinum
26+
python:
27+
- "3.7"
28+
- "3.8"
29+
- "3.9"
30+
- "3.10"
31+
- "3.11"
32+
connection_class:
33+
- urllib3
34+
- requests
35+
command: ./.buildkite/run-tests
36+
artifact_paths: "junit/*-junit.xml"
37+
- wait: ~
38+
continue_on_failure: true
39+
- label: ":junit: Test results"
40+
agents:
41+
provider: gcp
42+
image: family/core-ubuntu-2204
43+
plugins:
44+
- junit-annotate#v2.4.1:
45+
artifacts: "junit/*-junit.xml"
46+
job-uuid-file-pattern: "(.*)-junit.xml"
47+
fail-build-on-error: true
48+
failure-format: file

.buildkite/run-tests

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
# fetch cloud creds used by qaf
11+
CLOUD_ACCESS_KEY=$(vault read -field="$EC_ENV" secret/ci/elastic-elasticsearch-serverless-python/cloud-access)
12+
echo "{\"api_key\":{\"$EC_ENV\":\"$CLOUD_ACCESS_KEY\"}}" > "$(pwd)/cloud.json"
13+
14+
run_qaf() {
15+
cmd=$1
16+
docker run --rm \
17+
-e EC_REGISTER_BACKEND \
18+
-e EC_ENV \
19+
-e EC_REGION \
20+
-e EC_PROJECT_NAME \
21+
-e VAULT_TOKEN \
22+
-v "$(pwd)/cloud.json:/root/.elastic/cloud.json" \
23+
docker.elastic.co/employees/dolaru/qaf:latest \
24+
bash -c "$cmd"
25+
}
26+
27+
# ensure serverless instance is deleted even if script errors
28+
cleanup() {
29+
echo -e "--- :elasticsearch: Tear down serverless instance EC_PROJECT_NAME"
30+
run_qaf 'qaf elastic-cloud projects delete'
31+
rm -rf "$(pwd)/cloud.json"
32+
}
33+
trap cleanup EXIT
34+
35+
echo -e "--- :elasticsearch: Start serverless instance"
36+
37+
run_qaf "qaf elastic-cloud projects create --project-type elasticsearch"
38+
deployment=$(run_qaf "qaf elastic-cloud projects describe --as-json --show-credentials")
39+
40+
ES_API_SECRET_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
41+
ELASTICSEARCH_URL=$(echo "$deployment" | jq -r '.elasticsearch.url')
42+
export ELASTICSEARCH_URL
43+
44+
echo -e "--- :computer: Environment variables"
45+
echo -e "ELASTICSEARCH_URL $ELASTICSEARCH_URL"
46+
echo -e "TEST_SUITE $TEST_SUITE"
47+
echo -e "PYTHON_VERSION $PYTHON_VERSION"
48+
echo -e "PYTHON_CONNECTION_CLASS $PYTHON_CONNECTION_CLASS"
49+
50+
echo -e "--- :docker: Build elasticsearch-serverless-python container"
51+
52+
docker build \
53+
--file .ci/Dockerfile \
54+
--tag elasticsearch-serverless-python \
55+
--build-arg "PYTHON_VERSION=$PYTHON_VERSION" \
56+
.
57+
58+
echo -e "--- :docker: :python: Run integration tests for Python $PYTHON_VERSION"
59+
60+
GITHUB_TOKEN=$(vault read -field=token secret/ci/elastic-elasticsearch-serverless-python/github-token)
61+
export GITHUB_TOKEN
62+
63+
docker run \
64+
-e ELASTICSEARCH_URL \
65+
-e "ES_API_KEY=$ES_API_SECRET_KEY" \
66+
-e PYTHON_CONNECTION_CLASS \
67+
-e TEST_SUITE \
68+
-e GITHUB_TOKEN \
69+
-e AIOHTTP_NO_EXTENSIONS \
70+
-e FROZENLIST_NO_EXTENSIONS \
71+
-e YARL_NO_EXTENSIONS \
72+
--name elasticsearch-serverless-python-tests \
73+
--volume "$(pwd)/junit:/code/elasticsearch-serverless-python/junit" \
74+
--rm \
75+
elasticsearch-serverless-python \
76+
nox -s "test-$PYTHON_VERSION"

.ci/Dockerfile

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
ARG PYTHON_VERSION=3.8
1+
ARG PYTHON_VERSION=3.9
22
FROM python:${PYTHON_VERSION}
33

4-
# Default UID/GID to 1000
5-
# it can be overridden at build time
6-
ARG BUILDER_UID=1000
7-
ARG BUILDER_GID=1000
8-
ENV BUILDER_USER elastic
9-
ENV BUILDER_GROUP elastic
10-
114
WORKDIR /code/elasticsearch-serverless-python
5+
RUN mkdir -p /code/elasticsearch-serverless-python/build
126

13-
# Create user
14-
RUN groupadd --system -g ${BUILDER_GID} ${BUILDER_GROUP} \
15-
&& useradd --system --shell /bin/bash -u ${BUILDER_UID} -g ${BUILDER_GROUP} -d /var/lib/elastic -m elastic 1>/dev/null 2>/dev/null \
16-
&& mkdir /code/elasticsearch-serverless-python/build \
17-
&& chown -R ${BUILDER_USER}:${BUILDER_GROUP} /code/
18-
USER ${BUILDER_USER}:${BUILDER_GROUP}
19-
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
7+
COPY pyproject.toml README.rst .
208
RUN python -m pip install \
219
-U --no-cache-dir \
2210
--disable-pip-version-check \
2311
.[dev]
12+
13+
COPY . .

.ci/run-elasticsearch.sh

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

catalog-info.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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: alpha
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+
everyone:
35+
access_level: READ_ONLY
36+
provider_settings:
37+
build_pull_requests: true
38+
build_branches: true
39+
cancel_intermediate_builds: true
40+
cancel_intermediate_builds_branch_filter: '!main'
41+
schedules:
42+
main_semi_daily:
43+
branch: 'main'
44+
cronline: '0 */12 * * *'

elasticsearch_serverless/_async/client/_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
)
3232
from elastic_transport.client_utils import DEFAULT, DefaultType
3333

34-
from ..._version import __versionstr__
3534
from ...compat import warn_stacklevel
3635
from ...exceptions import (
3736
HTTP_EXCEPTIONS,
@@ -42,9 +41,7 @@
4241
from .utils import _base64_auth_header, _quote_query
4342

4443
_WARNING_RE = re.compile(r"\"([^\"]*)\"")
45-
_COMPAT_MIMETYPE_TEMPLATE = "application/vnd.elasticsearch+%s; compatible-with=" + str(
46-
__versionstr__.partition(".")[0]
47-
)
44+
_COMPAT_MIMETYPE_TEMPLATE = "application/vnd.elasticsearch+%s; compatible-with=8"
4845
_COMPAT_MIMETYPE_RE = re.compile(r"application/(json|x-ndjson|vnd\.mapbox-vector-tile)")
4946
_COMPAT_MIMETYPE_SUB = _COMPAT_MIMETYPE_TEMPLATE % (r"\g<1>",)
5047

elasticsearch_serverless/_sync/client/_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
)
3232
from elastic_transport.client_utils import DEFAULT, DefaultType
3333

34-
from ..._version import __versionstr__
3534
from ...compat import warn_stacklevel
3635
from ...exceptions import (
3736
HTTP_EXCEPTIONS,
@@ -42,9 +41,7 @@
4241
from .utils import _base64_auth_header, _quote_query
4342

4443
_WARNING_RE = re.compile(r"\"([^\"]*)\"")
45-
_COMPAT_MIMETYPE_TEMPLATE = "application/vnd.elasticsearch+%s; compatible-with=" + str(
46-
__versionstr__.partition(".")[0]
47-
)
44+
_COMPAT_MIMETYPE_TEMPLATE = "application/vnd.elasticsearch+%s; compatible-with=8"
4845
_COMPAT_MIMETYPE_RE = re.compile(r"application/(json|x-ndjson|vnd\.mapbox-vector-tile)")
4946
_COMPAT_MIMETYPE_SUB = _COMPAT_MIMETYPE_TEMPLATE % (r"\g<1>",)
5047

elasticsearch_serverless/_sync/client/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def host_to_node_config(host: _TYPE_HOST) -> NodeConfig:
123123
if isinstance(host, NodeConfig):
124124
return host
125125
elif isinstance(host, str):
126-
return url_to_node_config(host)
126+
return url_to_node_config(host, use_default_ports_for_scheme=True)
127127
elif isinstance(host, Mapping):
128128
return host_mapping_to_node_config(host)
129129
else:

elasticsearch_serverless/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565

6666
# This file exists for backwards compatibility.
6767
warnings.warn(
68-
"Importing from the 'elasticsearch.client' module is deprecated. "
69-
"Instead use 'elasticsearch' module for importing the client.",
68+
"Importing from the 'elasticsearch_serverless.client' module is deprecated. "
69+
"Instead use 'elasticsearch_serverless' module for importing the client.",
7070
category=DeprecationWarning,
7171
stacklevel=2,
7272
)

test_elasticsearch_serverless/conftest.py

Lines changed: 8 additions & 5 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_api_key, es_url, es_version
2525

2626

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

3434

3535
@pytest.fixture(scope="session")
36-
def ca_certs():
37-
return CA_CERTS
36+
def elasticsearch_api_key():
37+
try:
38+
return es_api_key()
39+
except RuntimeError as e:
40+
pytest.skip(str(e))
3841

3942

4043
@pytest.fixture(scope="session")
41-
def elasticsearch_version(elasticsearch_url, ca_certs) -> Tuple[int, ...]:
44+
def elasticsearch_version(elasticsearch_url) -> Tuple[int, ...]:
4245
"""Returns the version of the current Elasticsearch cluster"""
43-
return es_version(Elasticsearch(elasticsearch_url, ca_certs=ca_certs))
46+
return es_version(Elasticsearch(elasticsearch_url))

test_elasticsearch_serverless/test_async/test_server/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
# under the License.
1717

1818
import pytest
19+
import pytest_asyncio
1920

2021
import elasticsearch_serverless
2122

22-
from ...utils import CA_CERTS, wipe_cluster
23+
from ...utils import wipe_cluster
2324

2425
pytestmark = pytest.mark.asyncio
2526

2627

27-
@pytest.fixture(scope="function")
28+
@pytest_asyncio.fixture(scope="function")
2829
@pytest.mark.usefixtures("sync_client")
29-
async def async_client(elasticsearch_url):
30+
async def async_client(elasticsearch_url, elasticsearch_api_key):
3031
# 'sync_client' fixture is used for the guaranteed wipe_cluster() call.
3132

3233
if not hasattr(elasticsearch_serverless, "AsyncElasticsearch"):
@@ -38,7 +39,7 @@ async def async_client(elasticsearch_url):
3839
client = None
3940
try:
4041
client = elasticsearch_serverless.AsyncElasticsearch(
41-
elasticsearch_url, request_timeout=3, ca_certs=CA_CERTS
42+
elasticsearch_url, api_key=elasticsearch_api_key, request_timeout=3
4243
)
4344
yield client
4445
finally:

0 commit comments

Comments
 (0)