diff --git a/ocp_resources/benchmark.py b/ocp_resources/benchmark.py index 541d552297..ef460d144b 100644 --- a/ocp_resources/benchmark.py +++ b/ocp_resources/benchmark.py @@ -1,4 +1,4 @@ -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 @@ -35,7 +35,7 @@ def _wait_for_instance_key(self, parent, key): str or None: 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, diff --git a/ocp_resources/constants.py b/ocp_resources/constants.py index 811acf67e1..13b4d2b7fb 100644 --- a/ocp_resources/constants.py +++ b/ocp_resources/constants.py @@ -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 diff --git a/ocp_resources/pod.py b/ocp_resources/pod.py index 76b5d82356..27bcbd8bc5 100644 --- a/ocp_resources/pod.py +++ b/ocp_resources/pod.py @@ -2,7 +2,7 @@ import kubernetes -from ocp_resources.constants import TIMEOUT_4MINUTES +from ocp_resources.constants import TIMEOUT_4MINUTES, TIMEOUT_5SEC from ocp_resources.node import Node from ocp_resources.resource import NamespacedResource from timeout_sampler import TimeoutWatch @@ -111,8 +111,8 @@ def execute(self, command, timeout=60, container=None, ignore_rc=False): 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 diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index c4d079c1c3..da146acd5d 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -35,6 +35,8 @@ TIMEOUT_1MINUTE, TIMEOUT_4MINUTES, TIMEOUT_10SEC, + TIMEOUT_30SEC, + TIMEOUT_5SEC, ) from ocp_resources.event import Event from timeout_sampler import ( @@ -876,12 +878,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, @@ -1050,7 +1056,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, ): @@ -1539,4 +1545,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, )