2023-09-07 13:06:21 -05:00
|
|
|
# Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-dedupe-nightly"
|
|
|
|
# Makefile target installs & checks all necessary tooling
|
|
|
|
# Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites()
|
|
|
|
|
2023-04-07 11:49:24 -05:00
|
|
|
load helpers_cloud
|
2023-08-30 14:24:28 -05:00
|
|
|
load helpers_wait
|
2023-04-07 11:49:24 -05:00
|
|
|
|
|
|
|
function setup_file() {
|
|
|
|
# Verify prerequisites are available
|
2023-08-30 14:24:28 -05:00
|
|
|
if ! $(verify_prerequisites); then
|
2023-04-07 11:49:24 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Download test data to folder common for the entire suite, not just this file
|
2023-10-12 08:42:07 -05:00
|
|
|
skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TEST_DATA_DIR}/alpine:1
|
2023-04-07 11:49:24 -05:00
|
|
|
# Setup zot server
|
|
|
|
local zot_root_dir=${BATS_FILE_TMPDIR}/zot
|
|
|
|
local zot_config_file_dedupe=${BATS_FILE_TMPDIR}/zot_config_dedupe.json
|
|
|
|
local zot_config_file_nodedupe=${BATS_FILE_TMPDIR}/zot_config_nodedupe.json
|
2023-09-20 11:25:06 -05:00
|
|
|
local ZOT_LOG_FILE_DEDUPE=${BATS_FILE_TMPDIR}/zot-log-dedupe.json
|
|
|
|
local ZOT_LOG_FILE_NODEDUPE=${BATS_FILE_TMPDIR}/zot-log-nodedupe.json
|
|
|
|
|
2023-10-12 08:42:07 -05:00
|
|
|
touch ${ZOT_LOG_FILE_NODEDUPE}
|
2023-04-07 11:49:24 -05:00
|
|
|
mkdir -p ${zot_root_dir}
|
|
|
|
|
|
|
|
cat > ${zot_config_file_dedupe}<<EOF
|
|
|
|
{
|
2024-02-20 06:27:21 -05:00
|
|
|
"distSpecVersion": "1.1.0",
|
2023-09-20 11:25:06 -05:00
|
|
|
"storage": {
|
2023-04-07 11:49:24 -05:00
|
|
|
"rootDirectory": "${zot_root_dir}",
|
|
|
|
"dedupe": true,
|
|
|
|
"remoteCache": true,
|
|
|
|
"storageDriver": {
|
|
|
|
"name": "s3",
|
|
|
|
"rootdirectory": "/zot",
|
|
|
|
"region": "us-east-2",
|
|
|
|
"regionendpoint": "localhost:4566",
|
|
|
|
"bucket": "zot-storage",
|
|
|
|
"secure": false,
|
|
|
|
"skipverify": false
|
|
|
|
},
|
|
|
|
"cacheDriver": {
|
|
|
|
"name": "dynamodb",
|
|
|
|
"endpoint": "http://localhost:4566",
|
|
|
|
"region": "us-east-2",
|
|
|
|
"cacheTablename": "BlobTable"
|
|
|
|
}
|
2023-09-20 11:25:06 -05:00
|
|
|
},
|
|
|
|
"http": {
|
|
|
|
"address": "127.0.0.1",
|
|
|
|
"port": "8080"
|
|
|
|
},
|
|
|
|
"log": {
|
|
|
|
"level": "debug",
|
|
|
|
"output": "${ZOT_LOG_FILE_DEDUPE}"
|
|
|
|
}
|
2023-04-07 11:49:24 -05:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > ${zot_config_file_nodedupe}<<EOF
|
|
|
|
{
|
2024-02-20 06:27:21 -05:00
|
|
|
"distSpecVersion": "1.1.0",
|
2023-09-20 11:25:06 -05:00
|
|
|
"storage": {
|
2023-04-07 11:49:24 -05:00
|
|
|
"rootDirectory": "${zot_root_dir}",
|
|
|
|
"dedupe": false,
|
2023-10-12 08:42:07 -05:00
|
|
|
"gc": false,
|
2023-04-07 11:49:24 -05:00
|
|
|
"storageDriver": {
|
|
|
|
"name": "s3",
|
|
|
|
"rootdirectory": "/zot",
|
|
|
|
"region": "us-east-2",
|
|
|
|
"regionendpoint": "localhost:4566",
|
|
|
|
"bucket": "zot-storage",
|
|
|
|
"secure": false,
|
|
|
|
"skipverify": false
|
|
|
|
}
|
2023-09-20 11:25:06 -05:00
|
|
|
},
|
|
|
|
"http": {
|
|
|
|
"address": "127.0.0.1",
|
|
|
|
"port": "8080"
|
|
|
|
},
|
|
|
|
"log": {
|
|
|
|
"level": "debug",
|
|
|
|
"output": "${ZOT_LOG_FILE_NODEDUPE}"
|
|
|
|
}
|
2023-04-07 11:49:24 -05:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
awslocal s3 --region "us-east-2" mb s3://zot-storage
|
|
|
|
awslocal dynamodb --region "us-east-2" create-table --table-name "BlobTable" --attribute-definitions AttributeName=Digest,AttributeType=S --key-schema AttributeName=Digest,KeyType=HASH --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5
|
|
|
|
zot_serve ${zot_config_file_dedupe}
|
2023-08-30 14:24:28 -05:00
|
|
|
wait_zot_reachable 8080
|
2023-04-07 11:49:24 -05:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:06:21 -05:00
|
|
|
function teardown() {
|
|
|
|
# conditionally printing on failure is possible from teardown but not from from teardown_file
|
2023-09-20 11:25:06 -05:00
|
|
|
cat ${BATS_FILE_TMPDIR}/zot-log-dedupe.json
|
|
|
|
cat ${BATS_FILE_TMPDIR}/zot-log-nodedupe.json || true
|
2023-09-07 13:06:21 -05:00
|
|
|
}
|
|
|
|
|
2023-04-07 11:49:24 -05:00
|
|
|
function teardown_file() {
|
|
|
|
local zot_root_dir=${BATS_FILE_TMPDIR}/zot
|
|
|
|
zot_stop
|
|
|
|
rm -rf ${zot_root_dir}
|
|
|
|
awslocal s3 rb s3://"zot-storage" --force
|
|
|
|
awslocal dynamodb --region "us-east-2" delete-table --table-name "BlobTable"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "push 50 images with dedupe enabled" {
|
|
|
|
for i in {1..50}
|
|
|
|
do
|
|
|
|
run skopeo --insecure-policy copy --dest-tls-verify=false \
|
2023-10-12 08:42:07 -05:00
|
|
|
oci:${TEST_DATA_DIR}/alpine:1 \
|
|
|
|
docker://127.0.0.1:8080/alpine${i}:1
|
2023-04-07 11:49:24 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "restart zot with dedupe false and wait for restore blobs task to finish" {
|
|
|
|
local zot_config_file_nodedupe=${BATS_FILE_TMPDIR}/zot_config_nodedupe.json
|
|
|
|
local zot_root_dir=${BATS_FILE_TMPDIR}/zot
|
2023-09-20 11:25:06 -05:00
|
|
|
local ZOT_LOG_FILE=${BATS_FILE_TMPDIR}/zot-log-nodedupe.json
|
2023-04-07 11:49:24 -05:00
|
|
|
|
|
|
|
# stop server
|
|
|
|
zot_stop
|
|
|
|
|
|
|
|
sleep 10
|
|
|
|
|
|
|
|
# start with dedupe disabled
|
|
|
|
zot_serve ${zot_config_file_nodedupe}
|
2023-10-12 08:42:07 -05:00
|
|
|
|
|
|
|
sleep 1 # if we wait for zot to be reachable we may not catch the log message
|
|
|
|
|
2023-04-07 11:49:24 -05:00
|
|
|
start=`date +%s`
|
|
|
|
echo "waiting for restoring blobs task to finish" >&3
|
2023-12-11 08:39:32 -05:00
|
|
|
run wait_for_string "no digests left, finished" ${ZOT_LOG_FILE} "5m"
|
2023-05-31 12:26:23 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2023-04-07 11:49:24 -05:00
|
|
|
end=`date +%s`
|
|
|
|
|
|
|
|
runtime=$((end-start))
|
|
|
|
echo "restoring blobs finished in $runtime sec" >&3
|
|
|
|
sleep 10 # wait a bit more because dedupe runs in background.
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "pulling a previous deduped image should work" {
|
2023-10-12 08:42:07 -05:00
|
|
|
wait_zot_reachable 8080
|
|
|
|
|
|
|
|
# alpine1 should have original blobs already
|
2023-04-07 11:49:24 -05:00
|
|
|
echo "pulling first image" >&3
|
|
|
|
run skopeo --insecure-policy copy --src-tls-verify=false \
|
2023-10-12 08:42:07 -05:00
|
|
|
docker://127.0.0.1:8080/alpine1:1 \
|
|
|
|
oci:${TEST_DATA_DIR}/alpine1:1
|
2023-04-07 11:49:24 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
echo "pulling second image" >&3
|
2023-10-12 08:42:07 -05:00
|
|
|
# alpine2 should have original blobs after restoring blobs
|
2023-04-07 11:49:24 -05:00
|
|
|
run skopeo --insecure-policy copy --src-tls-verify=false \
|
2023-10-12 08:42:07 -05:00
|
|
|
docker://127.0.0.1:8080/alpine2:1 \
|
|
|
|
oci:${TEST_DATA_DIR}/alpine2:1
|
2023-04-07 11:49:24 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
|