Skip to content

Commit

Permalink
Merge pull request #366 from milanbalazs/main
Browse files Browse the repository at this point in the history
Fix the 'max_pool_size' parameter passing for Adapters
  • Loading branch information
openshift-merge-bot[bot] authored Jan 18, 2024
2 parents 51463b6 + 2264989 commit 1d99b26
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions podman/api/client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -28,6 +29,16 @@
"""Type alias for request timeout parameter."""


class ParameterDeprecationWarning(DeprecationWarning):
"""
Custom DeprecationWarning for deprecated parameters.
"""


# Make the ParameterDeprecationWarning visible for user.
warnings.simplefilter('always', ParameterDeprecationWarning)


class APIResponse:
"""APIResponse proxy requests.Response objects.
Expand Down Expand Up @@ -89,7 +100,8 @@ 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,
max_pools_size=None, # This parameter is kept only for backward compatibility.
**kwargs,
): # pylint: disable=unused-argument
"""Instantiate APIClient object.
Expand All @@ -103,6 +115,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
Expand All @@ -117,10 +130,32 @@ 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.",
ParameterDeprecationWarning,
)
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
if max_pools_size is not None:
adapter_kwargs["pool_maxsize"] = max_pools_size
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

Expand All @@ -133,8 +168,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."

Expand Down

0 comments on commit 1d99b26

Please sign in to comment.