From cc8e5252b762274602b1849c3d7593093de3dd7c Mon Sep 17 00:00:00 2001 From: Milan Balazs Date: Wed, 17 Jan 2024 14:07:31 +0100 Subject: [PATCH 1/4] Fix the 'max_pool_size' parameter passing Signed-off-by: Milan Balazs --- podman/api/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/podman/api/client.py b/podman/api/client.py index 880fdc3d..765d11ff 100644 --- a/podman/api/client.py +++ b/podman/api/client.py @@ -89,7 +89,7 @@ def __init__( num_pools: Optional[int] = None, credstore_env: Optional[Mapping[str, str]] = None, use_ssh_client=True, - max_pools_size=None, + max_pool_size=None, **kwargs, ): # pylint: disable=unused-argument """Instantiate APIClient object. @@ -119,8 +119,8 @@ def __init__( adapter_kwargs = kwargs.copy() if num_pools is not None: adapter_kwargs["pool_connections"] = num_pools - if max_pools_size is not None: - adapter_kwargs["pool_maxsize"] = max_pools_size + if max_pool_size is not None: + adapter_kwargs["pool_maxsize"] = max_pool_size if timeout is not None: adapter_kwargs["timeout"] = timeout From cd11e3826995c6905ca53fd89f7d962da4b31899 Mon Sep 17 00:00:00 2001 From: Milan Balazs Date: Thu, 18 Jan 2024 11:27:47 +0100 Subject: [PATCH 2/4] Keep the backward compatible Fix the parameter passing for HttpAdapter Signed-off-by: Milan Balazs --- podman/api/client.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/podman/api/client.py b/podman/api/client.py index 765d11ff..a68ec761 100644 --- a/podman/api/client.py +++ b/podman/api/client.py @@ -1,6 +1,7 @@ """APIClient for connecting to Podman service.""" import json +import warnings import urllib.parse from typing import Any, ClassVar, IO, Iterable, List, Mapping, Optional, Tuple, Type, Union @@ -27,6 +28,9 @@ _Timeout = Union[None, float, Tuple[float, float], Tuple[float, None]] """Type alias for request timeout parameter.""" +# Make the DeprecationWarning visible for user. +warnings.simplefilter('always', DeprecationWarning) + class APIResponse: """APIResponse proxy requests.Response objects. @@ -90,6 +94,7 @@ def __init__( credstore_env: Optional[Mapping[str, str]] = None, use_ssh_client=True, max_pool_size=None, + max_pools_size=None, # This parameter is kept only for backward compatibility. **kwargs, ): # pylint: disable=unused-argument """Instantiate APIClient object. @@ -103,6 +108,7 @@ def __init__( num_pools: The number of connection pools to cache. credstore_env: Environment for storing credentials. use_ssh_client: Use system ssh agent rather than ssh module. Always, True. + max_pools_size: Deprecated! Please use 'max_pool_size'. max_pool_size: Override number of connections pools to maintain. Default: requests.adapters.DEFAULT_POOLSIZE @@ -117,10 +123,28 @@ def __init__( self.base_url = self._normalize_url(base_url) adapter_kwargs = kwargs.copy() + + # The HTTPAdapter doesn't handle the "**kwargs", so it needs special structure + # where the parameters are set specifically. + http_adapter_kwargs = {} + + # 'max_pools_size' has been changed to 'max_pool_size' + # and the below section is needed for backward compatible. + # This section can be removed in a future release. + if max_pools_size is not None: + warnings.warn("'max_pools_size' parameter is deprecated! " + "Please use 'max_pool_size' parameter.", DeprecationWarning) + if max_pool_size is not None: + raise ValueError("Both of 'max_pools_size' and 'max_pool_size' parameters are set. " + "Please use only the 'max_pool_size', 'max_pools_size' is deprecated!") + max_pool_size = max_pools_size + if num_pools is not None: adapter_kwargs["pool_connections"] = num_pools + http_adapter_kwargs["pool_connections"] = num_pools if max_pool_size is not None: adapter_kwargs["pool_maxsize"] = max_pool_size + http_adapter_kwargs["pool_maxsize"] = max_pool_size if timeout is not None: adapter_kwargs["timeout"] = timeout @@ -133,8 +157,8 @@ def __init__( self.mount("https://", SSHAdapter(self.base_url.geturl(), **adapter_kwargs)) elif self.base_url.scheme == "http": - self.mount("http://", HTTPAdapter(**adapter_kwargs)) - self.mount("https://", HTTPAdapter(**adapter_kwargs)) + self.mount("http://", HTTPAdapter(**http_adapter_kwargs)) + self.mount("https://", HTTPAdapter(**http_adapter_kwargs)) else: assert False, "APIClient.supported_schemes changed without adding a branch here." From a26194ddf04a1a6c556edaad3f31f4da32dc3881 Mon Sep 17 00:00:00 2001 From: Milan Balazs Date: Thu, 18 Jan 2024 11:56:29 +0100 Subject: [PATCH 3/4] Fix the Python Black formatting. Signed-off-by: Milan Balazs --- podman/api/client.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/podman/api/client.py b/podman/api/client.py index a68ec761..3cd52637 100644 --- a/podman/api/client.py +++ b/podman/api/client.py @@ -132,11 +132,15 @@ def __init__( # and the below section is needed for backward compatible. # This section can be removed in a future release. if max_pools_size is not None: - warnings.warn("'max_pools_size' parameter is deprecated! " - "Please use 'max_pool_size' parameter.", DeprecationWarning) + warnings.warn( + "'max_pools_size' parameter is deprecated! Please use 'max_pool_size' parameter.", + DeprecationWarning, + ) if max_pool_size is not None: - raise ValueError("Both of 'max_pools_size' and 'max_pool_size' parameters are set. " - "Please use only the 'max_pool_size', 'max_pools_size' is deprecated!") + raise ValueError( + "Both of 'max_pools_size' and 'max_pool_size' parameters are set. " + "Please use only the 'max_pool_size', 'max_pools_size' is deprecated!" + ) max_pool_size = max_pools_size if num_pools is not None: From 226498938a10211dd8caa3f38218970b28fba6ec Mon Sep 17 00:00:00 2001 From: Milan Balazs Date: Thu, 18 Jan 2024 12:00:35 +0100 Subject: [PATCH 4/4] Use custom warning (ParameterDeprecationWarning) With this custom warning class only the specific warning will be shown to user (warnings.simplefilter). It doesn't affect to other Warings in other modules. Signed-off-by: Milan Balazs --- podman/api/client.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/podman/api/client.py b/podman/api/client.py index 3cd52637..7a98669b 100644 --- a/podman/api/client.py +++ b/podman/api/client.py @@ -28,8 +28,15 @@ _Timeout = Union[None, float, Tuple[float, float], Tuple[float, None]] """Type alias for request timeout parameter.""" -# Make the DeprecationWarning visible for user. -warnings.simplefilter('always', DeprecationWarning) + +class ParameterDeprecationWarning(DeprecationWarning): + """ + Custom DeprecationWarning for deprecated parameters. + """ + + +# Make the ParameterDeprecationWarning visible for user. +warnings.simplefilter('always', ParameterDeprecationWarning) class APIResponse: @@ -134,7 +141,7 @@ def __init__( if max_pools_size is not None: warnings.warn( "'max_pools_size' parameter is deprecated! Please use 'max_pool_size' parameter.", - DeprecationWarning, + ParameterDeprecationWarning, ) if max_pool_size is not None: raise ValueError(