diff --git a/CHANGELOG.md b/CHANGELOG.md index bfc76a33..2e5bf3f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Added ### Changed - Removed deprecated `numpy.float_` and update NumPy/Pandas imports ([#762](https://github.com/opensearch-project/opensearch-py/pull/762)) +- Removed workaround for [aiohttp#1769](https://github.com/aio-libs/aiohttp/issues/1769) ([#794](https://github.com/opensearch-project/opensearch-py/pull/794)) ### Deprecated ### Removed - Removed redundant dependency on six ([#781](https://github.com/opensearch-project/opensearch-py/pull/781)) diff --git a/benchmarks/bench_async.py b/benchmarks/bench_async.py index 251b0b99..66fc3ddc 100644 --- a/benchmarks/bench_async.py +++ b/benchmarks/bench_async.py @@ -10,6 +10,7 @@ # GitHub history for details. import asyncio +import os import uuid from typing import Any @@ -42,7 +43,7 @@ async def test_async(client_count: int = 1, item_count: int = 1) -> None: """ host = "localhost" port = 9200 - auth = ("admin", "admin") + auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")) index_name = "test-index-async" clients = [] diff --git a/benchmarks/bench_info_sync.py b/benchmarks/bench_info_sync.py index 5d0729d9..78dce182 100644 --- a/benchmarks/bench_info_sync.py +++ b/benchmarks/bench_info_sync.py @@ -11,6 +11,7 @@ import logging +import os import sys import time from typing import Any @@ -34,7 +35,7 @@ def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) - """test to index with thread_count threads, item_count records and run client_count clients""" host = "localhost" port = 9200 - auth = ("admin", "admin") + auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")) root = logging.getLogger() # root.setLevel(logging.DEBUG) diff --git a/benchmarks/bench_sync.py b/benchmarks/bench_sync.py index e9c30c53..e9e2479a 100644 --- a/benchmarks/bench_sync.py +++ b/benchmarks/bench_sync.py @@ -11,6 +11,7 @@ import json import logging +import os import sys import time import uuid @@ -52,7 +53,7 @@ def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> N """test to index with thread_count threads, item_count records and run client_count clients""" host = "localhost" port = 9200 - auth = ("admin", "admin") + auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")) index_name = "test-index-sync" root = logging.getLogger() diff --git a/opensearchpy/_async/helpers/test.py b/opensearchpy/_async/helpers/test.py index 455a2781..9f9cbc4d 100644 --- a/opensearchpy/_async/helpers/test.py +++ b/opensearchpy/_async/helpers/test.py @@ -15,7 +15,7 @@ from opensearchpy import AsyncOpenSearch from opensearchpy.exceptions import ConnectionError -OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://admin:admin@localhost:9200") +OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://localhost:9200") async def get_test_client(nowait: bool = False, **kwargs: Any) -> Any: diff --git a/opensearchpy/_async/http_aiohttp.py b/opensearchpy/_async/http_aiohttp.py index 4c383914..1e3da465 100644 --- a/opensearchpy/_async/http_aiohttp.py +++ b/opensearchpy/_async/http_aiohttp.py @@ -246,14 +246,6 @@ async def perform_request( else: query_string = "" - # There is a bug in aiohttp that disables the re-use - # of the connection in the pool when method=HEAD. - # See: aio-libs/aiohttp#1769 - is_head = False - if method == "HEAD": - method = "GET" - is_head = True - # Top-tier tip-toeing happening here. Basically # because Pip's old resolver is bad and wipes out # strict pins in favor of non-strict pins of extras @@ -301,11 +293,7 @@ async def perform_request( timeout=timeout, fingerprint=self.ssl_assert_fingerprint, ) as response: - if is_head: # We actually called 'GET' so throw away the data. - await response.release() - raw_data = "" - else: - raw_data = await response.text() + raw_data = await response.text() duration = self.loop.time() - start # We want to reraise a cancellation or recursion error. diff --git a/opensearchpy/connection/http_async.py b/opensearchpy/connection/http_async.py index ea4af477..d0490878 100644 --- a/opensearchpy/connection/http_async.py +++ b/opensearchpy/connection/http_async.py @@ -167,14 +167,6 @@ async def perform_request( else: query_string = "" - # There is a bug in aiohttp that disables the re-use - # of the connection in the pool when method=HEAD. - # See: https://github.com/aio-libs/aiohttp/issues/1769 - is_head = False - if method == "HEAD": - method = "GET" - is_head = True - # Top-tier tip-toeing happening here. Basically # because Pip's old resolver is bad and wipes out # strict pins in favor of non-strict pins of extras @@ -221,11 +213,7 @@ async def perform_request( timeout=timeout, fingerprint=self.ssl_assert_fingerprint, ) as response: - if is_head: # We actually called 'GET' so throw away the data. - await response.release() - raw_data = "" - else: - raw_data = await response.text() + raw_data = await response.text() duration = self.loop.time() - start # We want to reraise a cancellation or recursion error. diff --git a/opensearchpy/helpers/test.py b/opensearchpy/helpers/test.py index 6ad34b66..f799bd7d 100644 --- a/opensearchpy/helpers/test.py +++ b/opensearchpy/helpers/test.py @@ -34,7 +34,7 @@ from opensearchpy import OpenSearch from opensearchpy.exceptions import ConnectionError -OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://admin:admin@localhost:9200") +OPENSEARCH_URL = os.environ.get("OPENSEARCH_URL", "https://localhost:9200") def get_test_client(nowait: bool = False, **kwargs: Any) -> OpenSearch: @@ -105,10 +105,11 @@ def opensearch_version(client: opensearchpy.client.OpenSearch) -> Any: if "OPENSEARCH_VERSION" in os.environ: OPENSEARCH_VERSION = _get_version(os.environ["OPENSEARCH_VERSION"]) else: - client = OpenSearch( - OPENSEARCH_URL, - verify_certs=False, + OPENSEARCH_VERSION = opensearch_version( + get_test_client( + verify_certs=False, + http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")), + ) ) - OPENSEARCH_VERSION = opensearch_version(client) __all__ = ["OpenSearchTestCase"] diff --git a/samples/logging/log_collection_sample.py b/samples/logging/log_collection_sample.py index 7722a20b..bb3d704b 100644 --- a/samples/logging/log_collection_sample.py +++ b/samples/logging/log_collection_sample.py @@ -38,7 +38,7 @@ def main() -> None: # Setup connection with the OpenSearch cluster print("Setting up connection with OpenSearch cluster...") opensearch_client: Any = OpenSearch( - "https://admin:admin@localhost:9200", + "https://localhost:9200", use_ssl=True, verify_certs=False, ssl_show_warn=False, diff --git a/test_opensearchpy/test_async/test_server/test_helpers/conftest.py b/test_opensearchpy/test_async/test_server/test_helpers/conftest.py index 983ae711..66932402 100644 --- a/test_opensearchpy/test_async/test_server/test_helpers/conftest.py +++ b/test_opensearchpy/test_async/test_server/test_helpers/conftest.py @@ -7,6 +7,7 @@ # Modifications Copyright OpenSearch Contributors. See # GitHub history for details. +import os import re from datetime import datetime from typing import Any @@ -36,7 +37,10 @@ @fixture(scope="function") # type: ignore async def client() -> Any: - client = await get_test_client(verify_certs=False, http_auth=("admin", "admin")) + client = await get_test_client( + verify_certs=False, + http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")), + ) await add_connection("default", client) return client diff --git a/test_opensearchpy/test_server/test_helpers/conftest.py b/test_opensearchpy/test_server/test_helpers/conftest.py index 4f9a8d6f..f7b0815d 100644 --- a/test_opensearchpy/test_server/test_helpers/conftest.py +++ b/test_opensearchpy/test_server/test_helpers/conftest.py @@ -24,6 +24,7 @@ # specific language governing permissions and limitations # under the License. +import os import re from datetime import datetime from typing import Any @@ -46,7 +47,10 @@ @fixture(scope="session") # type: ignore def client() -> Any: - client = get_test_client(verify_certs=False, http_auth=("admin", "admin")) + client = get_test_client( + verify_certs=False, + http_auth=("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")), + ) add_connection("default", client) return client