From 1f1f9b3eff60e9d062c111595fb7f9be1884e691 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 23 Feb 2023 07:50:08 +0100 Subject: [PATCH] test: Fix cleanup of lingering user systemd managers Users who are not logged in are *not* showing up in `loginctl list-users`, unlike I originally assumed. To make sure that no "systemd" processes from users are left over (like `TestAccounts.testRootLogin` does), just stop *all* `user@*.service` after each test. This has the added benefit that it should always succeed (and if it doesn't, we really want to know). --- test/common/testlib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/common/testlib.py b/test/common/testlib.py index 18e066bd3b93..68ffbb41b485 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -1585,7 +1585,6 @@ def terminate_sessions(): # on OSTree we don't get "web console" sessions with the cockpit/ws container; just SSH; but also, some tests start # admin sessions without Cockpit self.machine.execute("""for u in $(loginctl --no-legend list-users | awk '{ if ($2 != "root") print $1 }'); do - systemctl stop user@$u.service 2>/dev/null || true loginctl terminate-user $u 2>/dev/null || true loginctl kill-user $u 2>/dev/null || true pkill -9 -u $u || true @@ -1613,6 +1612,9 @@ def terminate_sessions(): m.execute(f"loginctl session-status {s} >&2") raise + # terminate all systemd user services for users who are not logged in + self.machine.execute("systemctl stop user@*.service") + self.addCleanup(terminate_sessions) def tearDown(self):