[7.x] Fix config of client pytest fixtures
Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
co-authored by
Seth Michael Larson
parent
9744eae1b6
commit
10e76d7234
@@ -24,6 +24,13 @@ from unittest import SkipTest, TestCase
|
||||
from elasticsearch import Elasticsearch
|
||||
from elasticsearch.exceptions import ConnectionError
|
||||
|
||||
if "ELASTICSEARCH_URL" in os.environ:
|
||||
ELASTICSEARCH_URL = os.environ["ELASTICSEARCH_URL"]
|
||||
elif os.environ.get("TEST_SUITE") == "platinum":
|
||||
ELASTICSEARCH_URL = "https://elastic:changeme@localhost:9200"
|
||||
else:
|
||||
ELASTICSEARCH_URL = "http://localhost:9200"
|
||||
|
||||
|
||||
def get_test_client(nowait=False, **kwargs):
|
||||
# construct kwargs from the environment
|
||||
@@ -37,7 +44,7 @@ def get_test_client(nowait=False, **kwargs):
|
||||
)
|
||||
|
||||
kw.update(kwargs)
|
||||
client = Elasticsearch(os.environ.get("ELASTICSEARCH_URL", {}), **kw)
|
||||
client = Elasticsearch(ELASTICSEARCH_URL, **kw)
|
||||
|
||||
# wait for yellow status
|
||||
for _ in range(1 if nowait else 100):
|
||||
|
||||
@@ -20,6 +20,8 @@ from unittest import TestCase
|
||||
|
||||
from ..client import Elasticsearch
|
||||
|
||||
ELASTICSEARCH_URL: str
|
||||
|
||||
def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ...
|
||||
def _get_version(version_string: str) -> Tuple[int, ...]: ...
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
# under the License.
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import elasticsearch
|
||||
from elasticsearch.helpers.test import ELASTICSEARCH_URL
|
||||
|
||||
from ...utils import wipe_cluster
|
||||
|
||||
@@ -34,15 +34,8 @@ async def async_client():
|
||||
if not hasattr(elasticsearch, "AsyncElasticsearch"):
|
||||
pytest.skip("test requires 'AsyncElasticsearch'")
|
||||
|
||||
kw = {
|
||||
"timeout": 3,
|
||||
"ca_certs": ".ci/certs/ca.pem",
|
||||
"connection_class": elasticsearch.AIOHttpConnection,
|
||||
}
|
||||
|
||||
client = elasticsearch.AsyncElasticsearch(
|
||||
[os.environ.get("ELASTICSEARCH_HOST", {})], **kw
|
||||
)
|
||||
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
|
||||
client = elasticsearch.AsyncElasticsearch(ELASTICSEARCH_URL, **kw)
|
||||
|
||||
# wait for yellow status
|
||||
for _ in range(100):
|
||||
|
||||
@@ -21,6 +21,7 @@ import time
|
||||
import pytest
|
||||
|
||||
import elasticsearch
|
||||
from elasticsearch.helpers.test import ELASTICSEARCH_URL
|
||||
|
||||
from ..utils import wipe_cluster
|
||||
|
||||
@@ -29,18 +30,15 @@ from ..utils import wipe_cluster
|
||||
def sync_client():
|
||||
client = None
|
||||
try:
|
||||
kw = {
|
||||
"timeout": 3,
|
||||
"ca_certs": ".ci/certs/ca.pem",
|
||||
"connection_class": getattr(
|
||||
elasticsearch,
|
||||
os.environ.get("PYTHON_CONNECTION_CLASS", "Urllib3HttpConnection"),
|
||||
),
|
||||
}
|
||||
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
|
||||
if "PYTHON_CONNECTION_CLASS" in os.environ:
|
||||
from elasticsearch import connection
|
||||
|
||||
client = elasticsearch.Elasticsearch(
|
||||
[os.environ.get("ELASTICSEARCH_URL", {})], **kw
|
||||
)
|
||||
kw["connection_class"] = getattr(
|
||||
connection, os.environ["PYTHON_CONNECTION_CLASS"]
|
||||
)
|
||||
|
||||
client = elasticsearch.Elasticsearch(ELASTICSEARCH_URL, **kw)
|
||||
|
||||
# wait for yellow status
|
||||
for _ in range(100):
|
||||
|
||||
@@ -71,7 +71,7 @@ def wipe_cluster_settings(client):
|
||||
for name, value in settings.items():
|
||||
if value:
|
||||
new_settings.setdefault(name, {})
|
||||
for key in name.keys():
|
||||
for key in value.keys():
|
||||
new_settings[name][key + ".*"] = None
|
||||
if new_settings:
|
||||
client.cluster.put_settings(body=new_settings)
|
||||
@@ -104,7 +104,6 @@ def wipe_data_streams(client):
|
||||
|
||||
|
||||
def wipe_indices(client):
|
||||
|
||||
client.indices.delete(
|
||||
index="*",
|
||||
expand_wildcards="all",
|
||||
|
||||
Reference in New Issue
Block a user