Skip to content

Commit 1e336a6

Browse files
jluebbeEmantor
authored andcommitted
sshdriver: reduce loglevel when running commands
This avoids potential SSH log messages from ending up in the command output, especially when using stderr_merge. Signed-off-by: Jan Luebbe <[email protected]> Signed-off-by: Rouven Czerwinski <[email protected]>
1 parent 6720c2f commit 1e336a6

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

doc/configuration.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1575,10 +1575,10 @@ Arguments:
15751575
explicitly use the SFTP protocol for file transfers instead of scp's default protocol
15761576
- su_username(str, default="root"): only used if su_password is set
15771577
- su_prompt(str, default="Passowrd:"): prompt string for su
1578-
- su_password(str, default=None): su password for the user set via su_username
1578+
- su_password(str): optional, su password for the user set via su_username
15791579

15801580
.. note::
1581-
Using the su support will automatically enable stderr_merge, since ssh this
1581+
Using the su support will automatically enable ``stderr_merge``, since ssh this
15821582
is required to interact with the password prompt.
15831583

15841584
UBootDriver

labgrid/driver/sshdriver.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def handle_password(self, fd, stdin, marker):
206206
# no password needed
207207
return p.after
208208

209-
stdin.write(f"{self.su_password}".encode("utf-8"))
209+
stdin.write(self.su_password.encode("utf-8"))
210210
# It seems we need to close stdin here to reliably get su to accept the
211211
# password. \n doesn't seem to work.
212212
stdin.close()
@@ -233,7 +233,7 @@ def _run(self, cmd, codec="utf-8", decodeerrors="strict", timeout=None):
233233
if not self._check_keepalive():
234234
raise ExecutionError("Keepalive no longer running")
235235

236-
complete_cmd = ["ssh", "-x", *self.ssh_prefix,
236+
complete_cmd = ["ssh", "-x", "-o", "LogLevel=QUIET", *self.ssh_prefix,
237237
"-p", str(self.networkservice.port), "-l", self.networkservice.username,
238238
self.networkservice.address
239239
]
@@ -263,14 +263,11 @@ def _run(self, cmd, codec="utf-8", decodeerrors="strict", timeout=None):
263263
)
264264

265265
if self.su_password:
266-
fd = sub.stdout if self.stderr_merge else sub.stderr
266+
fd = sub.stdout
267267
output = self.handle_password(fd, sub.stdin, marker)
268268
sub.stdin.close()
269-
self.logger.debug(f"su leftover output: %s", output)
270-
if self.stderr_merge:
271-
stderr += output
272-
else:
273-
stdout += output
269+
self.logger.debug("su leftover output: %s", output)
270+
stderr += output
274271

275272
sub.stdin = None # never try to write to stdin here
276273
comout, comerr = sub.communicate(timeout=timeout)

0 commit comments

Comments
 (0)