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 D083D43B01; Mon, 12 Feb 2024 17:49:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4238B402C8; Mon, 12 Feb 2024 17:49:18 +0100 (CET) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by mails.dpdk.org (Postfix) with ESMTP id 1324C40279 for ; Mon, 12 Feb 2024 17:49:17 +0100 (CET) Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5ceb3fe708eso2373634a12.3 for ; Mon, 12 Feb 2024 08:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1707756556; x=1708361356; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MJTluqO1wLuboodzkvHwg+RDkOLB9ybneZvDy1oa3ZU=; b=Ud/1Vpgz8fPJkRSecEEaYOtOhEU9MHyZoq3G9thCkvzr58Ix6ZacAQHAoaJBLupuPZ Kn/jbcgQ9/fMmn5/wpYD6zfqJ9PtkiPqtI8kJdD+HJbJeHdcq58VKXb2evWortjIQRNq UQJpFEIzgFPUT74Oc3RFWFl08Xj70Nxz1Hu2U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707756556; x=1708361356; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MJTluqO1wLuboodzkvHwg+RDkOLB9ybneZvDy1oa3ZU=; b=fCMfLBOplJ9Bt3mrEVVzgSwmMz4TDgapCNry+20uc3iCZ9ajla4eEWCm2CH7CPW+ep GIVcTeHyb/M/3RX/+kKgmaWpZyEX4a3t+TE7n5poVNRaZFyLwDetuls617ar4ogafwIK WAdjqZ4628sn9rXGld7FUkVYxgS5dX1Q+lFTk9RLj0RyVrSt2D3kWt2Qtg6x0dKjtNvg bGuBeyo6289p3DFAdHVZz9wMUiUF2AqVids4yokhrbYNx2zk1/gtzoUD+XaoNHCcgxHB UYyB9tp63GrHVsfzkPabfgOLh79+oW9juYAFtks1LUAX9M6/rpxAzT5SphS3eI+PwF4R QXvQ== X-Gm-Message-State: AOJu0YwPRE4VvU3LYkU6ayF+eB88WdytlHSnx4UXeNPBBW6b0zCr0LwB g08Qg5Hf7yxue4JasK/NTU7HCbqCQZ8gTjYDQEwd+6B9qt9VtVMfgxLDhTCeiav9TuH41TUj0sz UypcnTC6mOx1WVoacPsQneYek/H7COZQT+8n7wQ== X-Google-Smtp-Source: AGHT+IHjbKj0c+pcdfNdrR4ss8jsSAsmUHMVMPFvx1MV523UL10hTnDYaOCB5REvVtfXNpWq3r5jXhTJtMKICSgcjKQ= X-Received: by 2002:a17:90a:dc01:b0:296:fa99:e94c with SMTP id i1-20020a17090adc0100b00296fa99e94cmr4230146pjv.17.1707756556248; Mon, 12 Feb 2024 08:49:16 -0800 (PST) MIME-Version: 1.0 References: <20240207121641.22739-1-juraj.linkes@pantheon.tech> In-Reply-To: <20240207121641.22739-1-juraj.linkes@pantheon.tech> From: Jeremy Spewock Date: Mon, 12 Feb 2024 11:49:05 -0500 Message-ID: Subject: Re: [PATCH v1] dts: strip whitespaces from stdout and stderr To: =?UTF-8?Q?Juraj_Linke=C5=A1?= Cc: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Wed, Feb 7, 2024 at 7:16=E2=80=AFAM Juraj Linke=C5=A1 wrote: > > 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=C5=A1 > --- > .../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/framewo= rk/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=3DTrue, frozen=3DTrue) > +@dataclass(slots=3DTrue, frozen=3DTrue) > 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 =3D field(init=3DFalse) > + stderr: str =3D field(init=3DFalse) > + > + def __post_init__(self, init_stdout, init_stderr): Are the typehints skipped deliberately here because it's redundant? We might want to include them anyway just for better typehint coverage. > + """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 fi= elds > + 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 >