From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2CDFC440CE; Fri, 31 May 2024 13:22:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2312F42D45; Fri, 31 May 2024 13:22:18 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id A0F914161A for ; Fri, 31 May 2024 13:22:14 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 592C2169C; Fri, 31 May 2024 04:22:38 -0700 (PDT) Received: from localhost.localdomain (FVFG51LCQ05N.cambridge.arm.com [10.1.39.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 657A33F792; Fri, 31 May 2024 04:22:13 -0700 (PDT) From: Luca Vizzarro To: dev@dpdk.org Cc: Jeremy Spewock , =?UTF-8?q?Juraj=20Linke=C5=A1?= , Luca Vizzarro , Paul Szczepanek Subject: [PATCH v6 3/3] dts: store stderr in RemoteCommandExecutionError Date: Fri, 31 May 2024 12:20:42 +0100 Message-Id: <20240531112042.18736-4-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531112042.18736-1-luca.vizzarro@arm.com> References: <20240122182611.1904974-1-luca.vizzarro@arm.com> <20240531112042.18736-1-luca.vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Store the stderr of an executed command in RemoteCommandExecutionError. Consequently, when the exception is logged the error message includes the stderr. Signed-off-by: Luca Vizzarro Reviewed-by: Paul Szczepanek --- dts/framework/exception.py | 13 ++++++++++--- dts/framework/remote_session/remote_session.py | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dts/framework/exception.py b/dts/framework/exception.py index cce1e0231a..8502c41779 100644 --- a/dts/framework/exception.py +++ b/dts/framework/exception.py @@ -2,6 +2,7 @@ # Copyright(c) 2010-2014 Intel Corporation # Copyright(c) 2022-2023 PANTHEON.tech s.r.o. # Copyright(c) 2022-2023 University of New Hampshire +# Copyright(c) 2024 Arm Limited """DTS exceptions. @@ -129,21 +130,27 @@ class RemoteCommandExecutionError(DTSError): severity: ClassVar[ErrorSeverity] = ErrorSeverity.REMOTE_CMD_EXEC_ERR #: The executed command. command: str + _command_stderr: str _command_return_code: int - def __init__(self, command: str, command_return_code: int): + def __init__(self, command: str, command_stderr: str, command_return_code: int): """Define the meaning of the first two arguments. Args: command: The executed command. + command_stderr: The stderr of the executed command. command_return_code: The return code of the executed command. """ self.command = command + self._command_stderr = command_stderr self._command_return_code = command_return_code def __str__(self) -> str: - """Include both the command and return code in the string representation.""" - return f"Command {self.command} returned a non-zero exit code: {self._command_return_code}" + """Include the command, its return code and stderr in the string representation.""" + return ( + f"Command '{self.command}' returned a non-zero exit code: " + f"{self._command_return_code}\nStderr: {self._command_stderr}" + ) class InteractiveCommandExecutionError(DTSError): diff --git a/dts/framework/remote_session/remote_session.py b/dts/framework/remote_session/remote_session.py index ad0f53720a..8db26e9efc 100644 --- a/dts/framework/remote_session/remote_session.py +++ b/dts/framework/remote_session/remote_session.py @@ -2,6 +2,7 @@ # Copyright(c) 2010-2014 Intel Corporation # Copyright(c) 2022-2023 PANTHEON.tech s.r.o. # Copyright(c) 2022-2023 University of New Hampshire +# Copyright(c) 2024 Arm Limited """Base remote session. @@ -172,7 +173,7 @@ def send_command( ) self._logger.debug(f"stdout: '{result.stdout}'") self._logger.debug(f"stderr: '{result.stderr}'") - raise RemoteCommandExecutionError(command, result.return_code) + raise RemoteCommandExecutionError(command, result.stderr, result.return_code) self._logger.debug(f"Received from '{command}':\n{result}") self.history.append(result) return result -- 2.34.1