Files
opensearch-pyd/opensearchpy/_async/helpers/test.py
T
55f9940d51 Remove HEAD-handling hack. (#794)
* remove HEAD -> GET workaround

Signed-off-by: dblock <dblock@amazon.com>

* Removed remaining HEAD-handling code.

Signed-off-by: dblock <dblock@amazon.com>

* Fixed remaining references to admin:admin.

Signed-off-by: dblock <dblock@amazon.com>

---------

Signed-off-by: dblock <dblock@amazon.com>
Co-authored-by: Vincent Castaneda <vincent.castaneda@sage.com>
2024-08-15 10:15:13 -04:00

44 lines
1.3 KiB
Python

# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.
import os
import time
from typing import Any
from unittest import SkipTest
from opensearchpy import AsyncOpenSearch
from opensearchpy.exceptions import ConnectionError
OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://localhost:9200")
async def get_test_client(nowait: bool = False, **kwargs: Any) -> Any:
# construct kwargs from the environment
kw = {"timeout": 30}
from opensearchpy import AsyncConnection
async_connection = AsyncConnection()
if hasattr(async_connection, "AIOHttpConnection"):
kw["connection_class"] = getattr(async_connection, "AIOHttpConnection")
kw.update(kwargs)
client = AsyncOpenSearch(OPENSEARCH_URL, **kw) # type: ignore
# wait for yellow status
for _ in range(1 if nowait else 100):
try:
await client.cluster.health(wait_for_status="yellow")
return client
except ConnectionError:
time.sleep(0.1)
else:
# timeout
raise SkipTest("OpenSearch failed to start.")