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 20, 2023
1 parent 342dc90 commit d08a35c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ def _start_keepalive(self):
args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
)

self.logger.debug('Started keepalive for %s', self.networkservice.address)
Expand All @@ -540,12 +541,19 @@ def _stop_keepalive(self):

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

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

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

if stdout:
for line in stdout.splitlines():
self.logger.warning("Keepalive %s: %s", self.networkservice.address, line)

0 comments on commit d08a35c

Please sign in to comment.