From: Jeremy Spewock <jspew...@iol.unh.edu> Closing ports is a standard configuration feature that is available in testpmd but the framework lacks the ability to access this command through the Testpmd API. This patch adds a method that performs this action and verifies the results of sending the command to allow developers to have more control over the state of the ports that testpmd is aware of.
Signed-off-by: Jeremy Spewock <jspew...@iol.unh.edu> --- dts/framework/remote_session/testpmd_shell.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 77902a468d..c7161df374 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -844,6 +844,24 @@ def set_ports_queues(self, number_of: int) -> None: self.send_command(f"port config all rxq {number_of}") self.send_command(f"port config all txq {number_of}") + @requires_stopped_ports + def close_all_ports(self, verify: bool = True) -> None: + """Close all ports. + + Args: + verify: If :data:`True` the output of the close command will be scanned in an attempt + to verify that all ports were stopped successfully. Defaults to :data:`True`. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and at lease one port + failed to close. + """ + port_close_output = self.send_command("port close all") + if verify: + num_ports = len(self.ports) + if not all(f"Port {p_id} is closed" in port_close_output for p_id in range(num_ports)): + raise InteractiveCommandExecutionError("Ports were not closed successfully.") + def show_port_info_all(self) -> list[TestPmdPort]: """Returns the information of all the ports. -- 2.46.0