test/system: Make tests non-destructive

This allows to run the test suite without having to worry about blasting
the whole local state of Podman.

This is done by creating a configuration file with a custom path for the
storage of Podman and specifying the config file using an env var.

The used location for the temporary storage is located either under
XDG_CACHE_HOME and if the one is not defined, $HOME/.cache is used
instead. The data are namespaced. This follows the XDG Base Directory
Specification[0]. Other locations could be /tmp or /run but those
locations usually use tmpfs and that filesystem can not be used by
Podman[1] due to missing features in tmpfs.

https://github.com/containers/toolbox/pull/818

[0] https://specifications.freedesktop.org/basedir-spec/latest/index.html
[1] https://github.com/containers/podman/issues/10693#issuecomment-863007516
This commit is contained in:
Oliver Gutierrez 2021-06-22 18:29:07 +01:00 committed by Ondřej Míchal
parent 8a329752e0
commit 7a5f3ba2e2
13 changed files with 37 additions and 7 deletions

View File

@ -3,6 +3,8 @@
load 'libs/helpers'
@test "test suite: Setup" {
# Setup container storage paths
setup_containers_store
# Cache the default image for the system
_pull_and_cache_distro_image $(get_system_id) $(get_system_version) || die
# Cache all images that will be needed during the tests

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_containers
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_containers
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_all
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_containers
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_containers
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_containers
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_containers
}

View File

@ -6,6 +6,7 @@ load 'libs/helpers'
setup() {
check_xdg_runtime_dir
setup_containers_store
cleanup_all
}

View File

@ -4,4 +4,5 @@ load 'libs/helpers'
@test "test suite: Teardown" {
_clean_cached_images
_clean_temporary_storage
}

View File

@ -5,8 +5,8 @@ These tests are built with BATS (Bash Automated Testing System).
The tests are meant to ensure that Toolbox's functionality remains stable
throughout updates of both Toolbox and Podman/libpod.
**Warning**: The tests are not executed in an isolated environment. Running the
tests will clear all podman state (delete all containers, images, etc).
The tests are set up in a way that does not affect the host environment.
Running them won't remove any existing containers or images.
## Dependencies

Binary file not shown.

View File

@ -2,14 +2,19 @@
load 'libs/bats-support/load'
# Helpful globals
readonly TEMP_BASE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/toolbox"
readonly TEMP_STORAGE_DIR="${TEMP_BASE_DIR}/system-test-storage"
readonly IMAGE_CACHE_DIR="${BATS_RUN_TMPDIR}/image-cache"
readonly ROOTLESS_PODMAN_STORE_DIR="${TEMP_STORAGE_DIR}/storage"
readonly PODMAN_STORE_CONFIG_FILE="${TEMP_STORAGE_DIR}/store.conf"
# Podman and Toolbox commands to run
readonly PODMAN=${PODMAN:-podman}
readonly TOOLBOX=${TOOLBOX:-toolbox}
readonly SKOPEO=$(command -v skopeo)
# Helpful globals
readonly IMAGE_CACHE_DIR="${BATS_RUN_TMPDIR}/image-cache"
# Images
declare -Ag IMAGES=([busybox]="quay.io/toolbox_tests/busybox" \
[fedora]="registry.fedoraproject.org/fedora-toolbox" \
@ -26,6 +31,19 @@ function cleanup_containers() {
}
function _setup_containers_store() {
mkdir -p ${TEMP_STORAGE_DIR}
# Setup a storage config file for PODMAN
echo -e "[storage]\n driver = \"overlay\"\n rootless_storage_path = \"${ROOTLESS_PODMAN_STORE_DIR}\"\n" > ${PODMAN_STORE_CONFIG_FILE}
export CONTAINERS_STORAGE_CONF=${PODMAN_STORE_CONFIG_FILE}
}
function _clean_temporary_storage() {
rm -rf ${TEMP_STORAGE_DIR}
}
# Pulls an image using Podman and saves it to a image dir using Skopeo
#
# Parameters
@ -133,7 +151,8 @@ function pull_distro_image() {
return
fi
run $SKOPEO copy "dir:${IMAGE_CACHE_DIR}/${image_archive}" "containers-storage:${image}"
# https://github.com/containers/skopeo/issues/547 for the options for containers-storage
run $SKOPEO copy "dir:${IMAGE_CACHE_DIR}/${image_archive}" "containers-storage:[overlay@$ROOTLESS_PODMAN_STORE_DIR+$ROOTLESS_PODMAN_STORE_DIR]${image}"
if [ "$status" -ne 0 ]; then
echo "Failed to load image ${image} from cache ${IMAGE_CACHE_DIR}/${image_archive}"
assert_success