set -xeuo pipefail
. "$KOLA_EXT_DATA/commonlib.sh"
toolbox_create() {
run_as_core_user /bin/toolbox create --assumeyes
}
toolbox_run_basic() {
run_as_core_user /bin/toolbox run touch ok_toolbox
}
toolbox_list() {
run_as_core_user /bin/toolbox list --containers
}
toolbox_count() {
toolbox_list | grep --count -E "(fedora|rhel)-toolbox-" || true
}
toolbox_rm() {
toolbox="$(toolbox_list | awk '/(fedora|rhel)-toolbox-/ {print $2}')"
run_as_core_user /bin/toolbox rm -f "${toolbox}"
}
if file /bin/toolbox | grep -q "shell script"; then
echo "Using toolbox script <https://github.com/coreos/toolbox>"
rhel_major_version=$(get_rhel_maj_ver)
cat << EOF > /var/home/core/.toolboxrc
REGISTRY=registry.access.redhat.com
IMAGE=ubi${rhel_major_version}/toolbox:latest
TOOLBOX_NAME=rhel-toolbox-latest
AUTHFILE=/var/home/core/config.json
EOF
echo '{}' > /var/home/core/config.json
toolbox_create() {
run_as_core_user /bin/toolbox true
}
toolbox_run_basic() {
run_as_core_user /bin/toolbox touch /host/home/core/ok_toolbox
}
toolbox_list() {
/bin/podman ps -a
}
toolbox_rm() {
toolbox="$(toolbox_list | awk '/(fedora|rhel)-toolbox-/ {print $1}')"
/bin/podman rm -f "${toolbox}"
}
elif is_rhcos; then
rhel_major_version=$(get_rhel_maj_ver)
cat << EOF > /etc/containers/toolbox.conf
[general]
image = "registry.access.redhat.com/ubi${rhel_major_version}/toolbox:latest"
EOF
fi
for i in {1..5}; do
toolbox_create || true
if [[ $(toolbox_count) -eq 1 ]]; then
break
fi
if [[ $i -eq 5 ]]; then
fatal "Could not create toolbox after 5 attempts"
fi
echo "Could not create toolbox on try: $i"
sleep 10
done
ok toolbox create
toolbox_run_basic
if [[ ! -f '/home/core/ok_toolbox' ]]; then
fatal "Could not run a simple command inside a toolbox"
fi
ok toolbox run
toolbox_rm
if [[ $(toolbox_count) -ne 0 ]]; then
fatal "Could not remove the toolbox container"
fi
ok toolbox rm