Skip to content

Commit cd03697

Browse files
authored
[7.13] Start using the Elastic Artifacts API for YAML REST tests
1 parent a8cf8d9 commit cd03697

File tree

13 files changed

+212
-98
lines changed

13 files changed

+212
-98
lines changed

.ci/functions/imports.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require_stack_version
1818
if [[ -z $es_node_name ]]; then
1919
# only set these once
2020
set -euo pipefail
21-
export TEST_SUITE=${TEST_SUITE-free}
21+
export TEST_SUITE=${TEST_SUITE-platinum}
2222
export RUNSCRIPTS=${RUNSCRIPTS-}
2323
export DETACH=${DETACH-false}
2424
export CLEANUP=${CLEANUP-false}

.ci/run-elasticsearch.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
# Export the TEST_SUITE variable, eg. 'free' or 'platinum' defaults to 'free'.
88
# Export the NUMBER_OF_NODES variable to start more than 1 node
99

10-
# Version 1.2.0
10+
# Version 1.3.0
1111
# - Initial version of the run-elasticsearch.sh script
1212
# - Deleting the volume should not dependent on the container still running
1313
# - Fixed `ES_JAVA_OPTS` config
1414
# - Moved to STACK_VERSION and TEST_VERSION
1515
# - Refactored into functions and imports
1616
# - Support NUMBER_OF_NODES
1717
# - Added 5 retries on docker pull for fixing transient network errors
18+
# - Added flags to make local CCR configurations work
19+
# - Added action.destructive_requires_name=false as the default will be true in v8
1820

1921
script_path=$(dirname $(realpath -s $0))
2022
source $script_path/functions/imports.sh
@@ -37,6 +39,7 @@ environment=($(cat <<-END
3739
--env node.attr.testattr=test
3840
--env path.repo=/tmp
3941
--env repositories.url.allowed_urls=http://snapshot.test*
42+
--env action.destructive_requires_name=false
4043
END
4144
))
4245
if [[ "$TEST_SUITE" == "platinum" ]]; then
@@ -45,11 +48,11 @@ if [[ "$TEST_SUITE" == "platinum" ]]; then
4548
--env xpack.license.self_generated.type=trial
4649
--env xpack.security.enabled=true
4750
--env xpack.security.http.ssl.enabled=true
48-
--env xpack.security.http.ssl.verification_mode=certificate
4951
--env xpack.security.http.ssl.key=certs/testnode.key
5052
--env xpack.security.http.ssl.certificate=certs/testnode.crt
5153
--env xpack.security.http.ssl.certificate_authorities=certs/ca.crt
5254
--env xpack.security.transport.ssl.enabled=true
55+
--env xpack.security.transport.ssl.verification_mode=certificate
5356
--env xpack.security.transport.ssl.key=certs/testnode.key
5457
--env xpack.security.transport.ssl.certificate=certs/testnode.crt
5558
--env xpack.security.transport.ssl.certificate_authorities=certs/ca.crt
@@ -104,7 +107,7 @@ END
104107
docker run \
105108
--name "$node_name" \
106109
--network "$network_name" \
107-
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \
110+
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g -da:org.elasticsearch.xpack.ccr.index.engine.FollowingEngineAssertions" \
108111
"${environment[@]}" \
109112
"${volumes[@]}" \
110113
--publish "$http_port":9200 \

.ci/run-repository.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ echo -e "\033[1m>>>>> Run [elastic/elasticsearch-py container] >>>>>>>>>>>>>>>>>
3434
mkdir -p junit
3535
docker run \
3636
--network=${network_name} \
37+
--env "STACK_VERSION=${STACK_VERSION}" \
3738
--env "ELASTICSEARCH_URL=${elasticsearch_url}" \
3839
--env "TEST_SUITE=${TEST_SUITE}" \
3940
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \

.ci/run-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Default environment variables
88
export STACK_VERSION="${STACK_VERSION:=8.0.0-SNAPSHOT}"
9-
export TEST_SUITE="${TEST_SUITE:=free}"
9+
export TEST_SUITE="${TEST_SUITE:=platinum}"
1010
export PYTHON_VERSION="${PYTHON_VERSION:=3.9}"
1111
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=Urllib3HttpConnection}"
1212

.ci/test-matrix.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ STACK_VERSION:
22
- 7.x-SNAPSHOT
33

44
TEST_SUITE:
5-
- free
65
- platinum
76

87
PYTHON_VERSION:

CONTRIBUTING.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ There are several environment variables that control integration tests:
2323
the same as tags of `docker.elastic.co/elasticsearch/elasticsearch`
2424
such as `8.0.0-SNAPSHOT`, `7.x-SNAPSHOT`, etc. Defaults to the
2525
same `*-SNAPSHOT` version as the branch.
26-
- `TEST_SUITE`: Determines how to configure Elasticsearch either by running
27-
without any non-free features or by beginning a Platinum license. Possible options
28-
are `free` and `platinum`. Defaults to `free` as there are fewer test cases.
2926

