Skip to content

Commit

Permalink
Remove HEAD-handling hack. (#794)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dblock and vcastane committed Aug 15, 2024
1 parent 19a9113 commit 55f9940
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# GitHub history for details.

import asyncio
import os
import uuid
from typing import Any

Expand Down Expand Up @@ -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 = []
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_info_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


import logging
import os
import sys
import time
from typing import Any
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import json
import logging
import os
import sys
import time
import uuid
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/_async/helpers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 1 addition & 13 deletions opensearchpy/_async/http_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 1 addition & 13 deletions opensearchpy/connection/http_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions opensearchpy/helpers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion samples/logging/log_collection_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion test_opensearchpy/test_server/test_helpers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 55f9940

Please sign in to comment.