From patchwork Wed Feb 7 12:16:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 136479 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8803443A46; Wed, 7 Feb 2024 13:16:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 72ABE40279; Wed, 7 Feb 2024 13:16:44 +0100 (CET) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by mails.dpdk.org (Postfix) with ESMTP id 3487E4026E for ; Wed, 7 Feb 2024 13:16:43 +0100 (CET) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-51032058f17so667063e87.3 for ; Wed, 07 Feb 2024 04:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1707308202; x=1707913002; 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=nmtqDPY6klTHRtvZ4ON5zokL5K7hPtEIHMVcFCqqW5w=; b=MfExZ3k9O+jqELvFyW/1eGVt7u+WILmumBom0ZhqlRJPZbm+SlWoTfsnxiYlBGBk+M JrraH+phCdGNkJ335YTG3tVtoC/+LPjdZduX7A6TIZInBWtac1/Wzy2pE2cH+7QhS/8m t8q1/VzMpMn91pmtYl/2kq2SDtsArmYKqhYg5U1e18vKId2h+k7ay5VMeaBAvF3vgeUG KZJ5aP9W7j0cTTOyNuGJ4e4RCEyphJCB3Yj1DCdYraCQDwI43JkBP4H1UhNEws7HS+BF zT/hyJxAhmU/SVo+yymF4Mu/gimvtwnL/ThBOjy5fkWtUoinewrdMokuDTH53plDI09i FoKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707308202; x=1707913002; 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=nmtqDPY6klTHRtvZ4ON5zokL5K7hPtEIHMVcFCqqW5w=; b=YtIHZ5p5XdxranJ9hqzmJNzjPYh3sjf4PZIuPs/o47i7krKTPyxUFVhMjNtwT87dy7 jNBsJN87NGWqIJ1/chPVJYfIaLQNfvyagsHcY4lJ9k7HahsSF1Z5DwPp/Uhc0MUzguq9 colCae76rXk4zlve1CQ8QVi/06mZU8XtrYvaOEOSR7eaqDCxe/YRH1Ss1nDG8sTkUTbG ciMGJ4nBW/5y5Voz7dgep9I0ZhLHMnFmbT0dsDg+19a/Gv9fpamyxnd6DBdgrbiiJHQD bhZ7ri0CvrzmSPgr7GePF68m8WCyyYR85k8r3+rD2U5xShOwmhChgcH/fEIY1SyLwZ8p yUFw== X-Gm-Message-State: AOJu0YxLsKyN7MfhqLRsSEhtoUKuXA2MOve16ADIHYctDV5QVMcRq6Pn VnBremEzHiJCVx0X1BmzrkcNwMPNTksHycNeFewDU7I2/DgfyPvGlCtSW9xzyv8= X-Google-Smtp-Source: AGHT+IHqNrSceYIOwXuJ2pVrmIW7RpvR4Zoy3RWk10QTys33iEoL+TnSkzxFR3BcY3sY4D3oHjc2nw== X-Received: by 2002:a05:6512:33cb:b0:511:499d:5ab6 with SMTP id d11-20020a05651233cb00b00511499d5ab6mr5361233lfg.14.1707308202633; Wed, 07 Feb 2024 04:16:42 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVmQw2+HJUwDby2P076j4z74TZh04c40aDCOXmqxMrAVGv86DNQVMB/ixLNeryAK4IwVpJ29g+AbrCRhBErqml1q0fg8SWE89OKTNrQuiFnPJQmQGcKUJ5ed21Emvx/6m0u7NelUC4Mk2pL6U/BUKyicwuXvtoGKp5WFppOkHnj7ciGUTKj6EX2sDZf7jf8HjrbUvWJWiZuaC52Xlt0rBtx87Kh/rwbDyZSxKQr4xEuwSyCOVhRM2hl3s2SEzfLwIHN 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 cu9-20020a170906ba8900b00a381bcf7bdcsm700341ejd.142.2024.02.07.04.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 04:16:42 -0800 (PST) From: =?utf-8?q?Juraj_Linke=C5=A1?= 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_Linke=C5=A1?= Subject: [PATCH v1] dts: strip whitespaces from stdout and stderr Date: Wed, 7 Feb 2024 13:16:41 +0100 Message-Id: <20240207121641.22739-1-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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 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š --- .../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..6bea1a2306 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, init_stderr): + """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."""