mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 08:56:05 +08:00 
			
		
		
		
	When a systemd-related system test fails, we usually get:
    systemctl start foo
    FAILED exit status 1, try 'systemctl --status' or 'journalctl -xe'
That makes it impossible to debug flakes.
Solution: new systemctl_start() [note underscore], to be used
instead of systemctl <SPACE> start. On failure, will run log
commands.
Signed-off-by: Ed Santiago <santiago@redhat.com>
		
	
		
			
				
	
	
		
			103 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
# -*- bash -*-
 | 
						|
#
 | 
						|
# BATS helpers for systemd-related functionality
 | 
						|
#
 | 
						|
 | 
						|
# podman initializes this if unset, but systemctl doesn't
 | 
						|
if [ -z "$XDG_RUNTIME_DIR" ]; then
 | 
						|
    if is_rootless; then
 | 
						|
        export XDG_RUNTIME_DIR=/run/user/$(id -u)
 | 
						|
    fi
 | 
						|
fi
 | 
						|
 | 
						|
# For tests which write systemd unit files
 | 
						|
UNIT_DIR="/run/systemd/system"
 | 
						|
_DASHUSER=
 | 
						|
if is_rootless; then
 | 
						|
    UNIT_DIR="${XDG_RUNTIME_DIR}/systemd/user"
 | 
						|
    # Why isn't systemd smart enough to figure this out on its own?
 | 
						|
    _DASHUSER="--user"
 | 
						|
fi
 | 
						|
 | 
						|
mkdir -p $UNIT_DIR
 | 
						|
 | 
						|
systemctl() {
 | 
						|
    timeout --foreground -v --kill=10 $PODMAN_TIMEOUT systemctl $_DASHUSER "$@"
 | 
						|
}
 | 
						|
 | 
						|
journalctl() {
 | 
						|
    timeout --foreground -v --kill=10 $PODMAN_TIMEOUT journalctl $_DASHUSER "$@"
 | 
						|
}
 | 
						|
 | 
						|
systemd-run() {
 | 
						|
    timeout --foreground -v --kill=10 $PODMAN_TIMEOUT systemd-run $_DASHUSER "$@";
 | 
						|
}
 | 
						|
 | 
						|
# "systemctl start" is special: when it fails, it doesn't give any useful info.
 | 
						|
# This helper fixes that.
 | 
						|
systemctl_start() {
 | 
						|
    # Arg processing. First arg might be "--wait"...
 | 
						|
    local wait=
 | 
						|
    if [[ "$1" = "--wait" ]]; then
 | 
						|
        wait="$1"
 | 
						|
        shift
 | 
						|
    fi
 | 
						|
    # ...but beyond that, only one arg is allowed
 | 
						|
    local unit="$1"
 | 
						|
    shift
 | 
						|
    assert "$*" = "" "systemctl_start invoked with spurious args"
 | 
						|
 | 
						|
    echo "$_LOG_PROMPT systemctl $wait start $unit"
 | 
						|
    run systemctl $wait start "$unit"
 | 
						|
    echo "$output"
 | 
						|
    if [[ $status -eq 0 ]]; then
 | 
						|
        return
 | 
						|
    fi
 | 
						|
 | 
						|
    # Failed. This is our value added.
 | 
						|
    echo
 | 
						|
    echo "***** systemctl start $unit -- FAILED!"
 | 
						|
    echo
 | 
						|
    echo "$_LOG_PROMPT systemctl status $unit"
 | 
						|
    run systemctl status "$unit"
 | 
						|
    echo "$output"
 | 
						|
    echo
 | 
						|
    echo "$_LOG_PROMPT journalctl -xeu $unit"
 | 
						|
    run journalctl -xeu "$unit"
 | 
						|
    echo "$output"
 | 
						|
    false
 | 
						|
}
 | 
						|
 | 
						|
install_kube_template() {
 | 
						|
    # If running from a podman source directory, build and use the source
 | 
						|
    # version of the play-kube-@ unit file
 | 
						|
    unit_name="podman-kube@.service"
 | 
						|
    unit_file="contrib/systemd/system/${unit_name}"
 | 
						|
    if [[ -e ${unit_file}.in ]]; then
 | 
						|
        echo "# [Building & using $unit_name from source]" >&3
 | 
						|
        # Force regenerating unit file (existing one may have /usr/bin path)
 | 
						|
        rm -f $unit_file
 | 
						|
        BINDIR=$(dirname $PODMAN) make $unit_file
 | 
						|
        cp $unit_file $UNIT_DIR/$unit_name
 | 
						|
    fi
 | 
						|
}
 | 
						|
 | 
						|
quadlet_to_service_name() {
 | 
						|
    local filename=$(basename -- "$1")
 | 
						|
    local extension="${filename##*.}"
 | 
						|
    local filename="${filename%.*}"
 | 
						|
    local suffix=""
 | 
						|
 | 
						|
    if [ "$extension" == "volume" ]; then
 | 
						|
        suffix="-volume"
 | 
						|
    elif [ "$extension" == "network" ]; then
 | 
						|
        suffix="-network"
 | 
						|
    elif [ "$extension" == "image" ]; then
 | 
						|
        suffix="-image"
 | 
						|
    elif [ "$extension" == "pod" ]; then
 | 
						|
        suffix="-pod"
 | 
						|
    fi
 | 
						|
 | 
						|
    echo "$filename$suffix.service"
 | 
						|
}
 |