From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 086B843B04;
	Tue, 13 Feb 2024 12:14:43 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id C89244029C;
	Tue, 13 Feb 2024 12:14:42 +0100 (CET)
Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com
 [209.85.218.52]) by mails.dpdk.org (Postfix) with ESMTP id 353E14027B
 for <dev@dpdk.org>; Tue, 13 Feb 2024 12:14:41 +0100 (CET)
Received: by mail-ej1-f52.google.com with SMTP id
 a640c23a62f3a-a3cfacf0eadso64667166b.2
 for <dev@dpdk.org>; Tue, 13 Feb 2024 03:14:41 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=pantheon.tech; s=google; t=1707822881; x=1708427681; darn=dpdk.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=XwS7/IBPVBE7voCmquRkW9Hj7rVCwqCUM+vME9MleZA=;
 b=vSqIDdmQJ7V0zNz7YcJPTaObjFVpFgnvCNtqgk8ESVibeU29Fk5p/FzeeKu1U7gKXj
 HRUoa/MMRy6cz33GuIDgiWCDUYwlSPHwlK0OY5Q1K64pQRkSerZ9Ho+Cwyvb9X84aqjn
 a3UO9WeQwMFyH5D0wEfl1d+oseGKEC8YyVMBaOkDYCvdKZBjOGCDeL8Jy28wMy/4455f
 PeD8EopYFE9gjY7QJSqjlP1ikO6FdYr/b7NlngjNxPgB3Hwy5ceIYx94SOIFSx4/vDN9
 DyMZ5ix3sO5V7V+7n02nU7xk3DhkAPI17VbXSCbfAiiW0J5JMpDrAsFWT9BhrhiCifKd
 vH5g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1707822881; x=1708427681;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=XwS7/IBPVBE7voCmquRkW9Hj7rVCwqCUM+vME9MleZA=;
 b=OoAQPdW9sbd3Hk39tH7m4uFJaHx846ES2eFj8PAiJcrJX/8CSOD9bXuIA1uXZkie5F
 wwgqnyzZE6rveVyiFEhiJm2KXGEOqzXi+HdqTzDQm7s2YJYCnGUshoNyinYiNOtibpiJ
 gJowYZnwVkMlWO7F3mOn8eiJS2IgVTpKlOKA/Ye0rVj2aslAi5YvGhcqQkXWxkQdePe6
 fstWtXwrtyTTdlyxGnJVmBpyu+vyD5v3cdHipedEizzAkBBdMHCpWags8mZUuRzkbdOQ
 QFmRgsYWMuPbvMBrqix5M7Nhg49nwPt+VJv+tLaQk6YjbHNpUt2N2hvTW+Crb2rmPzDA
 EIWg==
X-Gm-Message-State: AOJu0YyGksyxmBnX8Gki/YneLMMYEvVrOwAyXm1oGTcD3V9zA8pXSzJ3
 7BcHrDp7XMXt4Le3AG0kEuGeEKz2IBHyy7uIfiissYEN96O4fxYBtWHQnqJK8W4=
X-Google-Smtp-Source: AGHT+IGmpoonZqBJLJfFyShva3WEoavP+DKJdKGJ2AmsSDRSQkHrg8tJ+Q1ivgixY3JewoxrEZfR1Q==
X-Received: by 2002:a17:906:6d4a:b0:a3d:f94:ebe2 with SMTP id
 a10-20020a1709066d4a00b00a3d0f94ebe2mr697956ejt.76.1707822880862; 
 Tue, 13 Feb 2024 03:14:40 -0800 (PST)
X-Forwarded-Encrypted: i=1;
 AJvYcCWMN1Fx5E4U1wALik593R7JzNrl9nxjl639/kh3sDV/XxWsjOEKxcMlGGcBPpUv5YH1XUz8ls7neS7pOvgCm+ypQegYwpECHfnIMN5K4yQyleQt/qIYcQLkBDE98suxe99r/Mior9PYHj4u/xssm0QgcqlBBSXmJFG7KNYWD8QLejbX/GfN+af+vOYpuS7WUUtPkayuq3iG0hbIDrzAGpQch8CwQAmToAdt6rZQ2a20TW3HtQS2VzUTKQpBlHE2ct2u
Received: from jlinkes-PT-Latitude-5530.pantheon.local
 (81.89.53.154.host.vnet.sk. [81.89.53.154])
 by smtp.gmail.com with ESMTPSA id
 vb9-20020a170907d04900b00a3d12d84cffsm277356ejc.167.2024.02.13.03.14.40
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 13 Feb 2024 03:14:40 -0800 (PST)
From: =?UTF-8?q?Juraj=20Linke=C5=A1?= <juraj.linkes@pantheon.tech>
To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, jspewock@iol.unh.edu,
 probb@iol.unh.edu, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com
Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= <juraj.linkes@pantheon.tech>
Subject: [PATCH v2] dts: strip whitespaces from stdout and stderr
Date: Tue, 13 Feb 2024 12:14:39 +0100
Message-Id: <20240213111439.215386-1-juraj.linkes@pantheon.tech>
X-Mailer: git-send-email 2.34.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

There could be a newline at the end of stdout or stderr of a remotely
executed command. These cause issues when used later, such as when
joining paths from such commands - a newline in the middle of a path is
not valid.

Fixes: ad80f550dbc5 ("dts: add SSH command verification")
Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
 .../remote_session/remote_session.py          | 24 +++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/dts/framework/remote_session/remote_session.py b/dts/framework/remote_session/remote_session.py
index 2059f9a981..6ba097f261 100644
--- a/dts/framework/remote_session/remote_session.py
+++ b/dts/framework/remote_session/remote_session.py
@@ -10,8 +10,8 @@
 """
 
 
-import dataclasses
 from abc import ABC, abstractmethod
+from dataclasses import InitVar, dataclass, field
 from pathlib import PurePath
 
 from framework.config import NodeConfiguration
@@ -20,7 +20,7 @@
 from framework.settings import SETTINGS
 
 
-@dataclasses.dataclass(slots=True, frozen=True)
+@dataclass(slots=True, frozen=True)
 class CommandResult:
     """The result of remote execution of a command.
 
@@ -34,9 +34,25 @@ class CommandResult:
 
     name: str
     command: str
-    stdout: str
-    stderr: str
+    init_stdout: InitVar[str]
+    init_stderr: InitVar[str]
     return_code: int
+    stdout: str = field(init=False)
+    stderr: str = field(init=False)
+
+    def __post_init__(self, init_stdout: str, init_stderr: str) -> None:
+        """Strip the whitespaces from stdout and stderr.
+
+        The generated __init__ method uses object.__setattr__() when the dataclass is frozen,
+        so that's what we use here as well.
+
+        In order to get access to dataclass fields in the __post_init__ method,
+        we have to type them as InitVars. These InitVars are included in the __init__ method's
+        signature, so we have to exclude the actual stdout and stderr fields
+        from the __init__ method's signature, so that we have the proper number of arguments.
+        """
+        object.__setattr__(self, "stdout", init_stdout.strip())
+        object.__setattr__(self, "stderr", init_stderr.strip())
 
     def __str__(self) -> str:
         """Format the command outputs."""
-- 
2.34.1