From 7450143c8643198abf62f474db7f1f48415cc6b2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 10 Mar 2026 13:31:53 +0100 Subject: [PATCH] fix a potential hang because "journalctl -f" never finishes by itself, and handles might stay open if we don't close them during test teardown. --- cmdeploy/src/cmdeploy/tests/plugin.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index e7d1cefd..8e8bf2d6 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -487,13 +487,16 @@ def cmfactory( @pytest.fixture def remote(sshdomain, pytestconfig): - return Remote(sshdomain, ssh_config=pytestconfig.getoption("ssh_config")) + r = Remote(sshdomain, ssh_config=pytestconfig.getoption("ssh_config")) + yield r + r.close() class Remote: def __init__(self, sshdomain, ssh_config=None): self.sshdomain = sshdomain self.ssh_config = ssh_config + self._procs = [] def iter_output(self, logcmd="", ready=None): getjournal = "journalctl -f" if not logcmd else logcmd @@ -509,12 +512,14 @@ class Remote: command.extend(["-F", self.ssh_config]) command.append(f"root@{self.sshdomain}") [command.append(arg) for arg in getjournal.split()] - self.popen = subprocess.Popen( + popen = subprocess.Popen( command, + stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, ) + self._procs.append(popen) while 1: - line = self.popen.stdout.readline() + line = popen.stdout.readline() res = line.decode().strip().lower() if not res: break @@ -523,6 +528,12 @@ class Remote: ready = None yield res + def close(self): + while self._procs: + proc = self._procs.pop() + proc.kill() + proc.wait() + @pytest.fixture def lp(request):