diff options
author | Ed Santiago <santiago@redhat.com> | 2021-07-20 08:24:37 -0600 |
---|---|---|
committer | Ed Santiago <santiago@redhat.com> | 2021-07-20 08:57:26 -0600 |
commit | 313c7118eadca28ff6f0121f43f56687b36d3849 (patch) | |
tree | 71de7e9499b5ec32f7a911450c1c293804c7e723 /test/system/255-auto-update.bats | |
parent | 4fb4614cf14a362c047b17612488fbdc0dc8e253 (diff) | |
download | podman-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/255-auto-update.bats')
-rw-r--r-- | test/system/255-auto-update.bats | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/test/system/255-auto-update.bats b/test/system/255-auto-update.bats index 4d7a8e783..25eaba45b 100644 --- a/test/system/255-auto-update.bats +++ b/test/system/255-auto-update.bats @@ -4,21 +4,12 @@ # load helpers +load helpers.systemd -DASHUSER="" -UNIT_DIR="/run/systemd/system" SNAME_FILE=$BATS_TMPDIR/services function setup() { skip_if_remote "systemd tests are meaningless over remote" - - if is_rootless; then - test -n "${XDG_RUNTIME_DIR}" || skip "\$XDG_RUNTIME_DIR is unset" - UNIT_DIR="${XDG_RUNTIME_DIR}/systemd/user" - mkdir -p $UNIT_DIR - # Why isn't systemd smart enough to figure this out on its own? - DASHUSER="--user" - fi basic_setup } @@ -26,10 +17,10 @@ function teardown() { while read line; do if [[ "$line" =~ "podman-auto-update" ]]; then echo "Stop timer: $line.timer" - systemctl $DASHUSER stop $line.timer - systemctl $DASHUSER disable $line.timer + systemctl stop $line.timer + systemctl disable $line.timer else - systemctl $DASHUSER stop $line + systemctl stop $line fi rm -f $UNIT_DIR/$line.{service,timer} done < $SNAME_FILE @@ -69,9 +60,9 @@ function generate_service() { echo "container-$cname" >> $SNAME_FILE run_podman rm -f $cname - systemctl $DASHUSER daemon-reload - systemctl $DASHUSER start container-$cname - systemctl $DASHUSER status container-$cname + systemctl daemon-reload + systemctl start container-$cname + systemctl status container-$cname # Original image ID. # IMPORTANT: variable 'ori_image' is passed (out of scope) up to caller! @@ -84,7 +75,7 @@ function _wait_service_ready() { local timeout=6 while [[ $timeout -gt 1 ]]; do - if systemctl $DASHUSER -q is-active $sname; then + if systemctl -q is-active $sname; then return fi sleep 1 @@ -92,7 +83,7 @@ function _wait_service_ready() { done # Print serivce status as debug information before failed the case - systemctl $DASHUSER status $sname + systemctl status $sname die "Timed out waiting for $sname to start" } @@ -267,14 +258,14 @@ WantedBy=multi-user.target default.target EOF echo "podman-auto-update-$cname" >> $SNAME_FILE - systemctl $DASHUSER enable --now podman-auto-update-$cname.timer - systemctl $DASHUSER list-timers --all + systemctl enable --now podman-auto-update-$cname.timer + systemctl list-timers --all local expect='Finished Podman auto-update testing service' local failed_start=failed local count=0 while [ $count -lt 120 ]; do - run journalctl $DASHUSER -n 15 -u podman-auto-update-$cname.service + run journalctl -n 15 -u podman-auto-update-$cname.service if [[ "$output" =~ $expect ]]; then failed_start= break |