mirror of
https://github.com/containers/podman.git
synced 2025-06-23 10:38:20 +08:00
Some BATS cleanup: run and systemd tests
run test: run positive test before negative; and actually implement real negative tests. Also, add confirmation tests for cidfile/pidfile, not just 'exit status is good'. systemd test: enable rootless, and again add actual content testing. Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
@ -161,17 +161,31 @@ echo $rand | 0 | $rand
|
|||||||
# 'run --conmon-pidfile --cid-file' makes sure we don't regress on these flags.
|
# 'run --conmon-pidfile --cid-file' makes sure we don't regress on these flags.
|
||||||
# Both are critical for systemd units.
|
# Both are critical for systemd units.
|
||||||
@test "podman run --conmon-pidfile --cidfile" {
|
@test "podman run --conmon-pidfile --cidfile" {
|
||||||
pid=$(mktemp)
|
pidfile=${PODMAN_TMPDIR}/pidfile
|
||||||
cid=$(mktemp)
|
cidfile=${PODMAN_TMPDIR}/cidfile
|
||||||
|
|
||||||
# CID file exists -> expected to fail.
|
cname=$(random_string)
|
||||||
run_podman 125 run --rm --conmon-pidfile=$pid --cidfile=$cid $IMAGE ls
|
run_podman run --name $cname \
|
||||||
|
--conmon-pidfile=$pidfile \
|
||||||
|
--cidfile=$cidfile \
|
||||||
|
--detach \
|
||||||
|
$IMAGE sleep infinity
|
||||||
|
cid="$output"
|
||||||
|
|
||||||
rm $pid $cid
|
is "$(< $cidfile)" "$cid" "contents of cidfile == container ID"
|
||||||
run_podman run --name keepme --conmon-pidfile=$pid --cidfile=$cid --detach $IMAGE sleep infinity
|
|
||||||
stat $pid $cid
|
conmon_pid=$(< $pidfile)
|
||||||
run_podman rm -f keepme
|
is "$(readlink /proc/$conmon_pid/exe)" ".*/conmon" \
|
||||||
rm $pid $cid
|
"conmon pidfile (= PID $conmon_pid) points to conmon process"
|
||||||
|
|
||||||
|
# All OK. Kill container.
|
||||||
|
run_podman rm -f $cid
|
||||||
|
|
||||||
|
# Podman must not overwrite existing cid file.
|
||||||
|
# (overwriting conmon-pidfile is OK, so don't test that)
|
||||||
|
run_podman 125 run --cidfile=$cidfile $IMAGE true
|
||||||
|
is "$output" "Error: container id file exists. .* delete $cidfile" \
|
||||||
|
"podman will not overwrite existing cidfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
@ -6,44 +6,65 @@
|
|||||||
load helpers
|
load helpers
|
||||||
|
|
||||||
SERVICE_NAME="podman_test_$(random_string)"
|
SERVICE_NAME="podman_test_$(random_string)"
|
||||||
|
|
||||||
|
SYSTEMCTL="systemctl"
|
||||||
UNIT_DIR="/usr/lib/systemd/system"
|
UNIT_DIR="/usr/lib/systemd/system"
|
||||||
|
if is_rootless; then
|
||||||
|
UNIT_DIR="$HOME/.config/systemd/user"
|
||||||
|
mkdir -p $UNIT_DIR
|
||||||
|
|
||||||
|
SYSTEMCTL="$SYSTEMCTL --user"
|
||||||
|
fi
|
||||||
UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service"
|
UNIT_FILE="$UNIT_DIR/$SERVICE_NAME.service"
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
skip_if_remote
|
skip_if_remote
|
||||||
skip_if_rootless "systemd tests are root-only for now"
|
|
||||||
|
|
||||||
basic_setup
|
basic_setup
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
|
run '?' $SYSTEMCTL stop "$SERVICE_NAME"
|
||||||
rm -f "$UNIT_FILE"
|
rm -f "$UNIT_FILE"
|
||||||
systemctl daemon-reload
|
$SYSTEMCTL daemon-reload
|
||||||
basic_teardown
|
basic_teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This test can fail in dev. environment because of SELinux.
|
||||||
|
# quick fix: chcon -t container_runtime_exec_t ./bin/podman
|
||||||
@test "podman generate - systemd - basic" {
|
@test "podman generate - systemd - basic" {
|
||||||
run_podman create --name keepme --detach busybox:latest top
|
cname=$(random_string)
|
||||||
|
run_podman create --name $cname --detach $IMAGE top
|
||||||
|
|
||||||
run_podman generate systemd --new keepme > "$UNIT_FILE"
|
run_podman generate systemd --new $cname
|
||||||
run_podman rm keepme
|
echo "$output" > "$UNIT_FILE"
|
||||||
|
run_podman rm $cname
|
||||||
|
|
||||||
systemctl daemon-reload
|
$SYSTEMCTL daemon-reload
|
||||||
|
|
||||||
run systemctl start "$SERVICE_NAME"
|
run $SYSTEMCTL start "$SERVICE_NAME"
|
||||||
if [ $status -ne 0 ]; then
|
if [ $status -ne 0 ]; then
|
||||||
die "Error starting systemd unit $SERVICE_NAME, output: $output"
|
die "Error starting systemd unit $SERVICE_NAME, output: $output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run systemctl status "$SERVICE_NAME"
|
run $SYSTEMCTL status "$SERVICE_NAME"
|
||||||
if [ $status -ne 0 ]; then
|
if [ $status -ne 0 ]; then
|
||||||
die "Non-zero status of systemd unit $SERVICE_NAME, output: $output"
|
die "Non-zero status of systemd unit $SERVICE_NAME, output: $output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run systemctl stop "$SERVICE_NAME"
|
# Give container time to start; make sure output looks top-like
|
||||||
|
sleep 2
|
||||||
|
run_podman logs $cname
|
||||||
|
is "$output" ".*Load average:.*" "running container 'top'-like output"
|
||||||
|
|
||||||
|
# All good. Stop service, clean up.
|
||||||
|
run $SYSTEMCTL stop "$SERVICE_NAME"
|
||||||
if [ $status -ne 0 ]; then
|
if [ $status -ne 0 ]; then
|
||||||
die "Error stopping systemd unit $SERVICE_NAME, output: $output"
|
die "Error stopping systemd unit $SERVICE_NAME, output: $output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$UNIT_FILE"
|
||||||
|
$SYSTEMCTL daemon-reload
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user