[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 import Elasticsearch
|
||||||
from elasticsearch.exceptions import ConnectionError
|
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):
|
def get_test_client(nowait=False, **kwargs):
|
||||||
# construct kwargs from the environment
|
# construct kwargs from the environment
|
||||||
@@ -37,7 +44,7 @@ def get_test_client(nowait=False, **kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
kw.update(kwargs)
|
kw.update(kwargs)
|
||||||
client = Elasticsearch(os.environ.get("ELASTICSEARCH_URL", {}), **kw)
|
client = Elasticsearch(ELASTICSEARCH_URL, **kw)
|
||||||
|
|
||||||
# wait for yellow status
|
# wait for yellow status
|
||||||
for _ in range(1 if nowait else 100):
|
for _ in range(1 if nowait else 100):
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ from unittest import TestCase
|
|||||||
|
|
||||||
from ..client import Elasticsearch
|
from ..client import Elasticsearch
|
||||||
|
|
||||||
|
ELASTICSEARCH_URL: str
|
||||||
|
|
||||||
def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ...
|
def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ...
|
||||||
def _get_version(version_string: str) -> Tuple[int, ...]: ...
|
def _get_version(version_string: str) -> Tuple[int, ...]: ...
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import elasticsearch
|
import elasticsearch
|
||||||
|
from elasticsearch.helpers.test import ELASTICSEARCH_URL
|
||||||
|
|
||||||
from ...utils import wipe_cluster
|
from ...utils import wipe_cluster
|
||||||
|
|
||||||
@@ -34,15 +34,8 @@ async def async_client():
|
|||||||
if not hasattr(elasticsearch, "AsyncElasticsearch"):
|
if not hasattr(elasticsearch, "AsyncElasticsearch"):
|
||||||
pytest.skip("test requires 'AsyncElasticsearch'")
|
pytest.skip("test requires 'AsyncElasticsearch'")
|
||||||
|
|
||||||
kw = {
|
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
|
||||||
"timeout": 3,
|
client = elasticsearch.AsyncElasticsearch(ELASTICSEARCH_URL, **kw)
|
||||||
"ca_certs": ".ci/certs/ca.pem",
|
|
||||||
"connection_class": elasticsearch.AIOHttpConnection,
|
|
||||||
}
|
|
||||||
|
|
||||||
client = elasticsearch.AsyncElasticsearch(
|
|
||||||
[os.environ.get("ELASTICSEARCH_HOST", {})], **kw
|
|
||||||
)
|
|
||||||
|
|
||||||
# wait for yellow status
|
# wait for yellow status
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import time
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import elasticsearch
|
import elasticsearch
|
||||||
|
from elasticsearch.helpers.test import ELASTICSEARCH_URL
|
||||||
|
|
||||||
from ..utils import wipe_cluster
|
from ..utils import wipe_cluster
|
||||||
|
|
||||||
@@ -29,18 +30,15 @@ from ..utils import wipe_cluster
|
|||||||
def sync_client():
|
def sync_client():
|
||||||
client = None
|
client = None
|
||||||
try:
|
try:
|
||||||
kw = {
|
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
|
||||||
"timeout": 3,
|
if "PYTHON_CONNECTION_CLASS" in os.environ:
|
||||||
"ca_certs": ".ci/certs/ca.pem",
|
from elasticsearch import connection
|
||||||
"connection_class": getattr(
|
|
||||||
elasticsearch,
|
|
||||||
os.environ.get("PYTHON_CONNECTION_CLASS", "Urllib3HttpConnection"),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
client = elasticsearch.Elasticsearch(
|
kw["connection_class"] = getattr(
|
||||||
[os.environ.get("ELASTICSEARCH_URL", {})], **kw
|
connection, os.environ["PYTHON_CONNECTION_CLASS"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
client = elasticsearch.Elasticsearch(ELASTICSEARCH_URL, **kw)
|
||||||
|
|
||||||
# wait for yellow status
|
# wait for yellow status
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ def wipe_cluster_settings(client):
|
|||||||
for name, value in settings.items():
|
for name, value in settings.items():
|
||||||
if value:
|
if value:
|
||||||
new_settings.setdefault(name, {})
|
new_settings.setdefault(name, {})
|
||||||
for key in name.keys():
|
for key in value.keys():
|
||||||
new_settings[name][key + ".*"] = None
|
new_settings[name][key + ".*"] = None
|
||||||
if new_settings:
|
if new_settings:
|
||||||
client.cluster.put_settings(body=new_settings)
|
client.cluster.put_settings(body=new_settings)
|
||||||
@@ -104,7 +104,6 @@ def wipe_data_streams(client):
|
|||||||
|
|
||||||
|
|
||||||
def wipe_indices(client):
|
def wipe_indices(client):
|
||||||
|
|
||||||
client.indices.delete(
|
client.indices.delete(
|
||||||
index="*",
|
index="*",
|
||||||
expand_wildcards="all",
|
expand_wildcards="all",
|
||||||
|
|||||||
Reference in New Issue
Block a user