Skip to content

Commit

Permalink
tests/lib/reset: try to identify unexpected snap units still present …
Browse files Browse the repository at this point in the history
…after purge

The reset code runs purge, but give how purge works, it may happen that there
are unexpected snap units. Specifically, lxd tends to start
snap.lxd.workaround.service unit directly through systemd-run, which is not
known to snapd and thus will not be stopped during purge.

This should fix the following issue in tests/main/postrm-purge:

```
 + systemctl --plain --no-legend --full
+ grep -E 'snap\..*\.(service|timer|socket)'
snap.lxd.workaround.service                                                                  loaded active exited    /bin/true
+ echo 'found unexpected leftovers'
found unexpected leftovers
+ exit 1
```

Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo committed Apr 3, 2024
1 parent 1d280d9 commit eede787
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/lib/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ reset_classic() {
;;
esac

local unexpected_units=0
for unit in $(systemctl --plain --no-legend --full | awk '/^ *snap\..*\.service +loaded/ {print $1}'); do
case "$unit" in
snap.lxd.workaround.service)
systemctl stop "$unit" || true
;;
*)
echo "unexpected unit $unit"
unexpected_units=1
;;
esac
done
if [ "$unexpected_units" != "0" ]; then
echo "error: found unexpected systemd units after purge"
exit 1
fi

# purge may have removed udev rules, retrigger device events
udevadm trigger
udevadm settle
Expand Down

0 comments on commit eede787

Please sign in to comment.