mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
fix and enable systemd system tests
The systemd unit test never ran in CI and was broken for various reasons. Fix the test to execute Podman in systemd units and to also run generated units files. Note: more tests will be added in the future. The simple check for now will prevent regressions. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
@ -1,48 +0,0 @@
|
|||||||
#!/usr/bin/env bats -*- bats -*-
|
|
||||||
#
|
|
||||||
# Tests generated configurations for systemd.
|
|
||||||
#
|
|
||||||
|
|
||||||
load helpers
|
|
||||||
|
|
||||||
# Be extra paranoid in naming to avoid collisions.
|
|
||||||
SERVICE_NAME="podman_test_$(random_string)"
|
|
||||||
UNIT_DIR="$HOME/.config/systemd/user"
|
|
||||||
UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service"
|
|
||||||
|
|
||||||
# FIXME: the must run as root (because of CI). It's also broken...
|
|
||||||
|
|
||||||
function setup() {
|
|
||||||
skip_if_not_systemd
|
|
||||||
skip_if_remote
|
|
||||||
|
|
||||||
basic_setup
|
|
||||||
|
|
||||||
if [ ! -d "$UNIT_DIR" ]; then
|
|
||||||
mkdir -p "$UNIT_DIR"
|
|
||||||
systemctl --user daemon-reload
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function teardown() {
|
|
||||||
rm -f "$UNIT_FILE"
|
|
||||||
systemctl --user stop "$SERVICE_NAME"
|
|
||||||
basic_teardown
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "podman generate - systemd - basic" {
|
|
||||||
run_podman create $IMAGE echo "I'm alive!"
|
|
||||||
cid="$output"
|
|
||||||
|
|
||||||
run_podman generate systemd $cid > "$UNIT_FILE"
|
|
||||||
|
|
||||||
run systemctl --user start "$SERVICE_NAME"
|
|
||||||
if [ $status -ne 0 ]; then
|
|
||||||
die "The systemd service $SERVICE_NAME did not start correctly, output: $output"
|
|
||||||
fi
|
|
||||||
|
|
||||||
run_podman logs $cid
|
|
||||||
is "$output" "I'm alive!" "Container output"
|
|
||||||
}
|
|
||||||
|
|
||||||
# vim: filetype=sh
|
|
49
test/system/250-systemd.bats
Normal file
49
test/system/250-systemd.bats
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env bats -*- bats -*-
|
||||||
|
#
|
||||||
|
# Tests generated configurations for systemd.
|
||||||
|
#
|
||||||
|
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
SERVICE_NAME="podman_test_$(random_string)"
|
||||||
|
UNIT_DIR="/usr/lib/systemd/system"
|
||||||
|
UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service"
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
skip_if_remote
|
||||||
|
skip_if_rootless "systemd tests are root-only for now"
|
||||||
|
|
||||||
|
basic_setup
|
||||||
|
}
|
||||||
|
|
||||||
|
function teardown() {
|
||||||
|
rm -f "$UNIT_FILE"
|
||||||
|
systemctl daemon-reload
|
||||||
|
basic_teardown
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "podman generate - systemd - basic" {
|
||||||
|
run_podman create --name keepme --detach busybox:latest top
|
||||||
|
|
||||||
|
run_podman generate systemd --new keepme > "$UNIT_FILE"
|
||||||
|
run_podman rm keepme
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
run systemctl start "$SERVICE_NAME"
|
||||||
|
if [ $status -ne 0 ]; then
|
||||||
|
die "Error starting systemd unit $SERVICE_NAME, output: $output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
run systemctl status "$SERVICE_NAME"
|
||||||
|
if [ $status -ne 0 ]; then
|
||||||
|
die "Non-zero status of systemd unit $SERVICE_NAME, output: $output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
run systemctl stop "$SERVICE_NAME"
|
||||||
|
if [ $status -ne 0 ]; then
|
||||||
|
die "Error stopping systemd unit $SERVICE_NAME, output: $output"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim: filetype=sh
|
@ -252,17 +252,6 @@ function skip_if_remote() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#########################
|
|
||||||
# skip_if_not_systemd # ...with an optional message
|
|
||||||
#########################
|
|
||||||
function skip_if_not_systemd() {
|
|
||||||
if systemctl --user >/dev/null 2>&1; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
skip "${1:-no systemd or daemon does not respond}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#########
|
#########
|
||||||
# die # Abort with helpful message
|
# die # Abort with helpful message
|
||||||
#########
|
#########
|
||||||
|
Reference in New Issue
Block a user