Skip to content

Commit

Permalink
sshdriver: reduce loglevel when running commands
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jluebbe authored and Emantor committed Aug 1, 2023
1 parent 6720c2f commit 1e336a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1575,10 +1575,10 @@ Arguments:
explicitly use the SFTP protocol for file transfers instead of scp's default protocol
- su_username(str, default="root"): only used if su_password is set
- su_prompt(str, default="Passowrd:"): prompt string for su
- su_password(str, default=None): su password for the user set via su_username
- su_password(str): optional, su password for the user set via su_username

.. note::
Using the su support will automatically enable stderr_merge, since ssh this
Using the su support will automatically enable ``stderr_merge``, since ssh this
is required to interact with the password prompt.

UBootDriver
Expand Down
13 changes: 5 additions & 8 deletions labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def handle_password(self, fd, stdin, marker):
# no password needed
return p.after

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

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

if self.su_password:
fd = sub.stdout if self.stderr_merge else sub.stderr
fd = sub.stdout
output = self.handle_password(fd, sub.stdin, marker)
sub.stdin.close()
self.logger.debug(f"su leftover output: %s", output)
if self.stderr_merge:
stderr += output
else:
stdout += output
self.logger.debug("su leftover output: %s", output)
stderr += output

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

0 comments on commit 1e336a6

Please sign in to comment.