system test: auto-update: allow running as rootless

They were being skipped for no clear reason.

Also: use --files and --name option in generate-systemd. Before,
output went to stdout, resulting in completely unreadable logs
on test failure.

Also: use volatile systemd directories (/run, $XDG_RUNTIME_DIR)
instead of permanent ones. Thanks to @Luap99 for the reference.

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago
2021-07-19 13:22:25 -06:00
parent f4e81d0b88
commit caf03fd7a4

View File

@ -5,13 +5,20 @@
load helpers load helpers
UNIT_DIR="/usr/lib/systemd/system" DASHUSER=""
UNIT_DIR="/run/systemd/system"
SNAME_FILE=$BATS_TMPDIR/services SNAME_FILE=$BATS_TMPDIR/services
function setup() { function setup() {
skip_if_remote "systemd tests are meaningless over remote" skip_if_remote "systemd tests are meaningless over remote"
skip_if_rootless
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 basic_setup
} }
@ -19,10 +26,10 @@ function teardown() {
while read line; do while read line; do
if [[ "$line" =~ "podman-auto-update" ]]; then if [[ "$line" =~ "podman-auto-update" ]]; then
echo "Stop timer: $line.timer" echo "Stop timer: $line.timer"
systemctl stop $line.timer systemctl $DASHUSER stop $line.timer
systemctl disable $line.timer systemctl $DASHUSER disable $line.timer
else else
systemctl stop $line systemctl $DASHUSER stop $line
fi fi
rm -f $UNIT_DIR/$line.{service,timer} rm -f $UNIT_DIR/$line.{service,timer}
done < $SNAME_FILE done < $SNAME_FILE
@ -58,14 +65,13 @@ function generate_service() {
fi fi
run_podman run -d --name $cname $label $target_img top -d 120 run_podman run -d --name $cname $label $target_img top -d 120
run_podman generate systemd --new $cname (cd $UNIT_DIR; run_podman generate systemd --new --files --name $cname)
echo "$output" > "$UNIT_DIR/container-$cname.service"
echo "container-$cname" >> $SNAME_FILE echo "container-$cname" >> $SNAME_FILE
run_podman rm -f $cname run_podman rm -f $cname
systemctl daemon-reload systemctl $DASHUSER daemon-reload
systemctl start container-$cname systemctl $DASHUSER start container-$cname
systemctl status container-$cname systemctl $DASHUSER status container-$cname
# Original image ID. # Original image ID.
# IMPORTANT: variable 'ori_image' is passed (out of scope) up to caller! # IMPORTANT: variable 'ori_image' is passed (out of scope) up to caller!
@ -78,7 +84,7 @@ function _wait_service_ready() {
local timeout=6 local timeout=6
while [[ $timeout -gt 1 ]]; do while [[ $timeout -gt 1 ]]; do
if systemctl -q is-active $sname; then if systemctl $DASHUSER -q is-active $sname; then
return return
fi fi
sleep 1 sleep 1
@ -86,7 +92,7 @@ function _wait_service_ready() {
done done
# Print serivce status as debug information before failed the case # Print serivce status as debug information before failed the case
systemctl status $sname systemctl $DASHUSER status $sname
die "Timed out waiting for $sname to start" die "Timed out waiting for $sname to start"
} }
@ -261,14 +267,14 @@ WantedBy=multi-user.target default.target
EOF EOF
echo "podman-auto-update-$cname" >> $SNAME_FILE echo "podman-auto-update-$cname" >> $SNAME_FILE
systemctl enable --now podman-auto-update-$cname.timer systemctl $DASHUSER enable --now podman-auto-update-$cname.timer
systemctl list-timers --all systemctl $DASHUSER list-timers --all
local expect='Finished Podman auto-update testing service' local expect='Finished Podman auto-update testing service'
local failed_start=failed local failed_start=failed
local count=0 local count=0
while [ $count -lt 120 ]; do while [ $count -lt 120 ]; do
run journalctl -n 15 -u podman-auto-update-$cname.service run journalctl $DASHUSER -n 15 -u podman-auto-update-$cname.service
if [[ "$output" =~ $expect ]]; then if [[ "$output" =~ $expect ]]; then
failed_start= failed_start=
break break