From 0d08449b2acb612346375f1338693c2acb079944 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Mon, 21 Apr 2025 12:34:03 +0200 Subject: [PATCH] Run background iperf3 tests with --json-stream option always Either iperf3 is run from a pod (we recommend to use a certain centos10 pod) or from the supported Fedora 41 Advanced VM instances, iperf3 supports the --json-stream option on those environments (iperf version greater or equal to 3.17). This option can be used with --logfile (the output is written for every iperf3 interval on a file) or without it (the output is written to stdout). This option should not be used when iperf3 is run from the test machine/container: undercloud, devstack, tobiko pod (in case of podified envs). Change-Id: I0491dbff33619ca3096a9eeac70ae4a46c68b62d --- tobiko/podified/_openshift.py | 2 +- tobiko/shell/iperf3/__init__.py | 1 - tobiko/shell/iperf3/_execute.py | 11 ++++++++++- tobiko/shell/iperf3/_interface.py | 16 ++++++++++++---- tobiko/shell/iperf3/_parameters.py | 3 +++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tobiko/podified/_openshift.py b/tobiko/podified/_openshift.py index 974101678..b4d13a8b9 100644 --- a/tobiko/podified/_openshift.py +++ b/tobiko/podified/_openshift.py @@ -502,7 +502,7 @@ def start_iperf3( parameters = iperf3.iperf3_client_parameters( address=address, bitrate=bitrate, download=download, port=port, protocol=protocol, - timeout=0, logfile=iperf3.JSON_STREAM) + timeout=0, json_stream=True) cmd_args = iperf3.get_iperf3_client_command( parameters).as_list()[1:] diff --git a/tobiko/shell/iperf3/__init__.py b/tobiko/shell/iperf3/__init__.py index e7ce74199..c6d43674f 100644 --- a/tobiko/shell/iperf3/__init__.py +++ b/tobiko/shell/iperf3/__init__.py @@ -20,7 +20,6 @@ from tobiko.shell.iperf3 import _execute from tobiko.shell.iperf3 import _interface from tobiko.shell.iperf3 import _parameters -JSON_STREAM = _interface.JSON_STREAM assert_has_bandwith_limits = _assert.assert_has_bandwith_limits execute_iperf3_client_in_background = \ diff --git a/tobiko/shell/iperf3/_execute.py b/tobiko/shell/iperf3/_execute.py index df38dff0f..acb950883 100644 --- a/tobiko/shell/iperf3/_execute.py +++ b/tobiko/shell/iperf3/_execute.py @@ -89,10 +89,19 @@ def execute_iperf3_client(address: typing.Union[str, netaddr.IPAddress], params_timeout = 0 elif timeout is not None: params_timeout = int(timeout - 0.5) + + # json_stream option should be set when: + # - tests are run_in_background + # - tests are executed from a VM instance + # This way we avoid using that option from the test machine (undercloud, + # test pod, devstack, ...) where it is not supported + # iperf3 support this option from version 3.17 + json_stream = run_in_background and (ssh_client is not None) + parameters = _parameters.iperf3_client_parameters( address=address, bitrate=bitrate, download=download, port=port, protocol=protocol, - timeout=params_timeout, logfile=logfile) + timeout=params_timeout, json_stream=json_stream, logfile=logfile) command = _interface.get_iperf3_client_command(parameters) # output is a dictionary diff --git a/tobiko/shell/iperf3/_interface.py b/tobiko/shell/iperf3/_interface.py index 338515d5a..63dab11b8 100644 --- a/tobiko/shell/iperf3/_interface.py +++ b/tobiko/shell/iperf3/_interface.py @@ -23,8 +23,6 @@ from tobiko.shell import sh LOG = log.getLogger(__name__) -JSON_STREAM = "json-stream" - def get_iperf3_client_command(parameters: _parameters.Iperf3ClientParameters): interface = Iperf3Interface() @@ -68,6 +66,8 @@ class Iperf3Interface: options += self.get_download_option(parameters.download) if parameters.protocol is not None: options += self.get_protocol_option(parameters.protocol) + if parameters.json_stream is not None: + options += self.get_json_stream_option(parameters.json_stream) if parameters.logfile is not None: options += self.get_logfile_option(parameters.logfile) return options @@ -124,7 +124,15 @@ class Iperf3Interface: return ['-p', port] @staticmethod - def get_logfile_option(logfile): - if logfile == JSON_STREAM: + def get_json_stream_option(json_stream: bool): + # NOTE: when iperf3 is run with --json-stream, new json + # entries are written for every interval + # This option is supported from iperf3 version 3.17: + if json_stream: return ['--json-stream'] + else: + return [] + + @staticmethod + def get_logfile_option(logfile): return ['--logfile', logfile] diff --git a/tobiko/shell/iperf3/_parameters.py b/tobiko/shell/iperf3/_parameters.py index 558ba614a..3d6acff56 100644 --- a/tobiko/shell/iperf3/_parameters.py +++ b/tobiko/shell/iperf3/_parameters.py @@ -29,6 +29,7 @@ class Iperf3ClientParameters(typing.NamedTuple): port: typing.Optional[int] = None protocol: typing.Optional[str] = None timeout: typing.Optional[int] = None + json_stream: typing.Optional[bool] = None logfile: typing.Optional[str] = None @@ -44,6 +45,7 @@ def iperf3_client_parameters( port: int = None, protocol: str = None, timeout: int = None, + json_stream: bool = None, logfile: str = None): """Get iperf3 client parameters mode allowed values: client or server @@ -68,6 +70,7 @@ def iperf3_client_parameters( port=port, protocol=protocol, timeout=timeout, + json_stream=json_stream, logfile=logfile)