From 419bbba8021f42b4abb1e6e268bcdc3bab8bf944 Mon Sep 17 00:00:00 2001 From: Dalibor Kricka Date: Wed, 6 Aug 2025 08:58:10 +0200 Subject: [PATCH] cmd/run: --deprecation message when using 0.0.96 and older Toolbx container + tests https://github.com/containers/toolbox/issues/1684 --- src/cmd/run.go | 3 ++ test/system/104-run.bats | 33 ++++++++++++++ test/system/libs/helpers.bash | 83 +++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/src/cmd/run.go b/src/cmd/run.go index 389ea1615..86a7b0468 100644 --- a/src/cmd/run.go +++ b/src/cmd/run.go @@ -529,6 +529,9 @@ func callFlatpakSessionHelper(container podman.Container) error { return nil } + fmt.Fprintf(os.Stderr, "Warning: container %s uses deprecated features\n", container.Name()) + fmt.Fprintf(os.Stderr, "Consider recreating it with Toolbox version 0.0.97 or newer.\n") + if _, err := utils.CallFlatpakSessionHelper(); err != nil { return err } diff --git a/test/system/104-run.bats b/test/system/104-run.bats index d667aa917..580e7c029 100644 --- a/test/system/104-run.bats +++ b/test/system/104-run.bats @@ -857,3 +857,36 @@ teardown() { assert_line --index 1 "Recreate it with Toolbx version 0.0.17 or newer." assert [ ${#stderr_lines[@]} -eq 2 ] } + +@test "run: Ensure that label 'com.github.containers.toolbox=true' is present in toolbx container" { + local container_name="toolbox-container" + + create_container "$container_name" + + run podman inspect --format '{{ index .Config.Labels "com.github.containers.toolbox" }}' "$container_name" + + assert_success + assert_output --regexp "true" + + run "$TOOLBX" run --container "$container_name" true + assert [ ${#lines[@]} -eq 0 ] + assert_success +} + +@test "run: Ensure that the warning message appears when using deprecated container (created before version 0.0.97)" { + local container_name="toolbox-container-deprecated" + + create_container_flatpak_dbus "$container_name" + + in_container_command="true" + + run --keep-empty-lines --separate-stderr "$TOOLBX" run --container "$container_name" "$in_container_command" + + assert [ ${#lines[@]} -eq 0 ] + lines=("${stderr_lines[@]}") + assert_line --index 0 "Warning: container $container_name uses deprecated features" + assert_line --index 1 "Consider recreating it with Toolbox version 0.0.97 or newer." + + assert [ "$status" -eq 0 ] + assert [ ${#stderr_lines[@]} -eq 2 ] +} diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index 33b42eaf6..4436d4706 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -577,3 +577,86 @@ function is_fedora_rawhide() ( return 0 ) + + +# Creates a container with org.freedesktop.Flatpak.SessionHelper D-Bus interface +# +# Pulling of an image is taken care of by the function +# +# Parameters: +# =========== +# - container_name - name of the container +function create_container_flatpak_dbus() ( + local container_name + + container_name="$1" + + flatpak_helper_monitor_path=$(get_flatpak_helper_monitor_path) \ + || fail "Error getting Flatpak Helper monitor path" + + home_dir_evaled=$(get_home_dir_evaled_path) \ + || fail "Error getting Home directory evaled path" + + pull_default_image + distro="$(get_system_id)" + version="$(get_system_version)" + image_full="${IMAGES[$distro]}:$version" + + podman_cmd=( + podman create \ + --dns none \ + --env TOOLBOX_PATH="$TOOLBX" \ + --name "$container_name" \ + --network host \ + --no-hosts \ + --pid host \ + --privileged \ + --userns=keep-id \ + --user root:root \ + --volume /etc:/run/host/etc \ + --volume "$flatpak_helper_monitor_path":/run/host/monitor \ + --volume "$home_dir_evaled":"$home_dir_evaled":rslave \ + --volume "$TOOLBX":/usr/bin/toolbox \ + --volume /usr:/run/host/usr:rslave \ + --volume "$XDG_RUNTIME_DIR":"$XDG_RUNTIME_DIR" \ + "$image_full" \ + toolbox init-container \ + --home "$HOME" \ + --shell "$SHELL" \ + --uid "$(id -ru)" \ + --user "$USER" + ) + + # Print the full command + # printf "%q " "${podman_cmd[@]}" >> /tmp/toolbox_podman_command.log + + "${podman_cmd[@]}" || fail "Podman couldn't create container '$container_name'" +) + + +#Returns the D-Bus object path to the Flatpak session helper monitor +get_flatpak_helper_monitor_path(){ + if ! output=$(gdbus call \ + --session \ + --dest org.freedesktop.Flatpak \ + --object-path /org/freedesktop/Flatpak/SessionHelper \ + --method org.freedesktop.Flatpak.SessionHelper.RequestSession); then + echo "failed to call org.freedesktop.Flatpak.SessionHelper.RequestSession" >&2 + return 1 + fi + + echo "$output" | grep -o "/.*/monitor" + return 0 +} + + +#Returns the fully-resolved (symlink-free) absolute path of the user's home directory +get_home_dir_evaled_path(){ + if ! home_dir_evaled_path=$(readlink -f "$HOME" 2>/dev/null); then + echo "failed to resolve symlinks of $HOME directory." >&2 + return 1 + fi + + echo "$home_dir_evaled_path" + return 0 +}