Skip to content

Commit

Permalink
feat(redis): added blackbox tests for redis
Browse files Browse the repository at this point in the history
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
  • Loading branch information
eusebiu-constantin-petu-dbk committed Apr 30, 2024
1 parent cfca8b9 commit 37d1b15
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 6 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/notaryproject/notation-go v1.1.0
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240201174943-0f98d91a0afe
github.com/project-zot/mockoidc v0.0.0-20230307111146-f607b4b5fb97
github.com/redis/go-redis/v9 v9.3.0
github.com/redis/go-redis/v9 v9.5.1
github.com/sigstore/cosign/v2 v2.2.4
github.com/swaggo/http-swagger v1.3.4
github.com/zitadel/oidc v1.13.5
Expand Down Expand Up @@ -195,15 +195,13 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rootless-containers/proto/go-proto v0.0.0-20210921234734-69430b6543fb // indirect
github.com/rubenv/sql-migrate v1.5.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sigstore/timestamp-authority v1.2.2 // indirect
github.com/sigstore/cosign v1.13.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/smarty/assertions v1.15.0 // indirect
github.com/sosodev/duration v1.2.0 // indirect
Expand All @@ -215,6 +213,7 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ github.com/CycloneDX/cyclonedx-go v0.8.0 h1:FyWVj6x6hoJrui5uRQdYZcSievw3Z32Z88uY
github.com/CycloneDX/cyclonedx-go v0.8.0/go.mod h1:K2bA+324+Og0X84fA8HhN2X066K7Bxz4rpMQ4ZhjtSk=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/DmitriyVTitov/size v1.5.0/go.mod h1:le6rNI4CoLQV1b9gzp1+3d7hMAD/uu2QcJ+aYbNgiU0=
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible h1:juIaKLLVhqzP55d8x4cSVgwyQv76Z55/fRv/UBr2KkQ=
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible/go.mod h1:BB1eHdMLYEFuFdBlRMb0N7YGVdM5s6Pt0njxgvfbGGs=
github.com/Intevation/gval v1.3.0 h1:+Ze5sft5MmGbZrHj06NVUbcxCb67l9RaPTLMNr37mjw=
Expand Down Expand Up @@ -1314,8 +1315,8 @@ github.com/protocolbuffers/txtpbfmt v0.0.0-20231025115547-084445ff1adf h1:014O62
github.com/protocolbuffers/txtpbfmt v0.0.0-20231025115547-084445ff1adf/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/redis/go-redis/v9 v9.3.0 h1:RiVDjmig62jIWp7Kk4XVLs0hzV6pI3PyTnnL0cnn0u0=
github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func NewRedisCache(parameters interface{}, log zlog.Logger) (*RedisDriver, error
if err != nil {
log.Error().Err(err).Str("directory", properParameters.URL).Msg("failed to connect to redis")

Check warning on line 41 in pkg/storage/cache/redis.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/cache/redis.go#L41

Added line #L41 was not covered by tests
}

Check failure on line 43 in pkg/storage/cache/redis.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(zotregistry.dev/zot) (gci)
cacheDB := redis.NewClient(connOpts)

if _, err := cacheDB.Ping(context.Background()).Result(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PATH=$PATH:${SCRIPTPATH}/../../hack/tools/bin

tests=("pushpull" "pushpull_authn" "delete_images" "referrers" "metadata" "anonymous_policy"
"annotations" "detect_manifest_collision" "cve" "sync" "sync_docker" "sync_replica_cluster"
"scrub" "garbage_collect" "metrics" "metrics_minimal" "multiarch_index")
"scrub" "garbage_collect" "metrics" "metrics_minimal" "multiarch_index", "redis_local", "redis_s3")

for test in ${tests[*]}; do
${BATS} ${BATS_FLAGS} ${SCRIPTPATH}/${test}.bats > ${test}.log & pids+=($!)
Expand Down
37 changes: 37 additions & 0 deletions test/blackbox/redis.bats → test/blackbox/redis_local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,43 @@ EOF
wait_zot_reachable ${zot_port}
}

@test "push 2 images" {
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
run skopeo --insecure-policy copy --dest-tls-verify=false \
oci:${TEST_DATA_DIR}/golang:1.20 \
docker://127.0.0.1:${zot_port}/golang:1.20
[ "$status" -eq 0 ]

run skopeo --insecure-policy copy --dest-tls-verify=false \
oci:${TEST_DATA_DIR}/golang:1.20 \
docker://127.0.0.1:${zot_port}/golang2:1.20
[ "$status" -eq 0 ]

run curl http://127.0.0.1:${zot_port}/v2/_catalog
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.repositories[]') = '"golang"' ]
run curl http://127.0.0.1:${zot_port}/v2/golang/tags/list
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.tags[]') = '"1.20"' ]
}

