Skip to content

Commit

Permalink
sshdriver: Log keepalive output
Browse files Browse the repository at this point in the history
While it is not normally expected for the keepalive process to produce
any output, it can be helpful for debugging purposes to log any output
it may have produced. As such, try harder to get output when terminating
the process, and also report any output after it exits

Signed-off-by: Joshua Watt <[email protected]>
  • Loading branch information
JoshuaWatt committed Sep 7, 2023
1 parent 2dcc631 commit 2fda584
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,35 @@ def _check_keepalive(self):
return self._keepalive.poll() is None

def _stop_keepalive(self):
def log_output(name, output):
if not output:
return

s = output.decode("utf-8", errors="ignore")
for line in s.splitlines():
self.logger.warning("Keepalive %s %s: %s", self.networkservice.address, name, line)

assert self._keepalive is not None

self.logger.debug('Stopping keepalive for %s', self.networkservice.address)

stdout = None
stderr = None

try:
self._keepalive.communicate(timeout=60)
stdout, stderr = self._keepalive.communicate(timeout=60)
except subprocess.TimeoutExpired:
self._keepalive.kill()

try:
self._keepalive.wait(timeout=60)
try:
# Try again to get output
stdout, stderr = self._keepalive.communicate(timeout=60)
except subprocess.TimeoutExpired:
try:
self._keepalive.wait(timeout=60)
except subprocess.TimeoutExpired:
self.logger.warning("ssh keepalive for %s timed out during termination", self.networkservice.address)
finally:
self._keepalive = None

log_output("stdout", stdout)
log_output("stderr", stderr)

0 comments on commit 2fda584

Please sign in to comment.