Skip to content

Commit

Permalink
increase timeout and sleep value for retry_cluster_exceptions() in pa…
Browse files Browse the repository at this point in the history
…tch call (#2217)

* increase timeout and sleep value for retry_cluster_exceptions() in patch call

* fix typo
  • Loading branch information
dbasunag authored Dec 3, 2024
1 parent bc52f84 commit 1046423
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ocp_resources/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Optional

from ocp_resources.constants import NOT_FOUND_ERROR_EXCEPTION_DICT
from ocp_resources.constants import NOT_FOUND_ERROR_EXCEPTION_DICT, TIMEOUT_30SEC
from ocp_resources.resource import NamespacedResource
from timeout_sampler import TimeoutSampler

Expand Down Expand Up @@ -37,7 +37,7 @@ def _wait_for_instance_key(self, parent: str, key: str) -> Any:
Any: Value of key if found, otherwise None
"""
samples = TimeoutSampler(
wait_timeout=30,
wait_timeout=TIMEOUT_30SEC,
sleep=1,
func=lambda: getattr(self.instance, parent, None),
exceptions_dict=NOT_FOUND_ERROR_EXCEPTION_DICT,
Expand Down
2 changes: 2 additions & 0 deletions ocp_resources/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
PROTOCOL_ERROR_EXCEPTION_DICT: Dict[type[Exception], List[str]] = {ProtocolError: []}
NOT_FOUND_ERROR_EXCEPTION_DICT: Dict[type[Exception], List[str]] = {NotFoundError: []}

TIMEOUT_5SEC: int = 5
TIMEOUT_10SEC: int = 10
TIMEOUT_30SEC: int = 30
TIMEOUT_1MINUTE: int = 60
TIMEOUT_2MINUTES: int = 2 * 60
TIMEOUT_4MINUTES: int = 4 * 60
Expand Down
5 changes: 3 additions & 2 deletions ocp_resources/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kubernetes
from timeout_sampler import TimeoutWatch

from ocp_resources.constants import TIMEOUT_5SEC
from ocp_resources.exceptions import ExecOnPodError
from ocp_resources.node import Node

Expand Down Expand Up @@ -510,8 +511,8 @@ def execute(self, command: List[str], timeout: int = 60, container: str = "", ig
if rcstring is None:
raise ExecOnPodError(command=command, rc=-1, out="", err=stream_closed_error)

stdout = resp.read_stdout(timeout=5)
stderr = resp.read_stderr(timeout=5)
stdout = resp.read_stdout(timeout=TIMEOUT_5SEC)
stderr = resp.read_stderr(timeout=TIMEOUT_5SEC)

if rcstring == "Success" or ignore_rc:
return stdout
Expand Down
16 changes: 12 additions & 4 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
TIMEOUT_1MINUTE,
TIMEOUT_4MINUTES,
TIMEOUT_10SEC,
TIMEOUT_30SEC,
TIMEOUT_5SEC,
)
from ocp_resources.event import Event
from timeout_sampler import (
Expand Down Expand Up @@ -955,12 +957,16 @@ def update_replace(self, resource_dict: Dict[str, Any]) -> None:

@staticmethod
def retry_cluster_exceptions(
func, exceptions_dict: Dict[type[Exception], List[str]] = DEFAULT_CLUSTER_RETRY_EXCEPTIONS, **kwargs: Any
func,
exceptions_dict: Dict[type[Exception], List[str]] = DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
timeout: int = TIMEOUT_10SEC,
sleep_time: int = 1,
**kwargs: Any,
) -> Any:
try:
sampler = TimeoutSampler(
wait_timeout=TIMEOUT_10SEC,
sleep=1,
wait_timeout=timeout,
sleep=sleep_time,
func=func,
print_log=False,
exceptions_dict=exceptions_dict,
Expand Down Expand Up @@ -1129,7 +1135,7 @@ def api_request(self, method: str, action: str, url: str, **params: Any) -> Dict
def wait_for_conditions(self) -> None:
timeout_watcher = TimeoutWatch(timeout=30)
for sample in TimeoutSampler(
wait_timeout=30,
wait_timeout=TIMEOUT_30SEC,
sleep=1,
func=lambda: self.exists,
):
Expand Down Expand Up @@ -1613,4 +1619,6 @@ def _apply_patches_sampler(self, patches: Dict[Any, Any], action_text: str, acti
patches=patches,
action_text=action_text,
action=action,
timeout=TIMEOUT_30SEC,
sleep_time=TIMEOUT_5SEC,
)

0 comments on commit 1046423

Please sign in to comment.