From f650d7adcb1c3e16fa821875b3d4abe7cd47a225 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Thu, 21 Mar 2024 10:53:51 +0100 Subject: [PATCH] Apply retries when ping execution fails due to ssh issues When tobiko executes remote ping commands, they could fail due to: - command error - error connecting to the remove server to run ping In the second case, the exception raised is a RetryLimitError. If that exception is not captured, retries cannot be applied. Change-Id: I00a76bb16de14440b25aeda00ee25b8d196992dd --- tobiko/shell/ping/_ping.py | 6 +++--- tobiko/shell/sh/_process.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tobiko/shell/ping/_ping.py b/tobiko/shell/ping/_ping.py index 0bd94466e..cae3d8387 100644 --- a/tobiko/shell/ping/_ping.py +++ b/tobiko/shell/ping/_ping.py @@ -331,10 +331,10 @@ def execute_ping(parameters, ssh_client=None, check=True): timeout=parameters.deadline + 3., expect_exit_status=None, network_namespace=parameters.network_namespace) - except sh.ShellError as ex: + except (sh.ShellError, tobiko.RetryLimitError) as ex: LOG.exception("Error executing ping command") - stdout = ex.stdout - stderr = ex.stderr + stdout = ex.stdout if hasattr(ex, "stdout") else None + stderr = ex.stderr if hasattr(ex, "stderr") else None else: stdout = result.stdout stderr = result.stderr diff --git a/tobiko/shell/sh/_process.py b/tobiko/shell/sh/_process.py index d9a2c541a..8f19407a7 100644 --- a/tobiko/shell/sh/_process.py +++ b/tobiko/shell/sh/_process.py @@ -352,11 +352,12 @@ class ShellProcessFixture(tobiko.SharedFixture): attempt.check_limits() except tobiko.RetryTimeLimitError: LOG.exception("retry timeout expired") + # Eventually raises either ShellCommandTimeout exception or + # RetryTimeLimitError + self.get_exit_status(timeout=timeout) + raise else: return - # Eventually raises ShellCommandTimeout exception - self.get_exit_status(timeout=timeout) - raise StopIteration def _is_communicating(self, streams, send, receive): if send and self.stdin in streams: