Skip to content

Deprecation message when using 0.0.96 and older Toolbx container + tests #1697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
33 changes: 33 additions & 0 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
83 changes: 83 additions & 0 deletions test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}