From ba14b305d56495844f78f5b1c0bbcf661c865cd4 Mon Sep 17 00:00:00 2001 From: ccamposr Date: Wed, 12 Mar 2025 18:09:42 +0100 Subject: [PATCH] Fix error when iperf3 client add some error warning in the report Test could fail if some log is added to the end of the report due to no json format Change-Id: I396a99f5593dbb19366e9af3c177e6af592661e5 --- tobiko/shell/iperf3/_execute.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tobiko/shell/iperf3/_execute.py b/tobiko/shell/iperf3/_execute.py index edd2e6b63..37ed0f073 100644 --- a/tobiko/shell/iperf3/_execute.py +++ b/tobiko/shell/iperf3/_execute.py @@ -253,6 +253,9 @@ def check_iperf3_client_results(address: typing.Union[str, netaddr.IPAddress], f'Error: {err}') return + # avoid test failure is iperf advertise some error/warning + iperf_log_raw = remove_log_lines_end_json_str(iperf_log_raw) + LOG.debug(f'iperf log raw: {iperf_log_raw} ') if not iperf_log_raw: if config.is_prevent_create(): @@ -292,6 +295,17 @@ def check_iperf3_client_results(address: typing.Union[str, netaddr.IPAddress], CONF.tobiko.rhosp.max_total_breaks_allowed) +def remove_log_lines_end_json_str(json_str: str) -> str: + lines = json_str.splitlines() + while lines: + if lines[-1].strip() == "}": + # Stop when we find } + break + # Remove last line, remove possible error logs + lines.pop() + return "\n".join(lines) + + def iperf3_client_alive(address: typing.Union[str, netaddr.IPAddress], # noqa; pylint: disable=W0613 ssh_client: ssh.SSHClientType = None, **kwargs) -> bool: