Skip to content

Commit

Permalink
Merge branch 'main' into nox-docs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>
  • Loading branch information
dblock authored Nov 10, 2023
2 parents 7f84f88 + 58b83d8 commit c6b4437
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- { os: 'ubuntu-latest', python-version: "3.10" }
- { os: 'ubuntu-latest', python-version: "3.11" }
- { os: 'macos-latest', python-version: "3.11" }
- { os: 'windows-latest', python-version: "3.11" }

name: test (os=${{ matrix.entry.os }}, python=${{ matrix.entry.python-version }})
continue-on-error: ${{ matrix.entry.experimental || false }}
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added a utf-8 header to all .py files ([#557](https://github.com/opensearch-project/opensearch-py/pull/557))
- Added `samples`, `benchmarks` and `docs` to `nox -rs format` ([#556](https://github.com/opensearch-project/opensearch-py/pull/556))
- Added guide on the document lifecycle API(s) ([#559](https://github.com/opensearch-project/opensearch-py/pull/559))
- Added Windows CI ([#569](https://github.com/opensearch-project/opensearch-py/pull/569))
### Changed
- Generate `tasks` client from API specs ([#508](https://github.com/opensearch-project/opensearch-py/pull/508))
- Generate `ingest` client from API specs ([#513](https://github.com/opensearch-project/opensearch-py/pull/513))
Expand All @@ -25,6 +26,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Use API generator for all APIs ([#551](https://github.com/opensearch-project/opensearch-py/pull/551))
- Merge `.pyi` type stubs inline ([#563](https://github.com/opensearch-project/opensearch-py/pull/563))
- Expanded type coverage to benchmarks, samples and tests ([#566](https://github.com/opensearch-project/opensearch-py/pull/566))
- Defaulted `enable_cleanup_closed=True` in `aiohttp.TCPConnector` to prevent TLS connection leaks ([#468](https://github.com/opensearch-project/opensearch-py/pull/468))
- Expanded `nox -rs docs` to generate docs ([#568](https://github.com/opensearch-project/opensearch-py/pull/568))
### Deprecated
- Deprecated point-in-time APIs (list_all_point_in_time, create_point_in_time, delete_point_in_time) and Security Client APIs (health_check and update_audit_config) ([#502](https://github.com/opensearch-project/opensearch-py/pull/502))
Expand Down Expand Up @@ -163,4 +165,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[2.2.0]: https://github.com/opensearch-project/opensearch-py/compare/v2.1.1...v2.2.0
[2.3.0]: https://github.com/opensearch-project/opensearch-py/compare/v2.2.0...v2.3.0
[2.3.1]: https://github.com/opensearch-project/opensearch-py/compare/v2.3.0...v2.3.1
[2.3.2]: https://github.com/opensearch-project/opensearch-py/compare/v2.3.1...v2.3.2
[2.3.2]: https://github.com/opensearch-project/opensearch-py/compare/v2.3.1...v2.3.2
9 changes: 7 additions & 2 deletions opensearchpy/_async/http_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def __init__(
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

ca_certs = self.default_ca_certs() if ca_certs is None else ca_certs
if ca_certs is None:
ca_certs = self.default_ca_certs()

if verify_certs:
if not ca_certs:
raise ImproperlyConfigured(
Expand Down Expand Up @@ -376,7 +378,10 @@ async def _create_aiohttp_session(self) -> Any:
cookie_jar=aiohttp.DummyCookieJar(),
response_class=OpenSearchClientResponse,
connector=aiohttp.TCPConnector(
limit=self._limit, use_dns_cache=True, ssl=self._ssl_context
limit=self._limit,
use_dns_cache=True,
enable_cleanup_closed=True,
ssl=self._ssl_context,
),
trust_env=self._trust_env,
)
Expand Down
5 changes: 5 additions & 0 deletions opensearchpy/connection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def __eq__(self, other: object) -> bool:
raise TypeError("Unsupported equality check for %s and %s" % (self, other))
return self.__hash__() == other.__hash__()

def __lt__(self, other: object) -> bool:
if not isinstance(other, Connection):
raise TypeError("Unsupported lt check for %s and %s" % (self, other))
return self.__hash__() < other.__hash__()

def __hash__(self) -> int:
return id(self)

Expand Down
27 changes: 15 additions & 12 deletions test_opensearchpy/test_async/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import aiohttp
import pytest
from _pytest.mark.structures import MarkDecorator
from mock import patch
from mock import MagicMock, patch
from multidict import CIMultiDict
from pytest import raises

Expand Down Expand Up @@ -254,26 +254,29 @@ async def test_warns_if_using_non_default_ssl_kwargs_with_ssl_context(self) -> N
== str(w[0].message)
)

@patch("ssl.SSLContext.load_verify_locations")
async def test_uses_given_ca_certs(
self, load_verify_locations: Any, tmp_path: Any
) -> None:
@patch("ssl.SSLContext", return_value=MagicMock())
async def test_uses_given_ca_certs(self, ssl_context: Any, tmp_path: Any) -> None:
path = tmp_path / "ca_certs.pem"
path.touch()
ssl_context.return_value.load_verify_locations.return_value = None
AIOHttpConnection(use_ssl=True, ca_certs=str(path))
load_verify_locations.assert_called_once_with(cafile=str(path))
ssl_context.return_value.load_verify_locations.assert_called_once_with(
cafile=str(path)
)

@patch("ssl.SSLContext.load_verify_locations")
async def test_uses_default_ca_certs(self, load_verify_locations: Any) -> None:
@patch("ssl.SSLContext", return_value=MagicMock())
async def test_uses_default_ca_certs(self, ssl_context: Any) -> None:
ssl_context.return_value.load_verify_locations.return_value = None
AIOHttpConnection(use_ssl=True)
load_verify_locations.assert_called_once_with(
ssl_context.return_value.load_verify_locations.assert_called_once_with(
cafile=Connection.default_ca_certs()
)

@patch("ssl.SSLContext.load_verify_locations")
async def test_uses_no_ca_certs(self, load_verify_locations: Any) -> None:
@patch("ssl.SSLContext", return_value=MagicMock())
async def test_uses_no_ca_certs(self, ssl_context: Any) -> None:
ssl_context.return_value.load_verify_locations.return_value = None
AIOHttpConnection(use_ssl=True, verify_certs=False)
load_verify_locations.assert_not_called()
ssl_context.return_value.load_verify_locations.assert_not_called()

async def test_trust_env(self) -> None:
con: Any = AIOHttpConnection(trust_env=True)
Expand Down
14 changes: 10 additions & 4 deletions test_opensearchpy/test_async/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ async def test_add_connection(self) -> None:

async def test_request_will_fail_after_X_retries(self) -> None:
t: Any = AsyncTransport(
[{"exception": ConnectionError("abandon ship")}],
[{"exception": ConnectionError(None, "abandon ship", Exception())}],
connection_class=DummyConnection,
)

Expand All @@ -287,7 +287,7 @@ async def test_request_will_fail_after_X_retries(self) -> None:

async def test_failed_connection_will_be_marked_as_dead(self) -> None:
t: Any = AsyncTransport(
[{"exception": ConnectionError("abandon ship")}] * 2,
[{"exception": ConnectionError(None, "abandon ship", Exception())}] * 2,
connection_class=DummyConnection,
)

Expand Down Expand Up @@ -381,7 +381,10 @@ async def test_sniff_reuses_connection_instances_if_possible(self) -> None:

async def test_sniff_on_fail_triggers_sniffing_on_fail(self) -> None:
t: Any = AsyncTransport(
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
[
{"exception": ConnectionError(None, "abandon ship", Exception())},
{"data": CLUSTER_NODES},
],
connection_class=DummyConnection,
sniff_on_connection_fail=True,
max_retries=0,
Expand All @@ -407,7 +410,10 @@ async def test_sniff_on_fail_failing_does_not_prevent_retires(
) -> None:
sniff_hosts.side_effect = [TransportError("sniff failed")]
t: Any = AsyncTransport(
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
[
{"exception": ConnectionError(None, "abandon ship", Exception())},
{"data": CLUSTER_NODES},
],
connection_class=DummyConnection,
sniff_on_connection_fail=True,
max_retries=3,
Expand Down
14 changes: 10 additions & 4 deletions test_opensearchpy/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_add_connection(self) -> None:

def test_request_will_fail_after_X_retries(self) -> None:
t: Any = Transport(
[{"exception": ConnectionError("abandon ship")}],
[{"exception": ConnectionError(None, "abandon ship", Exception())}],
connection_class=DummyConnection,
)

Expand All @@ -275,7 +275,7 @@ def test_request_will_fail_after_X_retries(self) -> None:

def test_failed_connection_will_be_marked_as_dead(self) -> None:
t: Any = Transport(
[{"exception": ConnectionError("abandon ship")}] * 2,
[{"exception": ConnectionError(None, "abandon ship", Exception())}] * 2,
connection_class=DummyConnection,
)

Expand Down Expand Up @@ -349,7 +349,10 @@ def test_sniff_reuses_connection_instances_if_possible(self) -> None:

def test_sniff_on_fail_triggers_sniffing_on_fail(self) -> None:
t: Any = Transport(
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
[
{"exception": ConnectionError(None, "abandon ship", Exception())},
{"data": CLUSTER_NODES},
],
connection_class=DummyConnection,
sniff_on_connection_fail=True,
max_retries=0,
Expand All @@ -366,7 +369,10 @@ def test_sniff_on_fail_failing_does_not_prevent_retires(
) -> None:
sniff_hosts.side_effect = [TransportError("sniff failed")]
t: Any = Transport(
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
[
{"exception": ConnectionError(None, "abandon ship", Exception())},
{"data": CLUSTER_NODES},
],
connection_class=DummyConnection,
sniff_on_connection_fail=True,
max_retries=3,
Expand Down

0 comments on commit c6b4437

Please sign in to comment.