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 AF14E43B04; Tue, 13 Feb 2024 12:06:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 76B3C4029C; Tue, 13 Feb 2024 12:06:57 +0100 (CET) Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by mails.dpdk.org (Postfix) with ESMTP id C7A5842D2A for ; Tue, 13 Feb 2024 12:06:55 +0100 (CET) Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-561f8b8c058so685159a12.0 for ; Tue, 13 Feb 2024 03:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1707822415; x=1708427215; 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=tMJ8zySMoyINs/H/ZtdncfabvDTmwRYnbN+UzyzCpqc=; b=JdgYBLVo6aqbYQRyL3iTyz/MDZxTnWf1F2zQyUUQTEIjdB+GUimMy3rn1gimPp5pgU sSjo+RHMUHQ701nQJctjd5KkJg5JlT9TXBs4WGYRJv0Ev9pqyCzeKdT/NHx4ETyqSfO9 Y+mxdaxoV1adrvlK/0XPO/n51ytYRoJ4sYc0b98Rqf5RpJhj0JIIZqkhJdQDBTeFXCvb n1s9/yFnPkzX9/+UvEz3MKuu8lDHorm44JHhN51SGeOfLzcUFcqZdaeWkkIo7i5QsYjf zF5Mej8liSFBB80p9fp4oE2gyReWGIsuHVsOVeggRXkyPvPLnwgycEzmbl2OaKrp/TaN HYFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707822415; x=1708427215; 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=tMJ8zySMoyINs/H/ZtdncfabvDTmwRYnbN+UzyzCpqc=; b=sIAuTCail364OWJoR8IYzIuc/BBv9U79hJNZ1qaPoKHtibXvhdf8otJscPUe179S2S wKvttHzDIfKa/8Slk+DjU9Yf0NJuhVamnRk2+nzBW/LsGm+UVFbU7dzkIZY95+svj5iE nEHHtsOez4SmIM9LAj4i29n+nHRNd40uRMaAzpSzuOlXmKSL3Oq/tjz911Wbm9ax/Rbh lVBfq5lA2ew7ULrgpmLD2j4fayKmudi7eSjo4jsUiVrFfzH4vJqIJqWEo7hfSpHvgtdS enjBqN82/tObrLHr2H9G0f3mGlydRkseYb9AxUWw2J9LA9e7XkgN80Pmp0y4vF4FNV0O y86g== X-Forwarded-Encrypted: i=1; AJvYcCW42gTaNRe2w4Txmp6BTAFAfkcC+TU4Opg9GPqR/RWJZvjffNTS6r+COZpYjDTopkihmW/cH+nTSIap6xM= X-Gm-Message-State: AOJu0Yz1Z+yxXvIF9j2tAztHO3pPpb9HPUWdSf5st9QtT7VTVXfacbu3 i9+BFfNllm3C6YoPLVczzS/DWcMwaHBpK0xgMz9Ci/yarkzXRtFl1SVVvXT+f5aSsb+0G+6Ufql w2WZiRj8kWWWs9ilAYgeAeUhIC1PltB3pqWio/g== X-Google-Smtp-Source: AGHT+IEMFzaK2kOhLa+Dj6wOfM9g/1Il6JuA83bqFa3KVSOgg7vOcbOh5EoKxIxfgcjEBQiEwiZXneUV8+RPHU6RPc0= X-Received: by 2002:a17:906:1194:b0:a3c:e8e0:3ef3 with SMTP id n20-20020a170906119400b00a3ce8e03ef3mr1785400eja.1.1707822415420; Tue, 13 Feb 2024 03:06:55 -0800 (PST) MIME-Version: 1.0 References: <20240207121641.22739-1-juraj.linkes@pantheon.tech> In-Reply-To: From: =?UTF-8?Q?Juraj_Linke=C5=A1?= Date: Tue, 13 Feb 2024 12:06:44 +0100 Message-ID: Subject: Re: [PATCH v1] dts: strip whitespaces from stdout and stderr To: Jeremy Spewock 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 Mon, Feb 12, 2024 at 5:49=E2=80=AFPM Jeremy Spewock wrote: > > 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/frame= work/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. > It's a method defined by the dataclasses module so I guess I didn't feel the need to include the typehints because of that. No harm in adding them though, I'll send a new version. > > + """Strip the whitespaces from stdout and stderr. > > + > > + The generated __init__ method uses object.__setattr__() when t= he 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 prop= er 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 > >