Repository navigation
Expand file tree
/
Copy pathrustfs-replication-test.sh
More file actions
executable file
·1394 lines (1280 loc) · 61.9 KB
/
Copy pathrustfs-replication-test.sh
File metadata and controls
executable file
·1394 lines (1280 loc) · 61.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# rustfs-replication-test.sh
# RustFS replication test suite: bucket replication (REP-*) and site
# replication (SITE-*).
#
# Bucket replication cases pair two deployments already running on the test
# node: the shared cluster (single-multi topology, :9000) as the SOURCE and a
# dedicated second instance (rustfs-rep2, :19000) as the TARGET. They drive
# the SigV4-signed admin plane (set/list/remove-remote-target,
# replication-check, replication-reset) plus the S3 data plane via the aws
# CLI, and assert PUT/delete-marker/existing-object-resync/multipart
# convergence on the target.
#
# Site replication cases configure site replication between the same two
# deployments (site1 = :9000, site2 = :19000) via the site-replication admin
# API (add/info/status/resync/remove) and assert IAM user/policy/bucket/
# object metadata converges in both directions.
#
# Usage:
# ./rustfs-replication-test.sh -y
# ./rustfs-replication-test.sh --suite bucket -y --package-url <deb url>
# ./rustfs-replication-test.sh --suite site -y
# ./rustfs-replication-test.sh --dry-run
#
# Notes:
# - Requires ssh to the test nodes, and aws/jq/curl/openssl on the runner
# (the S3 and admin channels are driven over HTTP from the runner).
#
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
JQ_LIB="${SCRIPT_DIR}/scripts/lib"
# ==================== Configuration ====================
if [ -n "${RUSTFS_NODES:-}" ]; then
read -r -a NODES <<<"${RUSTFS_NODES}"
else
NODES=(vm000 vm001 vm002 vm003)
fi
# Host prefix used in endpoint expressions (RUSTFS_VOLUMES, replication
# target, site peers). The names must resolve BOTH from the runner (SSH/S3)
# and from every node itself (rustfs local-host detection, replication
# workers dialing peers), so prefer the rustfs-nodeN aliases the shared
# environment provisions; fall back to the first node's SSH host when absent.
endpoint_host_prefix() {
if getent hosts "rustfs-node1" >/dev/null 2>&1; then printf 'rustfs-node';
else printf '%s' "${NODES[0]}"; fi
}
SSH_USER="${RUSTFS_SSH_USER:-azureuser}"
SSH_PORT="${RUSTFS_SSH_PORT:-22}"
SSH_OPTS=(-o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new -p "${SSH_PORT}")
RUSTFS_VERSION="${RUSTFS_VERSION:-1.0.0-rc.4-preview.1}"
PACKAGE_URL="${PACKAGE_URL:-}"
ARCH="${RUSTFS_ARCH:-amd64}"
PACKAGES_DIR="/home/rustfs/packages"
PACKAGE_FILE="rustfs.deb"
PACKAGE_SHA256="${PACKAGE_SHA256:-}"
API_ENDPOINT="${RUSTFS_API_ENDPOINT:-${RUSTFS_RC_ENDPOINT:-http://rustfs-node1:9000}}"
ACCESS_KEY="${RUSTFS_ACCESS_KEY:-rustfs@test}"
SECRET_KEY="${RUSTFS_SECRET_KEY:-rustfs@test}"
REGION="us-east-1"
SIGV4_REGION="us-east-1"
SIGV4_SERVICE="s3"
API_REQUEST_TIMEOUT=60
# Main cluster (source site): multi-multi across the shared nodes, i.e. one
# distributed rustfs with an endpoint per node (http://<node>:9000/data/...).
# A bare local path here would silently form N independent single-node
# clusters (each node gets its own format.json cluster id), which breaks
# replication and load-balanced S3 calls.
VOLUMES_PATH="/data/rustfs{1...4}/mnmd"
# Second instance (target site / bucket-replication target) on the first node.
# The script drives the nodes over SSH but talks S3/admin over HTTP from the
# host it runs on, so the endpoint must be the first node's address, not
# 127.0.0.1 (that only works when node and runner share a host). The target
# endpoint is ALSO dialed by the main-cluster nodes themselves (replication
# workers), so it must use the rustfs-nodeN alias that resolves inside the
# VMs too.
SITE2_SERVICE="rustfs-rep2"
SITE2_ADDRESS=":19000"
SITE2_CONSOLE_ADDRESS=":19001"
SITE2_HOSTPORT="${RUSTFS_SITE2_HOST:-$(endpoint_host_prefix)1}:19000"
SITE2_ENDPOINT="${RUSTFS_SITE2_ENDPOINT:-http://${SITE2_HOSTPORT}}"
SITE2_VOLUMES="/data/rustfs-rep2/mnmd"
SITE1_NAME="site1"
SITE2_NAME="site2"
RUSTFS_CONFIG_FILE="/etc/default/rustfs"
SITE2_CONFIG_FILE="/etc/default/rustfs-rep2"
RUSTFS_SERVICE="rustfs"
RUSTFS_USER="rustfs"
# The deb installs the binary at /usr/bin/rustfs; the upstream unit uses the
# same path. Keep it overridable for source-built deployments.
RUSTFS_BIN="${RUSTFS_BIN:-/usr/bin/rustfs}"
RUSTFS_ADDRESS=":9000"
RUSTFS_CONSOLE_ADDRESS=":9001"
RUSTFS_CONSOLE_ENABLE=true
RUSTFS_OBS_LOGGER_LEVEL=error
RUSTFS_OBS_LOG_DIRECTORY="/var/log/rustfs/"
# Convergence polling budget (seconds) for async replication.
CONVERGE_TIMEOUT=180
CONVERGE_INTERVAL=5
SUITE_BUCKET="bucket"
SUITE_SITE="site"
SUITE_ALL="all"
SERVICE_TIMEOUT=300
# ==================== Runtime options ====================
DRY_RUN=0
ASSUME_YES=0
KEEP_ENV=0
LOG_FILE=""
SELECTED_SUITES=()
TEST_TMP="$(mktemp -d "${TMPDIR:-/tmp}/rustfs-repl.XXXXXX")"
trap 'rm -rf "${TEST_TMP}"' EXIT
SIGNED_CODE_FILE="${TEST_TMP}/signed-api-code"
# ==================== Helpers ====================
log() { printf '\033[1;36m[INFO]\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m[WARN]\033[0m %s\n' "$*"; }
die() { printf '\033[1;31m[ERROR]\033[0m %s\n' "$*" >&2; exit 1; }
confirm() {
[ "${ASSUME_YES}" -eq 1 ] && return 0
printf '\033[1;33m[CONFIRM]\033[0m %s (y/N) ' "$1"
read -r answer
case "${answer}" in y|Y|yes|YES) return 0 ;; *) die "cancelled" ;; esac
}
need_cmd() {
[ "${DRY_RUN}" -eq 1 ] && return 0
command -v "$1" >/dev/null 2>&1 || die "missing command: $1 ($2); install it first"
}
build_package_url() {
local tag="${RUSTFS_VERSION#v}" asset
asset="${tag//-/.}"
printf 'https://github.com/rustfs/rustfs/releases/download/%s/rustfs_%s_%s.deb' "${tag}" "${asset}" "${ARCH}"
}
resolve_package_url() {
if [ -n "${PACKAGE_URL}" ]; then printf '%s' "${PACKAGE_URL}";
else build_package_url; fi
}
run_remote() {
local node="$1" script
script="$(cat)"
if [ "${DRY_RUN}" -eq 1 ]; then
log "DRY-RUN: ssh ${SSH_USER}@${node} <<'REMOTE'"
printf '%s\n' "${script}" | sed 's/^/ | /'
return 0
fi
ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" 'bash -s' <<<"${script}"
}
run_remote_all() {
local script pids=() i=0 fail=0 node
script="$(cat)"
for node in "${NODES[@]}"; do
if [ "${DRY_RUN}" -eq 1 ]; then
log "DRY-RUN: ssh ${SSH_USER}@${node} <<'REMOTE'"
printf '%s\n' "${script}" | sed 's/^/ | /'
else
( ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" 'bash -s' <<<"${script}" ) &
pids[$i]=$!; i=$((i+1))
fi
done
if [ "${#pids[@]}" -gt 0 ]; then
for pid in "${pids[@]}"; do wait "${pid}" || fail=1; done
fi
[ "${fail}" -eq 0 ] || die "one or more nodes failed"
}
wait_service_active() {
local node="$1" service="$2" waited=0
[ "${DRY_RUN}" -eq 1 ] && { log "DRY-RUN: wait ${service} active on ${node}"; return 0; }
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" "systemctl is-active --quiet ${service}" 2>/dev/null; then
log "${node}: ${service} is active"; return 0
fi
sleep 5; waited=$((waited+5))
done
die "${node}: timed out waiting for ${service} (${SERVICE_TIMEOUT}s)"
}
wait_http_live() {
local url="$1" waited=0
[ "${DRY_RUN}" -eq 1 ] && return 0
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if curl -fsS --max-time 5 "${url}/minio/health/live" >/dev/null 2>&1; then
log "endpoint ready: ${url}"; return 0
fi
sleep 5; waited=$((waited+5))
done
die "endpoint ${url} not ready (${SERVICE_TIMEOUT}s)"
}
# ==================== Environment setup ====================
# Expand a RUSTFS_VOLUMES expression ("/data/rustfs{1...4}/mnmd" or an
# http://host:port/path form) into the concrete directory list.
volume_dirs() {
local volumes="$1" expr path prefix suffix i start end
for expr in ${volumes}; do
path="${expr#*://}"; path="${path#*/}"; path="/${path}"
if [[ "${path}" =~ \{([0-9]+)\.\.\.([0-9]+)\} ]]; then
start="${BASH_REMATCH[1]}"; end="${BASH_REMATCH[2]}"
prefix="${path%%\{*}"; suffix="${path#*\}}"
for ((i=start; i<=end; i++)); do printf '%s%s%s\n' "${prefix}" "${i}" "${suffix}"; done
else
printf '%s\n' "${path}"
fi
done
}
ensure_volume_dirs() {
local node="$1" volumes="$2" dirs=() d
while IFS= read -r d; do dirs+=("${d}"); done < <(volume_dirs "${volumes}" | sort -u)
log "${node}: ensuring data dirs (${dirs[*]})"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf 'id -u %s >/dev/null 2>&1 || ${SUDO} useradd -r -s /bin/false -d /opt/%s %s\n' "${RUSTFS_USER}" "${RUSTFS_USER}" "${RUSTFS_USER}"
for d in "${dirs[@]}"; do
printf '${SUDO} mkdir -p %s\n' "${d}"
printf '${SUDO} chown -R %s:%s %s\n' "${RUSTFS_USER}" "${RUSTFS_USER}" "${d}"
done
} | run_remote "${node}"
}
rustfs_config_body() {
local volumes="$1"
cat <<EOF
RUSTFS_ACCESS_KEY=${ACCESS_KEY}
RUSTFS_SECRET_KEY=${SECRET_KEY}
RUSTFS_VOLUMES="${volumes}"
RUSTFS_ADDRESS="${RUSTFS_ADDRESS}"
RUSTFS_CONSOLE_ADDRESS="${RUSTFS_CONSOLE_ADDRESS}"
RUSTFS_CONSOLE_ENABLE=${RUSTFS_CONSOLE_ENABLE}
RUSTFS_OBS_LOGGER_LEVEL=${RUSTFS_OBS_LOGGER_LEVEL}
RUSTFS_OBS_LOG_DIRECTORY="${RUSTFS_OBS_LOG_DIRECTORY}"
RUSTFS_REPLICATION_ALLOW_LOOPBACK_TARGET=true
EOF
}
site2_config_body() {
cat <<EOF
RUSTFS_ACCESS_KEY=${ACCESS_KEY}
RUSTFS_SECRET_KEY=${SECRET_KEY}
RUSTFS_VOLUMES="${SITE2_VOLUMES}"
RUSTFS_ADDRESS="${SITE2_ADDRESS}"
RUSTFS_CONSOLE_ADDRESS="${SITE2_CONSOLE_ADDRESS}"
RUSTFS_CONSOLE_ENABLE=${RUSTFS_CONSOLE_ENABLE}
RUSTFS_OBS_LOGGER_LEVEL=${RUSTFS_OBS_LOGGER_LEVEL}
RUSTFS_OBS_LOG_DIRECTORY="/var/log/rustfs-rep2/"
RUSTFS_REPLICATION_ALLOW_LOOPBACK_TARGET=true
EOF
}
write_remote_config() {
local node="$1" config_file="$2" body="$3"
log "${node}: writing config ${config_file}"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf 'if [ -f %s ]; then ${SUDO} cp -a %s %s.bak.$(date +%%Y%%m%%d%%H%%M%%S) 2>/dev/null || true; fi\n' "${config_file}" "${config_file}" "${config_file}"
printf '%s tee %s >/dev/null <<RUSTFS_EOF\n' '${SUDO}' "${config_file}"
printf '%s' "${body}"
printf '\nRUSTFS_EOF\n'
} | run_remote "${node}"
}
write_site2_unit() {
local node="$1"
log "${node}: writing systemd unit for ${SITE2_SERVICE}"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf '${SUDO} tee /etc/systemd/system/%s.service >/dev/null <<UNIT_EOF\n' "${SITE2_SERVICE}"
printf '[Unit]\n'
printf 'Description=RustFS second site (replication test)\n'
printf 'After=network-online.target\n'
printf 'Wants=network-online.target\n\n'
printf '[Service]\n'
printf 'Type=simple\n'
printf 'User=%s\n' "${RUSTFS_USER}"
printf 'Group=%s\n' "${RUSTFS_USER}"
printf 'EnvironmentFile=%s\n' "${SITE2_CONFIG_FILE}"
printf 'ExecStart=%s server\n' "${RUSTFS_BIN}"
printf 'Restart=on-failure\n'
printf 'RestartSec=5\n'
printf 'LimitNOFILE=65536\n\n'
printf '[Install]\n'
printf 'WantedBy=multi-user.target\n'
printf 'UNIT_EOF\n'
printf '${SUDO} systemctl daemon-reload\n'
} | run_remote "${node}"
}
service_action() {
local action="$1" node="$2" service="${3:-${RUSTFS_SERVICE}}"
log "${node}: systemctl ${action} ${service}"
[ "${DRY_RUN}" -eq 1 ] && return 0
ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" \
"if [ \"\$(id -u)\" -ne 0 ]; then sudo -n systemctl ${action} ${service}; else systemctl ${action} ${service}; fi" \
|| die "${node}: systemctl ${action} ${service} failed"
}
cleanup_node() {
local node="$1" d
log "cleanup: replication test residue on ${node}"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf '${SUDO} systemctl stop %s 2>/dev/null || true\n' "${SITE2_SERVICE}"
printf '${SUDO} rm -f /etc/systemd/system/%s.service\n' "${SITE2_SERVICE}"
printf '${SUDO} rm -f %s\n' "${SITE2_CONFIG_FILE}"
printf '${SUDO} rm -rf %s /var/log/rustfs-rep2\n' "${SITE2_VOLUMES}"
printf '${SUDO} systemctl stop %s 2>/dev/null || true\n' "${RUSTFS_SERVICE}"
printf '${SUDO} rm -f %s\n' "${RUSTFS_CONFIG_FILE}"
printf '${SUDO} rm -rf /data/rustfs[1-9]/mnmd /var/log/rustfs\n'
printf '${SUDO} systemctl daemon-reload 2>/dev/null || true\n'
} | run_remote "${node}"
}
install_package_all() {
local url script
url="$(resolve_package_url)"
log "installing package ${url} on ${NODES[*]}"
script="$(cat <<EOF
set -euo pipefail
SUDO=""; [ "\$(id -u)" -ne 0 ] && SUDO="sudo -n"
\${SUDO} mkdir -p "${PACKAGES_DIR}"
curl -fSL --retry 3 -o "/tmp/${PACKAGE_FILE}" "${url}"
\${SUDO} install -m 0644 "/tmp/${PACKAGE_FILE}" "${PACKAGES_DIR}/${PACKAGE_FILE}"
\${SUDO} rm -f "/tmp/${PACKAGE_FILE}"
if [ -n "${PACKAGE_SHA256}" ]; then
echo "${PACKAGE_SHA256} ${PACKAGES_DIR}/${PACKAGE_FILE}" | sha256sum -c - || exit 1
fi
\${SUDO} DEBIAN_FRONTEND=noninteractive dpkg --force-confnew -i "${PACKAGES_DIR}/${PACKAGE_FILE}"
\${SUDO} systemctl daemon-reload
ls -lh "${PACKAGES_DIR}/${PACKAGE_FILE}"
EOF
)"
printf '%s\n' "${script}" | run_remote_all
}
env_setup_main_cluster() {
local node body
# Multi-multi, same form the security/s3 suites write: rustfs expands the
# {a...b} braces itself at startup, which keeps every node agreeing on the
# set layout. Pre-expanded endpoint lists are avoided on purpose.
local volumes
volumes="http://$(endpoint_host_prefix){1...$((${#NODES[@]}))}:9000${VOLUMES_PATH}"
log "environment setup: main cluster (multi-multi, ${NODES[*]}) volumes: ${volumes}"
for node in "${NODES[@]}"; do cleanup_node "${node}"; done
install_package_all
for node in "${NODES[@]}"; do ensure_volume_dirs "${node}" "${VOLUMES_PATH}"; done
body="$(rustfs_config_body "${volumes}")"
for node in "${NODES[@]}"; do
write_remote_config "${node}" "${RUSTFS_CONFIG_FILE}" "${body}"
done
local pids=() pid
for node in "${NODES[@]}"; do service_action start "${node}" & pids+=($!); done
for pid in "${pids[@]}"; do wait "${pid}" || die "start failed"; done
for node in "${NODES[@]}"; do wait_service_active "${node}" "${RUSTFS_SERVICE}"; done
wait_http_live "${API_ENDPOINT}"
export AWS_ACCESS_KEY_ID="${ACCESS_KEY}"
export AWS_SECRET_ACCESS_KEY="${SECRET_KEY}"
export AWS_DEFAULT_REGION="${REGION}"
export AWS_EC2_METADATA_DISABLED=true
}
env_setup_site2() {
local node="${NODES[0]}"
log "environment setup: second site ${SITE2_SERVICE} on ${node} (${SITE2_ENDPOINT})"
ensure_volume_dirs "${node}" "${SITE2_VOLUMES}"
write_remote_config "${node}" "${SITE2_CONFIG_FILE}" "$(site2_config_body)"
write_site2_unit "${node}"
service_action start "${node}" "${SITE2_SERVICE}"
wait_service_active "${node}" "${SITE2_SERVICE}"
wait_http_live "${SITE2_ENDPOINT}"
}
env_teardown() {
local node
log "environment teardown"
for node in "${NODES[@]}"; do cleanup_node "${node}"; done
}
# ==================== SigV4 request helper ====================
hex_of_ascii() { printf '%s' "$1" | od -An -tx1 | tr -d ' \n'; }
sha256_hex() { printf '%s' "$1" | openssl dgst -sha256 -hex | awk '{print $NF}'; }
# HMAC-SHA256 with the key supplied as hex (decoded to raw bytes). SigV4
# derives each round's key as raw bytes; feeding the hex string through
# -hmac would sign with the ASCII of the hex chars and the server rejects
# the result with SignatureDoesNotMatch.
hmac_sha256_hexkey() { printf '%s' "$2" | openssl dgst -sha256 -mac HMAC -macopt hexkey:"$1" -hex | awk '{print $NF}'; }
# SigV4 URI-encode one query name or value: keep RFC 3986 unreserved
# characters, percent-encode every other byte as uppercase %XX.
sigv4_uri_encode() {
local LC_ALL=C
local s="$1" out="" i c
for (( i = 0; i < ${#s}; i++ )); do
c="${s:i:1}"
case "${c}" in
[A-Za-z0-9_.~-]) out+="${c}" ;;
*) out+="$(printf '%%%02X' "$(( $(printf '%d' "'${c}") & 255 ))")" ;;
esac
done
printf '%s' "${out}"
}
canonical_query() {
local q="$1"
[ -z "${q}" ] && return 0
# The server percent-decodes the raw query and re-encodes every pair for
# the canonical request (name and value, RFC 3986 unreserved only), and a
# valueless param (?flag) comes back as "flag=". Callers pass raw values,
# so encode here and send the same encoded string on the wire; anything
# signed verbatim (e.g. "@" in an access key, ":" in an ARN) fails with
# SignatureDoesNotMatch.
local pairs=() pair name value
IFS='&' read -r -a pairs <<< "${q}"
for pair in "${pairs[@]}"; do
[ -n "${pair}" ] || continue
name="${pair%%=*}"
if [ "${name}" = "${pair}" ]; then value=""; else value="${pair#*=}"; fi
printf '%s=%s\n' "$(sigv4_uri_encode "${name}")" "$(sigv4_uri_encode "${value}")"
done | LC_ALL=C sort | paste -sd '&' -
}
# signed_request <endpoint> <method> <path> [query] [body] [content_type]
# Signs with the S3 service name (admin endpoints accept the S3 signing
# chain), UNSIGNED-PAYLOAD, and content-type;host;x-amz-content-sha256;
# x-amz-date whenever a body is sent (curl always emits Content-Type for
# -d and the server signs every header it sees except the ignored few,
# so an unsigned Content-Type fails with SignatureDoesNotMatch).
# Prints the response body; the HTTP code lands in the file read by signed_code().
signed_request() {
local endpoint="$1" method="$2" path="$3" query="${4:-}" body="${5:-}" content_type="${6:-application/xml}"
local amz_date date_stamp host_port
local canonical_headers signed_headers canonical_request string_to_sign
local scope k_secret k_date k_region k_service k_signing signature auth
local url tmp code raw_query
local curl_body=()
if [ "${DRY_RUN}" -eq 1 ]; then
log "DRY-RUN: signed ${method} ${endpoint}${path}${query:+?${query}}"
printf '200' > "${SIGNED_CODE_FILE}"
printf '{}'
return 0
fi
host_port="${endpoint#*://}"
host_port="${host_port%%/*}"
amz_date="$(date -u +%Y%m%dT%H%M%SZ)"
date_stamp="${amz_date:0:8}"
raw_query="${query}"
query="$(canonical_query "${query}")"
# The server requires every header actually sent to be signed (it rejects
# with "missing signed header: content-type"). Always sign content-type and
# always send it explicitly so the signed and sent sets match exactly.
canonical_headers="content-type:${content_type}
host:${host_port}
x-amz-content-sha256:UNSIGNED-PAYLOAD
x-amz-date:${amz_date}
"
signed_headers="content-type;host;x-amz-content-sha256;x-amz-date"
canonical_request="${method}
${path}
${query}
${canonical_headers}
${signed_headers}
UNSIGNED-PAYLOAD"
scope="${date_stamp}/${SIGV4_REGION}/${SIGV4_SERVICE}/aws4_request"
string_to_sign="AWS4-HMAC-SHA256
${amz_date}
${scope}
$(sha256_hex "${canonical_request}")"
k_secret="$(hex_of_ascii "AWS4${SECRET_KEY}")"
k_date="$(hmac_sha256_hexkey "${k_secret}" "${date_stamp}")"
k_region="$(hmac_sha256_hexkey "${k_date}" "${SIGV4_REGION}")"
k_service="$(hmac_sha256_hexkey "${k_region}" "${SIGV4_SERVICE}")"
k_signing="$(hmac_sha256_hexkey "${k_service}" "aws4_request")"
signature="$(hmac_sha256_hexkey "${k_signing}" "${string_to_sign}")"
auth="AWS4-HMAC-SHA256 Credential=${ACCESS_KEY}/${scope}, SignedHeaders=${signed_headers}, Signature=${signature}"
url="http://${host_port}${path}${raw_query:+?${raw_query}}"
tmp="$(mktemp)"
if [ -n "${body}" ]; then
curl_body=(-d "${body}")
fi
# Keep whatever -w printed even when curl exits non-zero (e.g. a reset
# keep-alive connection after the response arrived): the body below is
# authoritative proof the transaction completed, and clobbering the code
# to 000 would fail cases that actually succeeded.
code="$(curl -sS --max-time "${API_REQUEST_TIMEOUT}" -o "${tmp}" -w '%{http_code}' \
-H "Host: ${host_port}" \
-H "Content-Type: ${content_type}" \
-H "x-amz-content-sha256: UNSIGNED-PAYLOAD" \
-H "x-amz-date: ${amz_date}" \
-H "Authorization: ${auth}" \
"${curl_body[@]}" -X "${method}" "${url}")"
[ -n "${code}" ] || code="000"
# Publish via a file, not a variable: callers invoke signed_request inside
# $(...) command substitution, and a variable set in that subshell can never
# reach the caller's scope.
printf '%s' "${code}" > "${SIGNED_CODE_FILE}"
cat "${tmp}"
rm -f "${tmp}"
}
signed_code() { cat "${SIGNED_CODE_FILE}" 2>/dev/null || printf '000'; }
# admin_api <method> <path> [query] [body] — signed_request on the main site.
admin_api() {
signed_request "${API_ENDPOINT}" "$1" "$2" "${3:-}" "${4:-}" "application/json"
}
# node1_admin_api <method> <path> [query] [body] — signed_request straight to
# the first node. set-remote-target persists the bucket-targets metadata and
# updates only the handling node's in-memory target map; peers converge via
# the 15-minute bucket-metadata refresh loop and get no push notification, so
# target admin calls and replication-rule writes must stick to one node or
# they race that refresh window ("replication config has a stale target").
node1_admin_api() {
signed_request "http://$(endpoint_host_prefix)1:9000" "$1" "$2" "${3:-}" "${4:-}" "application/json"
}
# site2_admin_api <method> <path> [query] [body] — signed_request on site2.
site2_admin_api() {
signed_request "${SITE2_ENDPOINT}" "$1" "$2" "${3:-}" "${4:-}" "application/json"
}
# ==================== Test harness ====================
PASS=0; FAIL=0; UNSUPPORTED=0
FAILED_TESTS=()
run_test() {
local id="$1" name="$2" fn="$3" rc
if [ "${DRY_RUN}" -eq 1 ]; then
printf ' [DRY-RUN] %s %s\n' "${id}" "${name}"
return 0
fi
printf '\n--- %s %s ---\n' "${id}" "${name}"
if "${fn}" > "${TEST_TMP}/test.out" 2>&1; then
PASS=$((PASS+1)); printf '\033[1;32m[PASS]\033[0m %s %s\n' "${id}" "${name}"
else
rc=$?
if [ "${rc}" -eq 2 ]; then
UNSUPPORTED=$((UNSUPPORTED+1)); printf '\033[1;33m[UNSUPPORTED]\033[0m %s %s\n' "${id}" "${name}"
else
FAIL=$((FAIL+1)); FAILED_TESTS+=("${id} ${name}")
printf '\033[1;31m[FAIL]\033[0m %s %s\n' "${id}" "${name}"
sed 's/^/ | /' "${TEST_TMP}/test.out" | tail -40
fi
fi
}
aws_run() {
AWS_OUT="$(aws --endpoint-url "${API_ENDPOINT}" --region "${REGION}" "$@" 2>&1)"; AWS_CODE=$?
}
# aws_run_node1 <aws args...> — same as aws_run but straight at the first
# node. put-bucket-replication validates the rule's destination ARN against
# the handling node's cached bucket-targets, so it must land on the same node
# where set-remote-target registered the target (see node1_admin_api).
aws_run_node1() {
AWS_OUT="$(aws --endpoint-url "http://$(endpoint_host_prefix)1:9000" --region "${REGION}" "$@" 2>&1)"; AWS_CODE=$?
}
# node2_admin_api <method> <path> [query] [body] — signed_request straight to
# the second node. rustfs/backlog#2194: set-remote-target updates only the
# handling node's in-memory target map; peers historically converged only via
# the 15-minute bucket-metadata refresh loop. REP-109 asserts the fixed
# read-your-writes contract instead of pinning calls to node 1.
node2_admin_api() {
signed_request "http://$(endpoint_host_prefix)2:9000" "$1" "$2" "${3:-}" "${4:-}" "application/json"
}
# aws_run_node2 <aws args...> — same as aws_run but straight at the second
# node (cross-node rule write for REP-109).
aws_run_node2() {
AWS_OUT="$(aws --endpoint-url "http://$(endpoint_host_prefix)2:9000" --region "${REGION}" "$@" 2>&1)"; AWS_CODE=$?
}
aws_run_site2() {
AWS_OUT="$(aws --endpoint-url "${SITE2_ENDPOINT}" --region "${REGION}" "$@" 2>&1)"; AWS_CODE=$?
}
assert_aws_ok() {
[ "${AWS_CODE}" -eq 0 ] || { echo "aws failed (exit ${AWS_CODE}): $*"; echo "${AWS_OUT}"; return 1; }
}
md5_of_file() { md5sum "$1" 2>/dev/null | awk '{print $1}'; }
make_test_file() {
local path="$1" size="$2"
if [ "${size}" -eq 0 ]; then : > "${path}"; else head -c "${size}" /dev/urandom > "${path}"; fi
}
results_summary() {
printf '\n========================================\n'
printf 'RESULTS: PASS=%d FAIL=%d UNSUPPORTED=%d\n' "${PASS}" "${FAIL}" "${UNSUPPORTED}"
if [ "${#FAILED_TESTS[@]}" -gt 0 ]; then
printf '\nFailed tests:\n'
local t
for t in "${FAILED_TESTS[@]}"; do printf ' - %s\n' "${t}"; done
fi
}
# aws_wait_ep <endpoint> <desc> <aws args...> — poll until the aws call succeeds.
aws_wait_ep() {
local ep="$1" desc="$2"; shift 2
local waited=0
while [ "${waited}" -lt "${CONVERGE_TIMEOUT}" ]; do
if aws --endpoint-url "${ep}" --region "${REGION}" "$@" >/dev/null 2>&1; then
return 0
fi
sleep "${CONVERGE_INTERVAL}"; waited=$((waited+CONVERGE_INTERVAL))
done
echo "timeout (${CONVERGE_TIMEOUT}s) waiting for: ${desc}"
return 1
}
# ==================== Bucket/object helpers ====================
new_versioned_bucket() {
local ep="$1" b="$2"
if [ "${ep}" = "site2" ]; then aws_run_site2 s3api create-bucket --bucket "${b}";
else aws_run s3api create-bucket --bucket "${b}"; fi
assert_aws_ok "create-bucket ${b}" || return 1
if [ "${ep}" = "site2" ]; then aws_run_site2 s3api put-bucket-versioning --bucket "${b}" \
--versioning-configuration Status=Enabled;
else aws_run s3api put-bucket-versioning --bucket "${b}" \
--versioning-configuration Status=Enabled; fi
assert_aws_ok "put-bucket-versioning ${b}" || return 1
}
bucket_exists() {
local ep="$1" b="$2" url="${API_ENDPOINT}"
[ "${ep}" = "site2" ] && url="${SITE2_ENDPOINT}"
aws --endpoint-url "${url}" --region "${REGION}" s3api head-bucket --bucket "${b}" >/dev/null 2>&1
}
rm_bucket_force() {
# Best-effort recursive bucket removal (versions + delete markers).
# `delete-objects --delete` needs the {"Objects":[...]} document; the bare
# array this used to pass is rejected client-side ("Invalid JSON") before
# any request is sent, so every non-empty versioned bucket survived
# delete-bucket as BucketNotEmpty and leaked into the next suite
# (rustfs/backlog#2479). Batches of 1000 are the delete-objects limit.
local ep="$1" b="$2" i url="${API_ENDPOINT}" payload
[ "${ep}" = "site2" ] && url="${SITE2_ENDPOINT}"
for i in 1 2 3; do
while IFS= read -r payload; do
[ -n "${payload}" ] || continue
aws --endpoint-url "${url}" --region "${REGION}" s3api delete-objects --bucket "${b}" \
--delete "${payload}" >/dev/null 2>&1 || true
done < <(aws --endpoint-url "${url}" --region "${REGION}" s3api list-object-versions \
--bucket "${b}" --output json 2>/dev/null \
| jq -c -L "${JQ_LIB}" 'include "jq_nwise"; [.Versions[]?, .DeleteMarkers[]?] | map({Key, VersionId}) | select(length > 0) | nwise(1000)[] | {Objects: ., Quiet: true}')
aws --endpoint-url "${url}" --region "${REGION}" s3api delete-bucket --bucket "${b}" >/dev/null 2>&1 || true
bucket_exists "${ep}" "${b}" || return 0
sleep 2
done
return 0
}
register_replication_target() {
local src="$1" dst="$2" body arn
body="$(jq -nc --arg ep "${SITE2_HOSTPORT}" \
--arg ak "${ACCESS_KEY}" --arg sk "${SECRET_KEY}" --arg tb "${dst}" \
'{endpoint:$ep, credentials:{accessKey:$ak, secretKey:$sk}, targetbucket:$tb, secure:false, skipTlsVerify:false, type:"replication"}')"
arn="$(node1_admin_api PUT "/rustfs/admin/v3/set-remote-target" "bucket=${src}" "${body}")"
if [ "$(signed_code)" != "200" ]; then
echo "set-remote-target HTTP $(signed_code): ${arn}" >&2
return 1
fi
# 200 response body is the JSON-encoded ARN string.
printf '%s' "${arn}" | jq -r 'if type == "string" then . else (.arn // .[0].arn // empty) end'
}
# put_replication_rule <src_bucket> <arn> [delete_marker_status]
put_replication_rule() {
local src="$1" arn="$2" dmr="${3:-Disabled}"
local cfg_json
cfg_json="$(jq -nc --arg dst_arn "${arn}" --arg dmr "${dmr}" '{
Role: "",
Rules: [{
ID: "rule1", Priority: 1, Status: "Enabled",
DeleteMarkerReplication: {Status: $dmr},
ExistingObjectReplication: {Status: "Enabled"},
Destination: {Bucket: $dst_arn}
}]
}')"
aws_run_node1 s3api put-bucket-replication --bucket "${src}" --replication-configuration "${cfg_json}"
assert_aws_ok "put-bucket-replication ${src}" || return 1
}
# ==================== Site replication helpers ====================
site_add_payload() {
# Peers must reach each other by a routable address: the site1 endpoint as
# seen from site2 (running on NODES[0]), not the runner-local API endpoint.
local site1_peer
site1_peer="http://$(endpoint_host_prefix)1:9000"
jq -nc \
--arg n1 "${SITE1_NAME}" --arg e1 "${site1_peer}" \
--arg n2 "${SITE2_NAME}" --arg e2 "${SITE2_ENDPOINT}" \
--arg ak "${ACCESS_KEY}" --arg sk "${SECRET_KEY}" \
'[{name:$n1, endpoints:$e1, accessKey:$ak, secretKey:$sk, skipTlsVerify:false, caCertPem:""},
{name:$n2, endpoints:$e2, accessKey:$ak, secretKey:$sk, skipTlsVerify:false, caCertPem:""}]'
}
# ==================== Bucket replication test cases ====================
run_all_bucket_tests() {
run_test REP-101 "RemoteTargetRegisterListRemove" test_rep101
run_test REP-102 "ReplicationCheckPasses" test_rep102
run_test REP-103 "ReplicationCheckRejectsUnversioned" test_rep103
run_test REP-104 "PutObjectReplicates" test_rep104
run_test REP-105 "DeleteMarkerReplication" test_rep105
run_test REP-106 "RemoveTargetUsedByRule" test_rep106
run_test REP-107 "ExistingObjectResync" test_rep107
run_test REP-108 "MultipartReplicates" test_rep108
run_test REP-109 "PeerTargetVisibility" test_rep109
run_test REP-110 "DeleteReplicatedEndState" test_rep110
run_test REP-111 "ExistingObjectsLateVersioning" test_rep111
}
test_rep101() {
new_versioned_bucket main rep101-src || return 1
new_versioned_bucket site2 rep101-dst || return 1
local arn list
arn="$(register_replication_target rep101-src rep101-dst)" \
|| { rm_bucket_force main rep101-src; rm_bucket_force site2 rep101-dst; return 1; }
case "${arn}" in arn:*) : ;; *) echo "ARN has unexpected shape: ${arn}"; return 1 ;; esac
list="$(node1_admin_api GET "/rustfs/admin/v3/list-remote-targets" "bucket=rep101-src")"
[ "$(signed_code)" = "200" ] || { echo "list-remote-targets HTTP $(signed_code): ${list}"; return 1; }
printf '%s' "${list}" | jq -e --arg arn "${arn}" '.[0].arn == $arn' >/dev/null 2>&1 \
|| { echo "listing does not contain the ARN: ${list}"; return 1; }
node1_admin_api DELETE "/rustfs/admin/v3/remove-remote-target" "bucket=rep101-src&arn=${arn}" >/dev/null
# The handler replies 204 No Content on success.
[ "$(signed_code)" = "200" ] || [ "$(signed_code)" = "204" ] || { echo "remove-remote-target HTTP $(signed_code)"; return 1; }
list="$(node1_admin_api GET "/rustfs/admin/v3/list-remote-targets" "bucket=rep101-src")"
if [ "$(signed_code)" = "200" ]; then
printf '%s' "${list}" | jq -e --arg arn "${arn}" '([.[].arn] | index($arn)) == null' >/dev/null 2>&1 \
|| { echo "ARN still listed after removal: ${list}"; return 1; }
fi
rm_bucket_force main rep101-src
rm_bucket_force site2 rep101-dst
}
# REP-109 asserts the cross-node read-your-writes contract from
# rustfs/backlog#2194: after set-remote-target returns 200 on one node, a
# peer node must immediately (a) list the target and (b) accept a
# put-bucket-replication rule referencing its ARN — without waiting for the
# 15-minute bucket-metadata refresh loop. The pre-fix behavior was an empty
# peer list and `InvalidRequest: replication config has a stale target`.
test_rep109() {
new_versioned_bucket main rep109-src || return 1
new_versioned_bucket site2 rep109-dst || return 1
local arn peer_list cfg_json
arn="$(register_replication_target rep109-src rep109-dst)" \
|| { rm_bucket_force main rep109-src; rm_bucket_force site2 rep109-dst; return 1; }
case "${arn}" in arn:*) : ;; *) echo "ARN has unexpected shape: ${arn}"; return 1 ;; esac
# (a) the peer node must list the target immediately after registration.
peer_list="$(node2_admin_api GET "/rustfs/admin/v3/list-remote-targets" "bucket=rep109-src")"
[ "$(signed_code)" = "200" ] || { echo "peer list-remote-targets HTTP $(signed_code): ${peer_list}"; rm_bucket_force main rep109-src; rm_bucket_force site2 rep109-dst; return 1; }
printf '%s' "${peer_list}" | jq -e --arg arn "${arn}" '([.[].arn] | index($arn)) != null' >/dev/null 2>&1 \
|| { echo "peer node 2 does not see the target right after set-remote-target (backlog#2194): ${peer_list}"; rm_bucket_force main rep109-src; rm_bucket_force site2 rep109-dst; return 1; }
# (b) a replication-rule write handled by the peer must validate the ARN.
cfg_json="$(jq -nc --arg dst_arn "${arn}" '{
Role: "",
Rules: [{
ID: "rule1", Priority: 1, Status: "Enabled",
DeleteMarkerReplication: {Status: "Disabled"},
Destination: {Bucket: $dst_arn}
}]
}')"
aws_run_node2 s3api put-bucket-replication --bucket rep109-src --replication-configuration "${cfg_json}"
assert_aws_ok "cross-node put-bucket-replication (backlog#2194)" \
|| { rm_bucket_force main rep109-src; rm_bucket_force site2 rep109-dst; return 1; }
aws_run s3api delete-bucket-replication --bucket rep109-src
node1_admin_api DELETE "/rustfs/admin/v3/remove-remote-target" "bucket=rep109-src&arn=${arn}" >/dev/null 2>&1 || true
rm_bucket_force main rep109-src
rm_bucket_force site2 rep109-dst
}
test_rep102() {
new_versioned_bucket main rep102-src || return 1
new_versioned_bucket site2 rep102-dst || return 1
local arn body
arn="$(register_replication_target rep102-src rep102-dst)" \
|| { rm_bucket_force main rep102-src; rm_bucket_force site2 rep102-dst; return 1; }
put_replication_rule rep102-src "${arn}" \
|| { rm_bucket_force main rep102-src; rm_bucket_force site2 rep102-dst; return 1; }
body="$(signed_request "http://$(endpoint_host_prefix)1:9000" GET "/rep102-src" "replication-check")"
[ "$(signed_code)" = "200" ] \
|| { echo "replication-check HTTP $(signed_code): ${body}"; rm_bucket_force main rep102-src; rm_bucket_force site2 rep102-dst; return 1; }
printf '%s' "${body}" | jq -e '.Status == "OK"' >/dev/null 2>&1 \
|| { echo "replication-check not OK: ${body}"; rm_bucket_force main rep102-src; rm_bucket_force site2 rep102-dst; return 1; }
rm_bucket_force main rep102-src
rm_bucket_force site2 rep102-dst
}
test_rep103() {
# replication-check must reject a bucket without versioning (400 + "versioning").
aws_run s3api create-bucket --bucket rep103-src
assert_aws_ok "create-bucket rep103-src" || return 1
local body
body="$(signed_request "${API_ENDPOINT}" GET "/rep103-src" "replication-check")"
rm_bucket_force main rep103-src
[ "$(signed_code)" = "400" ] || { echo "expected 400 for unversioned bucket, got $(signed_code): ${body}"; return 1; }
printf '%s' "${body}" | grep -qi "versioning" || { echo "error missing 'versioning': ${body}"; return 1; }
}
test_rep104() {
new_versioned_bucket main rep104-src || return 1
new_versioned_bucket site2 rep104-dst || return 1
local arn
arn="$(register_replication_target rep104-src rep104-dst)" \
|| { rm_bucket_force main rep104-src; rm_bucket_force site2 rep104-dst; return 1; }
put_replication_rule rep104-src "${arn}" \
|| { rm_bucket_force main rep104-src; rm_bucket_force site2 rep104-dst; return 1; }
make_test_file "${TEST_TMP}/rep104-v" 65536
aws_run s3api put-object --bucket "rep104-src" --key data.bin --body "${TEST_TMP}/rep104-v"
assert_aws_ok "put-object data.bin" \
|| { rm_bucket_force main rep104-src; rm_bucket_force site2 rep104-dst; return 1; }
aws_wait_ep "${SITE2_ENDPOINT}" "object replicated to rep104-dst" \
s3api head-object --bucket rep104-dst --key data.bin \
|| { rm_bucket_force main rep104-src; rm_bucket_force site2 rep104-dst; return 1; }
aws_run_site2 s3api get-object --bucket "rep104-dst" --key data.bin "${TEST_TMP}/rep104-dl"
assert_aws_ok "get-object from target" \
|| { rm_bucket_force main rep104-src; rm_bucket_force site2 rep104-dst; return 1; }
[ "$(md5_of_file "${TEST_TMP}/rep104-dl")" = "$(md5_of_file "${TEST_TMP}/rep104-v")" ] \
|| { echo "replicated object MD5 mismatch"; rm_bucket_force main rep104-src; rm_bucket_force site2 rep104-dst; return 1; }
rm_bucket_force main rep104-src
rm_bucket_force site2 rep104-dst
}
test_rep105() {
new_versioned_bucket main rep105-src || return 1
new_versioned_bucket site2 rep105-dst || return 1
local arn
arn="$(register_replication_target rep105-src rep105-dst)" \
|| { rm_bucket_force main rep105-src; rm_bucket_force site2 rep105-dst; return 1; }
put_replication_rule rep105-src "${arn}" "Enabled" \
|| { rm_bucket_force main rep105-src; rm_bucket_force site2 rep105-dst; return 1; }
make_test_file "${TEST_TMP}/rep105-v" 128
aws_run s3api put-object --bucket "rep105-src" --key m.txt --body "${TEST_TMP}/rep105-v"
assert_aws_ok "put-object m.txt" \
|| { rm_bucket_force main rep105-src; rm_bucket_force site2 rep105-dst; return 1; }
aws_wait_ep "${SITE2_ENDPOINT}" "initial object on target" \
s3api head-object --bucket rep105-dst --key m.txt \
|| { rm_bucket_force main rep105-src; rm_bucket_force site2 rep105-dst; return 1; }
aws_run s3api delete-object --bucket "rep105-src" --key m.txt
assert_aws_ok "delete-object m.txt" \
|| { rm_bucket_force main rep105-src; rm_bucket_force site2 rep105-dst; return 1; }
aws_wait_ep "${SITE2_ENDPOINT}" "delete marker replicated" \
s3api list-object-versions --bucket rep105-dst --prefix m.txt --output json \
--query 'length(DeleteMarkers || `[]`) > `0`' --output text \
|| { rm_bucket_force main rep105-src; rm_bucket_force site2 rep105-dst; return 1; }
rm_bucket_force main rep105-src
rm_bucket_force site2 rep105-dst
}
test_rep106() {
new_versioned_bucket main rep106-src || return 1
new_versioned_bucket site2 rep106-dst || return 1
local arn body
arn="$(register_replication_target rep106-src rep106-dst)" \
|| { rm_bucket_force main rep106-src; rm_bucket_force site2 rep106-dst; return 1; }
put_replication_rule rep106-src "${arn}" \
|| { rm_bucket_force main rep106-src; rm_bucket_force site2 rep106-dst; return 1; }
# Removing a target still referenced by a replication rule must be rejected
# with 400 "removal disallowed".
body="$(node1_admin_api DELETE "/rustfs/admin/v3/remove-remote-target" "bucket=rep106-src&arn=${arn}")"
[ "$(signed_code)" = "400" ] \
|| { echo "expected 400 removing an in-use target, got $(signed_code): ${body}"; rm_bucket_force main rep106-src; rm_bucket_force site2 rep106-dst; return 1; }
printf '%s' "${body}" | grep -qi "disallowed" \
|| { echo "error missing 'disallowed': ${body}"; rm_bucket_force main rep106-src; rm_bucket_force site2 rep106-dst; return 1; }
rm_bucket_force main rep106-src
rm_bucket_force site2 rep106-dst
}
test_rep107() {
new_versioned_bucket main rep107-src || return 1
new_versioned_bucket site2 rep107-dst || return 1
make_test_file "${TEST_TMP}/rep107-v" 4096
aws_run s3api put-object --bucket "rep107-src" --key preexisting.bin --body "${TEST_TMP}/rep107-v"
assert_aws_ok "put-object preexisting.bin" \
|| { rm_bucket_force main rep107-src; rm_bucket_force site2 rep107-dst; return 1; }
local arn body
arn="$(register_replication_target rep107-src rep107-dst)" \
|| { rm_bucket_force main rep107-src; rm_bucket_force site2 rep107-dst; return 1; }
put_replication_rule rep107-src "${arn}" \
|| { rm_bucket_force main rep107-src; rm_bucket_force site2 rep107-dst; return 1; }
# Existing-object resync: PUT ?replication-reset, response target[0].arn/resetid.
body="$(signed_request "http://$(endpoint_host_prefix)1:9000" PUT "/rep107-src" "replication-reset")"
[ "$(signed_code)" = "200" ] \
|| { echo "replication-reset HTTP $(signed_code): ${body}"; rm_bucket_force main rep107-src; rm_bucket_force site2 rep107-dst; return 1; }
printf '%s' "${body}" | jq -e '.target[0].arn != null and .target[0].resetid != null' >/dev/null 2>&1 \
|| { echo "replication-reset response missing target[0].arn/resetid: ${body}"; rm_bucket_force main rep107-src; rm_bucket_force site2 rep107-dst; return 1; }
aws_wait_ep "${SITE2_ENDPOINT}" "existing object replicated after resync" \
s3api head-object --bucket rep107-dst --key preexisting.bin \
|| { rm_bucket_force main rep107-src; rm_bucket_force site2 rep107-dst; return 1; }
rm_bucket_force main rep107-src
rm_bucket_force site2 rep107-dst
}
test_rep108() {
new_versioned_bucket main rep108-src || return 1
new_versioned_bucket site2 rep108-dst || return 1
local arn
arn="$(register_replication_target rep108-src rep108-dst)" \
|| { rm_bucket_force main rep108-src; rm_bucket_force site2 rep108-dst; return 1; }
put_replication_rule rep108-src "${arn}" \
|| { rm_bucket_force main rep108-src; rm_bucket_force site2 rep108-dst; return 1; }
make_test_file "${TEST_TMP}/rep108-chunk" 5242880
aws_run s3api create-multipart-upload --bucket "rep108-src" --key mp.bin
assert_aws_ok "create-multipart-upload" \
|| { rm_bucket_force main rep108-src; rm_bucket_force site2 rep108-dst; return 1; }
local upload_id etag parts_json="[]" i
upload_id="$(printf '%s' "${AWS_OUT}" | jq -r '.UploadId')"
for i in 1 2; do
aws_run s3api upload-part --bucket "rep108-src" --key mp.bin --upload-id "${upload_id}" \
--part-number "${i}" --body "${TEST_TMP}/rep108-chunk"
assert_aws_ok "upload-part ${i}" \
|| { rm_bucket_force main rep108-src; rm_bucket_force site2 rep108-dst; return 1; }
etag="$(printf '%s' "${AWS_OUT}" | jq -r '.ETag | fromjson? // .')"
parts_json="$(printf '%s' "${parts_json}" | jq -c --argjson pn "${i}" --arg e "${etag}" '. + [{ETag:$e, PartNumber:$pn}]')"
done
aws_run s3api complete-multipart-upload --bucket "rep108-src" --key mp.bin --upload-id "${upload_id}" \
--multipart-upload "{\"Parts\":$(printf '%s' "${parts_json}" | jq -c '.')}"
assert_aws_ok "complete-multipart-upload" \
|| { rm_bucket_force main rep108-src; rm_bucket_force site2 rep108-dst; return 1; }
aws_wait_ep "${SITE2_ENDPOINT}" "multipart object replicated" \
s3api head-object --bucket rep108-dst --key mp.bin \
|| { rm_bucket_force main rep108-src; rm_bucket_force site2 rep108-dst; return 1; }
rm_bucket_force main rep108-src
rm_bucket_force site2 rep108-dst
}
test_rep110() {
# rustfs#8746: after a replicated delete the target must honor the delete,
# not keep serving the old object: the key must 404 on HEAD and vanish
# from ListObjectsV2. REP-105 only asserts the marker arrives; this case
# asserts the user-visible end state.
new_versioned_bucket main rep110-src || return 1
new_versioned_bucket site2 rep110-dst || return 1
local arn
arn="$(register_replication_target rep110-src rep110-dst)" \
|| { rm_bucket_force main rep110-src; rm_bucket_force site2 rep110-dst; return 1; }
put_replication_rule rep110-src "${arn}" "Enabled" \
|| { rm_bucket_force main rep110-src; rm_bucket_force site2 rep110-dst; return 1; }
make_test_file "${TEST_TMP}/rep110-v" 4096
aws_run s3api put-object --bucket "rep110-src" --key gone.txt --body "${TEST_TMP}/rep110-v"
assert_aws_ok "put-object gone.txt" \
|| { rm_bucket_force main rep110-src; rm_bucket_force site2 rep110-dst; return 1; }
aws_wait_ep "${SITE2_ENDPOINT}" "object on target" \
s3api head-object --bucket rep110-dst --key gone.txt \
|| { rm_bucket_force main rep110-src; rm_bucket_force site2 rep110-dst; return 1; }
aws_run s3api delete-object --bucket "rep110-src" --key gone.txt
assert_aws_ok "delete-object gone.txt" \
|| { rm_bucket_force main rep110-src; rm_bucket_force site2 rep110-dst; return 1; }
# Wait for the delete marker to arrive, then assert the end state: HEAD
# must 404 and the listing must be empty.
aws_wait_ep "${SITE2_ENDPOINT}" "delete marker on target" \
s3api list-object-versions --bucket rep110-dst --prefix gone.txt \
--query 'length(DeleteMarkers || `[]`) > `0`' --output text \
|| { rm_bucket_force main rep110-src; rm_bucket_force site2 rep110-dst; return 1; }
local deadline=$(( $(date +%s) + 120 )) gone=0
while [ "$(date +%s)" -lt "${deadline}" ]; do
aws_run_site2 s3api head-object --bucket rep110-dst --key gone.txt
if [ "${AWS_CODE}" -ne 0 ]; then
printf '%s' "${AWS_OUT}" | grep -q 'Not Found' \