summaryrefslogtreecommitdiff
path: root/test/system/helpers.systemd.bash
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2021-07-20 08:24:37 -0600
committerEd Santiago <santiago@redhat.com>2021-07-20 08:57:26 -0600
commit313c7118eadca28ff6f0121f43f56687b36d3849 (patch)
tree71de7e9499b5ec32f7a911450c1c293804c7e723 /test/system/helpers.systemd.bash
parent4fb4614cf14a362c047b17612488fbdc0dc8e253 (diff)
downloadpodman-313c7118eadca28ff6f0121f43f56687b36d3849.tar.gz
podman-313c7118eadca28ff6f0121f43f56687b36d3849.tar.bz2
podman-313c7118eadca28ff6f0121f43f56687b36d3849.zip
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 <santiago@redhat.com>
Diffstat (limited to 'test/system/helpers.systemd.bash')
-rw-r--r--test/system/helpers.systemd.bash30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/system/helpers.systemd.bash b/test/system/helpers.systemd.bash
new file mode 100644
index 000000000..4bde912a4
--- /dev/null
+++ b/test/system/helpers.systemd.bash
@@ -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 "$@"
+}