33# Test backup and restore from s3.
44#
55# In the below we start a small FDB cluster, populate it with
6- # some data and then start up a seaweedfs instance or use S3
6+ # some data and then start up MockS3Server or use S3
77# if it is available. We then run a backup to 'S3' and then
88# a restore. We verify the restore is the same as the original.
99#
@@ -27,13 +27,16 @@ function cleanup {
2727 if type shutdown_fdb_cluster & > /dev/null; then
2828 shutdown_fdb_cluster
2929 fi
30- if type shutdown_weed & > /dev/null; then
31- shutdown_weed " ${TEST_SCRATCH_DIR} "
30+ if type shutdown_mocks3 & > /dev/null; then
31+ shutdown_mocks3
3232 fi
3333 if type shutdown_aws & > /dev/null; then
3434 shutdown_aws " ${TEST_SCRATCH_DIR} "
3535 fi
36+
37+ # Clean up encryption key file
3638 if [[ -n " ${ENCRYPTION_KEY_FILE:- } " ]] && [[ -f " ${ENCRYPTION_KEY_FILE} " ]]; then
39+ echo " Removing encryption key file: ${ENCRYPTION_KEY_FILE} "
3740 rm -f " ${ENCRYPTION_KEY_FILE} "
3841 fi
3942}
@@ -71,9 +74,6 @@ function backup {
7174 local local_credentials=" ${4} "
7275 local local_encryption_key_file=" ${5:- } "
7376
74- # Backup to s3. Without the -k argument in the below, the backup gets
75- # 'No restore target version given, will use maximum restorable version from backup description.'
76- # TODO: Why is -k needed?
7777 local cmd_args=(
7878 " -C" " ${local_scratch_dir} /loopback_cluster/fdb.cluster"
7979 " -t" " ${TAG} " " -w"
@@ -113,7 +113,7 @@ function restore {
113113 local cmd_args=(
114114 " --dest-cluster-file" " ${local_scratch_dir} /loopback_cluster/fdb.cluster"
115115 " -t" " ${TAG} " " -w"
116- " -r" " ${url } "
116+ " -r" " ${local_url } "
117117 " --log" " --logdir=${local_scratch_dir} "
118118 " --blob-credentials" " ${local_credentials} "
119119 )
@@ -145,17 +145,12 @@ function test_s3_backup_and_restore {
145145 local local_build_dir=" ${4} "
146146 local local_encryption_key_file=" ${5:- } "
147147
148- log " Load data"
149- if ! load_data " ${local_build_dir} " " ${local_scratch_dir} " ; then
150- err " Failed loading data into fdb"
151- return 1
152- fi
153148 # Edit the url. Backup adds 'data' to the path. Need this url for
154149 # cleanup of test data.
155150 local edited_url=$( echo " ${local_url} " | sed -e " s/ctest/data\/ctest/" )
156151 readonly edited_url
157152 if [[ " ${USE_S3} " == " true" ]]; then
158- # Run this rm only if s3. In seaweed , it would fail because
153+ # Run this rm only if s3. In MockS3Server , it would fail because
159154 # bucket doesn't exist yet (they are lazily created).
160155 local preclear_cmd=(" ${local_build_dir} /bin/s3client" )
161156 preclear_cmd+=(" ${KNOBS[@]} " )
@@ -169,6 +164,11 @@ function test_s3_backup_and_restore {
169164 return 1
170165 fi
171166 fi
167+ log " Load data"
168+ if ! load_data " ${local_build_dir} " " ${local_scratch_dir} " ; then
169+ err " Failed loading data into fdb"
170+ return 1
171+ fi
172172 log " Run s3 backup"
173173 if ! backup " ${local_build_dir} " " ${local_scratch_dir} " " ${local_url} " " ${credentials} " " ${local_encryption_key_file} " ; then
174174 err " Failed backup"
@@ -197,7 +197,7 @@ function test_s3_backup_and_restore {
197197 local cleanup_cmd=(" ${local_build_dir} /bin/s3client" )
198198 cleanup_cmd+=(" ${KNOBS[@]} " )
199199
200- # Only add TLS CA file for real S3, not SeaweedFS
200+ # Only add TLS CA file for real S3, not MockS3Server
201201 if [[ " ${USE_S3} " == " true" ]]; then
202202 cleanup_cmd+=(" --tls-ca-file" " ${TLS_CA_FILE} " )
203203 fi
@@ -369,7 +369,9 @@ while (( "$#" )); do
369369done
370370
371371# Set positional arguments in their proper place
372- set -- " ${PARAMS[@]} "
372+ if [ ${# PARAMS[@]} -ne 0 ]; then
373+ set -- " ${PARAMS[@]} "
374+ fi
373375
374376# Globals
375377# TEST_SCRATCH_DIR gets set below. Tests should be their data in here.
@@ -382,17 +384,17 @@ readonly TAG="test_backup"
382384# internal apple dev environments where S3 is available).
383385readonly USE_S3=" ${USE_S3:- $( if [[ -n "${OKTETO_NAMESPACE+x}" ]]; then echo " true" ; else echo " false" ; fi )} "
384386
385- # Set KNOBS based on whether we're using real S3 or SeaweedFS
387+ # Set KNOBS based on whether we're using real S3 or MockS3Server
386388if [[ " ${USE_S3} " == " true" ]]; then
387389 # Use AWS KMS encryption for real S3
388390 KNOBS=(" --knob_blobstore_encryption_type=aws:kms" " --knob_http_verbose_level=${HTTP_VERBOSE_LEVEL} " )
389391else
390- # No encryption for SeaweedFS
392+ # No encryption for MockS3Server
391393 KNOBS=(" --knob_http_verbose_level=${HTTP_VERBOSE_LEVEL} " )
392394fi
393395readonly KNOBS
394396
395- # Set TLS_CA_FILE only when using real S3, not for SeaweedFS
397+ # Set TLS_CA_FILE only when using real S3, not for MockS3Server
396398if [[ " ${USE_S3} " == " true" ]]; then
397399 # Try to find a valid TLS CA file if not explicitly set
398400 if [[ -z " ${TLS_CA_FILE:- } " ]]; then
@@ -406,7 +408,7 @@ if [[ "${USE_S3}" == "true" ]]; then
406408 fi
407409 TLS_CA_FILE=" ${TLS_CA_FILE:- } "
408410else
409- # For SeaweedFS , don't use TLS
411+ # For MockS3Server , don't use TLS
410412 TLS_CA_FILE=" "
411413fi
412414readonly TLS_CA_FILE
471473fi
472474readonly ENCRYPTION_KEY_FILE
473475
474- # Set host, bucket, and blob_credentials_file whether seaweed or s3.
476+ # Set host, bucket, and blob_credentials_file whether MockS3Server or s3.
475477readonly path_prefix=" ctests"
476478host=
477479query_str=
@@ -502,30 +504,31 @@ if [[ "${USE_S3}" == "true" ]]; then
502504 export FDB_BLOB_CREDENTIALS=" ${blob_credentials_file} "
503505 export FDB_TLS_CA_FILE=" ${TLS_CA_FILE} "
504506else
505- log " Testing against seaweedfs "
506- # Now source in the seaweedfs fixture so we can use its methods in the below.
507+ log " Testing against MockS3Server "
508+ # Now source in the mocks3 fixture so we can use its methods in the below.
507509 # shellcheck source=/dev/null
508- if ! source " ${cwd} /../../fdbclient/tests/seaweedfs_fixture .sh" ; then
509- err " Failed to source seaweedfs_fixture .sh"
510+ if ! source " ${cwd} /../../fdbclient/tests/mocks3_fixture .sh" ; then
511+ err " Failed to source mocks3_fixture .sh"
510512 exit 1
511513 fi
512- if ! TEST_SCRATCH_DIR=$( create_weed_dir " ${scratch_dir} " ) ; then
513- err " Failed create of the weed dir." >&2
514- return 1
514+ if ! TEST_SCRATCH_DIR=$( mktemp -d " ${scratch_dir} /mocks3_backup_test.XXXXXX " ) ; then
515+ err " Failed create of the mocks3 test dir." >&2
516+ exit 1
515517 fi
516518 readonly TEST_SCRATCH_DIR
517- if ! host= $( run_weed " ${scratch_dir} " " ${TEST_SCRATCH_DIR} " ) ; then
518- err " Failed to run seaweed "
519- return 1
519+ if ! start_mocks3 " ${build_dir} " ; then
520+ err " Failed to start MockS3Server "
521+ exit 1
520522 fi
521- readonly host
522- readonly bucket=" ${SEAWEED_BUCKET} "
523- readonly region=" all_regions "
524- # Reference a non-existent blob file (its ignored by seaweed )
523+ readonly host= " ${MOCKS3_HOST} : ${MOCKS3_PORT} "
524+ readonly bucket=" test-bucket "
525+ readonly region=" us-east-1 "
526+ # Create an empty blob credentials file (MockS3Server uses simple auth )
525527 readonly blob_credentials_file=" ${TEST_SCRATCH_DIR} /blob_credentials.json"
526- # Let the connection to seaweed be insecure -- not-TLS -- because just awkward to set up.
528+ echo ' {}' > " ${blob_credentials_file} "
529+ # Let the connection to MockS3Server be insecure -- not-TLS
527530 query_str=" bucket=${bucket} ®ion=${region} &secure_connection=0"
528- # Set environment variables for SeaweedFS too
531+ # Set environment variables for MockS3Server
529532 export FDB_BLOB_CREDENTIALS=" ${blob_credentials_file} "
530533fi
531534
0 commit comments