From e7631d8d53e36e7ffbd1d8dc45f519c58e8da99e Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Tue, 19 Sep 2023 14:45:09 +0200 Subject: [PATCH] Retry creation of sandbox container (#276) * Extend sleep when Docker daemon seems ready * Pruning test shall not write to local fs * Make sure container names do not conflict --- test/pruning/docker-compose.yml | 2 +- test/pruning/run.sh | 12 +++++++----- test/test.sh | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/test/pruning/docker-compose.yml b/test/pruning/docker-compose.yml index c54a998..58adb02 100644 --- a/test/pruning/docker-compose.yml +++ b/test/pruning/docker-compose.yml @@ -35,7 +35,7 @@ services: volumes: - app_data:/backup/app_data:ro - /var/run/docker.sock:/var/run/docker.sock - - ./local:/archive + - ${LOCAL_DIR:-./local}:/archive offen: image: offen/offen:latest diff --git a/test/pruning/run.sh b/test/pruning/run.sh index bcff448..9e6aad7 100755 --- a/test/pruning/run.sh +++ b/test/pruning/run.sh @@ -9,7 +9,7 @@ cd "$(dirname "$0")" . ../util.sh current_test=$(basename $(pwd)) -mkdir -p local +export LOCAL_DIR=$(mktemp -d) docker compose up -d --quiet-pull sleep 5 @@ -20,7 +20,7 @@ sleep 5 expect_running_containers "3" -touch -r ./local/test-hostnametoken.tar.gz -d "14 days ago" ./local/test-hostnametoken-old.tar.gz +touch -r "$LOCAL_DIR/test-hostnametoken.tar.gz" -d "14 days ago" "$LOCAL_DIR/test-hostnametoken-old.tar.gz" docker run --rm \ -v minio_backup_data:/minio_data \ @@ -36,7 +36,9 @@ info "Create backup with no prune for s3 backend" docker compose exec backup backup info "Check if old backup has been pruned (local)" -test ! -f ./local/test-hostnametoken-old.tar.gz +if [ -f "$LOCAL_DIR/test-hostnametoken-old.tar.gz" ]; then + fail "Expired backup was not pruned from local storage." +fi info "Check if old backup has NOT been pruned (s3)" docker run --rm \ @@ -48,7 +50,7 @@ pass "Old remote backup has been pruned locally, skipped S3 backend is untouched # Skip local and s3 backend from prune (all backends) -touch -r ./local/test-hostnametoken.tar.gz -d "14 days ago" ./local/test-hostnametoken-old.tar.gz +touch -r "$LOCAL_DIR/test-hostnametoken.tar.gz" -d "14 days ago" "$LOCAL_DIR/test-hostnametoken-old.tar.gz" docker compose up -d sleep 5 @@ -57,7 +59,7 @@ info "Create backup with no prune for both backends" docker compose exec -e BACKUP_SKIP_BACKENDS_FROM_PRUNE="s3,local" backup backup info "Check if old backup has NOT been pruned (local)" -if [ ! -f ./local/test-hostnametoken-old.tar.gz ]; then +if [ ! -f "$LOCAL_DIR/test-hostnametoken-old.tar.gz" ]; then fail "Backdated file has not been deleted" fi diff --git a/test/test.sh b/test/test.sh index 40a8552..bd5de4a 100755 --- a/test/test.sh +++ b/test/test.sh @@ -49,16 +49,27 @@ for dir in $(find $find_args | sort); do if [ -z "$NO_IMAGE_CACHE" ]; then docker_run_args="$docker_run_args \ - -v "${sandbox}_image":/var/lib/docker/image \ - -v "${sandbox}_overlay2":/var/lib/docker/overlay2" + -v "${sandbox}_image":/var/lib/docker/image \ + -v "${sandbox}_overlay2":/var/lib/docker/overlay2" fi docker run $docker_run_args offen/docker-volume-backup:test-sandbox + retry_counter=0 until docker exec $sandbox /bin/sh -c 'docker info' > /dev/null 2>&1; do + if [ $retry_counter -gt 20 ]; then + echo "Gave up waiting for Docker daemon to become ready after 20 attempts" + exit 1 + fi + + if [ "$(docker inspect $sandbox --format '{{ .State.Running }}')" = "false" ]; then + docker rm $sandbox + docker run $docker_run_args offen/docker-volume-backup:test-sandbox + fi + sleep 0.5 + retry_counter=$((retry_counter+1)) done - sleep 0.5 docker exec $sandbox /bin/sh -c "docker load -i /cache/image.tar.gz" docker exec -e TEST_VERSION=$IMAGE_TAG $sandbox /bin/sh -c "/code/test/$test"