forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
system tests: cleaner, safer use of systemd
First and foremost: use ephemeral (/run, $XDG) directories for systemd unit files, so as not to vandalize a working system. Second, refactor common systemd-related functionality into a new helper file, loaded by the systemd-related tests. Shared functionality includes: * setting $XDG_RUNTIME_DIR if unset and rootless * setting $UNIT_DIR for use by tests * new systemctl() and journalctl() functions, which include "--user" when rootless (why can't systemd figure this out on its own?) Signed-off-by: Ed Santiago <[email protected]>
- Loading branch information
1 parent
4fb4614
commit 313c711
Showing
4 changed files
with
54 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- bash -*- | ||
# | ||
# BATS helpers for systemd-related functionality | ||
# | ||
|
||
# podman initializes this if unset, but systemctl doesn't | ||
if [ -z "$XDG_RUNTIME_DIR" ]; then | ||
if is_rootless; then | ||
export XDG_RUNTIME_DIR=/run/user/$(id -u) | ||
fi | ||
fi | ||
|
||
# For tests which write systemd unit files | ||
UNIT_DIR="/run/systemd/system" | ||
_DASHUSER= | ||
if is_rootless; then | ||
UNIT_DIR="${XDG_RUNTIME_DIR}/systemd/user" | ||
# Why isn't systemd smart enough to figure this out on its own? | ||
_DASHUSER="--user" | ||
fi | ||
|
||
mkdir -p $UNIT_DIR | ||
|
||
systemctl() { | ||
command systemctl $_DASHUSER "$@" | ||
} | ||
|
||
journalctl() { | ||
command journalctl $_DASHUSER "$@" | ||
} |