@test "pull both images" {
local oci_data_dir=${BATS_FILE_TMPDIR}/oci
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
run skopeo --insecure-policy copy --src-tls-verify=false \
docker://127.0.0.1:${zot_port}/golang:1.20 \
oci:${oci_data_dir}/golang:1.20
[ "$status" -eq 0 ]
run cat ${BATS_FILE_TMPDIR}/oci/golang/index.json
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.manifests[].annotations."org.opencontainers.image.ref.name"') = '"1.20"' ]

run skopeo --insecure-policy copy --src-tls-verify=false \
docker://127.0.0.1:${zot_port}/golang2:1.20 \
oci:${oci_data_dir}/golang:1.20
[ "$status" -eq 0 ]
}

function teardown_file() {
zot_stop_all
redis_stop
Expand Down
126 changes: 126 additions & 0 deletions test/blackbox/redis_s3.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci"
# Makefile target installs & checks all necessary tooling
# Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites()

load helpers_zot
load helpers_redis

function verify_prerequisites() {
if [ ! $(command -v curl) ]; then
echo "you need to install curl as a prerequisite to running the tests" >&3
return 1
fi

if [ ! $(command -v jq) ]; then
echo "you need to install jq as a prerequisite to running the tests" >&3
return 1
fi

if [ ! $(command -v docker) ]; then
echo "you need to install docker as a prerequisite to running the tests" >&3
return 1
fi

return 0
}

function setup_file() {
# Verify prerequisites are available
if ! $(verify_prerequisites); then
exit 1
fi

# Setup redis server
redis_start

# Setup zot server
local zot_root_dir=${BATS_FILE_TMPDIR}/zot
local zot_sync_ondemand_config_file=${BATS_FILE_TMPDIR}/zot_sync_ondemand_config.json
zot_port=$(get_free_port)
echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port

mkdir -p ${zot_root_dir}

cat >${zot_sync_ondemand_config_file} <<EOF
{
"distSpecVersion": "1.1.0",
"storage": {
"dedupe": true,
"gc": true,
"rootDirectory": "${zot_root_dir}",
"cacheDriver": {
"name": "redis",
"rootDir": "${zot_root_dir}/_redis",
"url": "redis://localhost:6379"
},
"storageDriver": {
"name": "s3",
"rootdirectory": "/zot",
"region": "us-east-2",
"regionendpoint": "localhost:4566",
"bucket": "zot-storage",
"secure": false,
"skipverify": false
}
},
"http": {
"address": "0.0.0.0",
"port": "${zot_port}"
},
"log": {
"level": "debug",
"output": "/tmp/blackbox.log"
},
"extensions": {
"ui": {
"enable": true
}
}
}
EOF

awslocal s3 --region "us-east-2" mb s3://zot-storage

zot_serve ${ZOT_PATH} ${zot_sync_ondemand_config_file}
wait_zot_reachable ${zot_port}
}

@test "push 3 images with dedupe enabled" {
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`

for i in {1..3}
do
run skopeo --insecure-policy copy --dest-tls-verify=false \
oci:${TEST_DATA_DIR}/alpine:1 \
docker://127.0.0.1:${zot_port}/alpine${i}:1.0
[ "$status" -eq 0 ]
done
}

@test "pull second image with deduped blobs" {
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`

run skopeo --insecure-policy copy --src-tls-verify=false docker://127.0.0.1:${zot_port}/alpine2 oci:test1/alpine2:1.0
[ "$status" -eq 0 ]
}

@test "original blobs are moved to the next image when removing the first one" {
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`

# in case of s3, because it doesn't support symlinks:
# blobs contents are stored only once, the rest of deduped blobs are 0 size files
# when removing an image which contains original blobs, their contents should move to the next candidates.
# so removing the first image: alpine1 which contains only original blobs, the contents should move to alpine2
run skopeo --insecure-policy delete --tls-verify=false \
docker://127.0.0.1:${zot_port}/alpine1:1.0
[ "$status" -eq 0 ]

# pulling the next image should work
run skopeo --insecure-policy copy --src-tls-verify=false docker://127.0.0.1:${zot_port}/alpine2 oci:test2/alpine2:1.0
[ "$status" -eq 0 ]
}

function teardown_file() {
zot_stop_all
redis_stop
}

0 comments on commit 37d1b15

Please sign in to comment.