mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

Record the user-specified "raw" image name in the SpecGenerator, so we can pass it along to the config when creating a container. We need a separate field as the image name in the generator may be set to the ID of the previously pulled image - ultimately the cause of #7404. Reverting the image name from the ID to the user input would not work since "alpine" for pulling iterates over the search registries in the registries.conf but looking up "alpine" normalizes to "localhost/alpine". Recording the raw-image name directly in the generator was the best of the options I considered as no hidden magic from search registries or normalizations (that may or may not change in the future) can interfere. The auto-update backend enforces that the raw-image name is a fully-qualified reference, so we need to worry about that in the front end. Fixes: #7407 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
85 lines
2.3 KiB
Bash
85 lines
2.3 KiB
Bash
#!/usr/bin/env bats -*- bats -*-
|
|
#
|
|
# Tests generated configurations for systemd.
|
|
#
|
|
|
|
load helpers
|
|
|
|
SERVICE_NAME="podman_test_$(random_string)"
|
|
|
|
SYSTEMCTL="systemctl"
|
|
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"
|
|
|
|
function setup() {
|
|
skip_if_remote "systemd tests are meaningless over remote"
|
|
|
|
basic_setup
|
|
}
|
|
|
|
function teardown() {
|
|
run '?' $SYSTEMCTL stop "$SERVICE_NAME"
|
|
rm -f "$UNIT_FILE"
|
|
$SYSTEMCTL daemon-reload
|
|
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" {
|
|
# podman initializes this if unset, but systemctl doesn't
|
|
if is_rootless; then
|
|
if [ -z "$XDG_RUNTIME_DIR" ]; then
|
|
export XDG_RUNTIME_DIR=/run/user/$(id -u)
|
|
fi
|
|
fi
|
|
|
|
cname=$(random_string)
|
|
# See #7407 for --pull=always.
|
|
run_podman create --pull=always --name $cname --label "io.containers.autoupdate=image" --detach $IMAGE top
|
|
|
|
run_podman generate systemd --new $cname
|
|
echo "$output" > "$UNIT_FILE"
|
|
run_podman rm $cname
|
|
|
|
$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
|
|
|
|
# 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"
|
|
|
|
# Exercise `podman auto-update`.
|
|
# TODO: this will at least run auto-update code but won't perform an update
|
|
# since the image didn't change. We need to improve on that and run
|
|
# an image from a local registry instead.
|
|
run_podman auto-update
|
|
|
|
# All good. Stop service, clean up.
|
|
run $SYSTEMCTL stop "$SERVICE_NAME"
|
|
if [ $status -ne 0 ]; then
|
|
die "Error stopping systemd unit $SERVICE_NAME, output: $output"
|
|
fi
|
|
|
|
rm -f "$UNIT_FILE"
|
|
$SYSTEMCTL daemon-reload
|
|
}
|
|
|
|
# vim: filetype=sh
|