DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v2] dts: strip whitespaces from stdout and stderr
@ 2024-02-13 11:14 Juraj Linkeš
  2024-02-13 16:14 ` Jeremy Spewock
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Juraj Linkeš @ 2024-02-13 11:14 UTC (permalink / raw)
  To: thomas, Honnappa.Nagarahalli, jspewock, probb, paul.szczepanek,
	Luca.Vizzarro
  Cc: dev, Juraj Linkeš

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dts: strip whitespaces from stdout and stderr
  2024-02-13 11:14 [PATCH v2] dts: strip whitespaces from stdout and stderr Juraj Linkeš
@ 2024-02-13 16:14 ` Jeremy Spewock
  2024-02-28 14:50 ` Patrick Robb
  2024-03-07  9:31 ` Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Jeremy Spewock @ 2024-02-13 16:14 UTC (permalink / raw)
  To: Juraj Linkeš
  Cc: thomas, Honnappa.Nagarahalli, probb, paul.szczepanek, Luca.Vizzarro, dev

Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dts: strip whitespaces from stdout and stderr
  2024-02-13 11:14 [PATCH v2] dts: strip whitespaces from stdout and stderr Juraj Linkeš
  2024-02-13 16:14 ` Jeremy Spewock
@ 2024-02-28 14:50 ` Patrick Robb
  2024-03-07  9:31 ` Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Patrick Robb @ 2024-02-28 14:50 UTC (permalink / raw)
  To: Juraj Linkeš
  Cc: thomas, Honnappa.Nagarahalli, jspewock, paul.szczepanek,
	Luca.Vizzarro, dev

[-- Attachment #1: Type: text/plain, Size: 43 bytes --]

Acked-by: Patrick Robb <probb@iol.unh.edu>

[-- Attachment #2: Type: text/html, Size: 109 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] dts: strip whitespaces from stdout and stderr
  2024-02-13 11:14 [PATCH v2] dts: strip whitespaces from stdout and stderr Juraj Linkeš
  2024-02-13 16:14 ` Jeremy Spewock
  2024-02-28 14:50 ` Patrick Robb
@ 2024-03-07  9:31 ` Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2024-03-07  9:31 UTC (permalink / raw)
  To: Juraj Linkeš
  Cc: Honnappa.Nagarahalli, jspewock, probb, paul.szczepanek,
	Luca.Vizzarro, dev

13/02/2024 12:14, Juraj Linkeš:
> 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>
Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>
Acked-by: Patrick Robb <probb@iol.unh.edu>

Applied, thanks.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-07  9:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 11:14 [PATCH v2] dts: strip whitespaces from stdout and stderr Juraj Linkeš
2024-02-13 16:14 ` Jeremy Spewock
2024-02-28 14:50 ` Patrick Robb
2024-03-07  9:31 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).