3027
**NOTE: You don't need to run the live integration tests for all changes. If
3128
you don't have Elasticsearch running locally the integration tests will be skipped.**

elasticsearch/_async/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ async def async_bulk(
267267

268268
# make streaming_bulk yield successful results so we can count them
269269
kwargs["yield_ok"] = True
270-
async for ok, item in async_streaming_bulk(client, actions, *args, **kwargs):
270+
async for ok, item in async_streaming_bulk(
271+
client, actions, ignore_status=ignore_status, *args, **kwargs
272+
):
271273
# go through request-response pairs and detect failures
272274
if not ok:
273275
if not stats_only:

elasticsearch/helpers/test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
if "ELASTICSEARCH_URL" in os.environ:
2828
ELASTICSEARCH_URL = os.environ["ELASTICSEARCH_URL"]
29-
elif os.environ.get("TEST_SUITE") == "platinum":
30-
ELASTICSEARCH_URL = "https://elastic:changeme@localhost:9200"
3129
else:
32-
ELASTICSEARCH_URL = "http://localhost:9200"
30+
ELASTICSEARCH_URL = "https://elastic:changeme@localhost:9200"
3331

3432

3533
def get_test_client(nowait=False, **kwargs):

test_elasticsearch/test_async/test_server/test_rest_api_spec.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
PARAMS_RENAMES,
3434
RUN_ASYNC_REST_API_TESTS,
3535
YAML_TEST_SPECS,
36-
InvalidActionType,
3736
YamlRunner,
3837
)
3938

@@ -85,7 +84,7 @@ async def run_code(self, test):
8584
if hasattr(self, "run_" + action_type):
8685
await await_if_coro(getattr(self, "run_" + action_type)(action))
8786
else:
88-
raise InvalidActionType(action_type)
87+
raise RuntimeError("Invalid action type %r" % (action_type,))
8988

9089
async def run_do(self, action):
9190
api = self.client
@@ -95,6 +94,16 @@ async def run_do(self, action):
9594
allowed_warnings = action.pop("allowed_warnings", ())
9695
assert len(action) == 1
9796

97+
# Remove the x_pack_rest_user authentication
98+
# if it's given via headers. We're already authenticated
99+
# via the 'elastic' user.
100+
if (
101+
headers
102+
and headers.get("Authorization", None)
103+
== "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
104+
):
105+
headers.pop("Authorization")
106+
98107
method, args = list(action.items())[0]
99108
args["headers"] = headers
100109

@@ -135,6 +144,18 @@ async def run_do(self, action):
135144
and str(w.message) not in allowed_warnings
136145
]
137146

147+
# This warning can show up in many places but isn't accounted for
148+
# in tests, so we remove it to make sure things pass.
149+
include_type_name_warning = (
150+
"[types removal] Using include_type_name in create index requests is deprecated. "
151+
"The parameter will be removed in the next major version."
152+
)
153+
if (
154+
include_type_name_warning in caught_warnings
155+
and include_type_name_warning not in warn
156+
):
157+
caught_warnings.remove(include_type_name_warning)
158+
138159
# Sorting removes the issue with order raised. We only care about
139160
# if all warnings are raised in the single API call.
140161
if warn and sorted(warn) != sorted(caught_warnings):

test_elasticsearch/test_server/conftest.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@
2525

2626
from ..utils import wipe_cluster
2727

28+
# Information about the Elasticsearch instance running, if any
29+
# Used for
30+
ELASTICSEARCH_VERSION = ""
31+
ELASTICSEARCH_BUILD_HASH = ""
32+
ELASTICSEARCH_REST_API_TESTS = []
2833

29-
@pytest.fixture(scope="function")
30-
def sync_client():
34+
35+
@pytest.fixture(scope="session")
36+
def sync_client_factory():
3137
client = None
3238
try:
39+
# Configure the client with certificates and optionally
40+
# an HTTP conn class depending on 'PYTHON_CONNECTION_CLASS' envvar
3341
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
3442
if "PYTHON_CONNECTION_CLASS" in os.environ:
3543
from elasticsearch import connection
@@ -40,20 +48,26 @@ def sync_client():
4048

4149
client = elasticsearch.Elasticsearch(ELASTICSEARCH_URL, **kw)
4250

43-
# wait for yellow status
51+
# Wait for the cluster to report a status of 'yellow'
4452
for _ in range(100):
4553
try:
4654
client.cluster.health(wait_for_status="yellow")
4755
break
4856
except ConnectionError:
4957
time.sleep(0.1)
5058
else:
51-
# timeout
52-
pytest.skip("Elasticsearch failed to start.")
59+
pytest.skip("Elasticsearch wasn't running at %r" % (ELASTICSEARCH_URL,))
5360

61+
wipe_cluster(client)
5462
yield client
55-
5663
finally:
5764
if client:
58-
wipe_cluster(client)
5965
client.close()
66+
67+
68+
@pytest.fixture(scope="function")
69+
def sync_client(sync_client_factory):
70+
try:
71+
yield sync_client_factory
72+
finally:
73+
wipe_cluster(sync_client_factory)

0 commit comments

Comments
 (0)