diff options
author | Alexis Lothoré <alexis.lothore@bootlin.com> | 2024-07-05 16:46:37 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-07-08 09:17:09 +0100 |
commit | e98a6f6812d149250a683ddfa11f5d0df422c0f2 (patch) | |
tree | 239ef0b3899f7680a218f02d8aba56f8f8d9748a /meta | |
parent | 5d5297775a3db869409f5f945b2e8c93e4738e7c (diff) | |
download | poky-e98a6f6812d149250a683ddfa11f5d0df422c0f2.tar.gz |
oeqa/ssh: allow to retrieve raw, unformatted ouput
The ssh target is currently well tailored to easily retrieve textual output
from a command run on a remote target. It could also be used to retrieve
raw data from a command run onto a remote target (for example, to feed this
data directly to another program), but it currently suffers two minor
issues preventing such use case:
- stderr is piped to stdout, so any error log will be mixed in the program
output
- the final output is decoded as utf-8 and stripped
Allow to return the raw, unmodified output by adding an optional "raw"
parameter. Keep it to False by default to preserve the current behavior.
When enabled, do not return a string but the raw output as bytes.
(From OE-Core rev: 8d05dc6e2284b7ed7c32a8215b9c8bf6f7dabf00)
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/core/target/ssh.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/meta/lib/oeqa/core/target/ssh.py b/meta/lib/oeqa/core/target/ssh.py index 09cdd14c75..d473469384 100644 --- a/meta/lib/oeqa/core/target/ssh.py +++ b/meta/lib/oeqa/core/target/ssh.py | |||
@@ -55,14 +55,14 @@ class OESSHTarget(OETarget): | |||
55 | def stop(self, **kwargs): | 55 | def stop(self, **kwargs): |
56 | pass | 56 | pass |
57 | 57 | ||
58 | def _run(self, command, timeout=None, ignore_status=True): | 58 | def _run(self, command, timeout=None, ignore_status=True, raw=False): |
59 | """ | 59 | """ |
60 | Runs command in target using SSHProcess. | 60 | Runs command in target using SSHProcess. |
61 | """ | 61 | """ |
62 | self.logger.debug("[Running]$ %s" % " ".join(command)) | 62 | self.logger.debug("[Running]$ %s" % " ".join(command)) |
63 | 63 | ||
64 | starttime = time.time() | 64 | starttime = time.time() |
65 | status, output = SSHCall(command, self.logger, timeout) | 65 | status, output = SSHCall(command, self.logger, timeout, raw) |
66 | self.logger.debug("[Command returned '%d' after %.2f seconds]" | 66 | self.logger.debug("[Command returned '%d' after %.2f seconds]" |
67 | "" % (status, time.time() - starttime)) | 67 | "" % (status, time.time() - starttime)) |
68 | 68 | ||
@@ -72,7 +72,7 @@ class OESSHTarget(OETarget): | |||
72 | 72 | ||
73 | return (status, output) | 73 | return (status, output) |
74 | 74 | ||
75 | def run(self, command, timeout=None, ignore_status=True): | 75 | def run(self, command, timeout=None, ignore_status=True, raw=False): |
76 | """ | 76 | """ |
77 | Runs command in target. | 77 | Runs command in target. |
78 | 78 | ||
@@ -91,7 +91,7 @@ class OESSHTarget(OETarget): | |||
91 | else: | 91 | else: |
92 | processTimeout = self.timeout | 92 | processTimeout = self.timeout |
93 | 93 | ||
94 | status, output = self._run(sshCmd, processTimeout, ignore_status) | 94 | status, output = self._run(sshCmd, processTimeout, ignore_status, raw) |
95 | self.logger.debug('Command: %s\nStatus: %d Output: %s\n' % (command, status, output)) | 95 | self.logger.debug('Command: %s\nStatus: %d Output: %s\n' % (command, status, output)) |
96 | 96 | ||
97 | return (status, output) | 97 | return (status, output) |
@@ -206,7 +206,7 @@ class OESSHTarget(OETarget): | |||
206 | remoteDir = os.path.join(remotePath, tmpDir.lstrip("/")) | 206 | remoteDir = os.path.join(remotePath, tmpDir.lstrip("/")) |
207 | self.deleteDir(remoteDir) | 207 | self.deleteDir(remoteDir) |
208 | 208 | ||
209 | def SSHCall(command, logger, timeout=None, **opts): | 209 | def SSHCall(command, logger, timeout=None, raw=False, **opts): |
210 | 210 | ||
211 | def run(): | 211 | def run(): |
212 | nonlocal output | 212 | nonlocal output |
@@ -265,7 +265,7 @@ def SSHCall(command, logger, timeout=None, **opts): | |||
265 | else: | 265 | else: |
266 | output_raw = process.communicate()[0] | 266 | output_raw = process.communicate()[0] |
267 | 267 | ||
268 | output = output_raw.decode('utf-8', errors='ignore') | 268 | output = output_raw if raw else output_raw.decode('utf-8', errors='ignore') |
269 | logger.debug('Data from SSH call:\n%s' % output.rstrip()) | 269 | logger.debug('Data from SSH call:\n%s' % output.rstrip()) |
270 | 270 | ||
271 | # timout or not, make sure process exits and is not hanging | 271 | # timout or not, make sure process exits and is not hanging |
@@ -292,7 +292,7 @@ def SSHCall(command, logger, timeout=None, **opts): | |||
292 | 292 | ||
293 | options = { | 293 | options = { |
294 | "stdout": subprocess.PIPE, | 294 | "stdout": subprocess.PIPE, |
295 | "stderr": subprocess.STDOUT, | 295 | "stderr": subprocess.STDOUT if not raw else None, |
296 | "stdin": None, | 296 | "stdin": None, |
297 | "shell": False, | 297 | "shell": False, |
298 | "bufsize": -1, | 298 | "bufsize": -1, |
@@ -320,4 +320,4 @@ def SSHCall(command, logger, timeout=None, **opts): | |||
320 | logger.debug('Something went wrong, killing SSH process') | 320 | logger.debug('Something went wrong, killing SSH process') |
321 | raise | 321 | raise |
322 | 322 | ||
323 | return (process.returncode, output.rstrip()) | 323 | return (process.returncode, output if raw else output.rstrip()) |