Skip to content

Commit

Permalink
test: Fix cleanup of lingering user systemd managers
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
martinpitt committed Feb 23, 2023
1 parent a4d8ab8 commit 1f1f9b3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1f1f9b3

Please sign in to comment.