Repository navigation
Expand file tree
/
Copy pathrustfs-storage-test.sh
More file actions
executable file
·1551 lines (1425 loc) · 66.7 KB
/
Copy pathrustfs-storage-test.sh
File metadata and controls
executable file
·1551 lines (1425 loc) · 66.7 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-storage-test.sh
# RustFS storage engine test suite (STOR-*, backlog #2024): disk compression,
# inline data, object data cache, stored-representation preservation, storage
# checksum detection, and physical capacity accounting.
#
# The suite drives the S3 API (aws/rc) for user-visible behavior and the
# SigV4-signed admin API for cache/storage-info checks. Disk-level assertions
# (part file sizes, inline representation) run over SSH against the node data
# dirs (/data/rustfs*/mnmd/<bucket>/...).
#
# Server-side knobs written into /etc/default/rustfs on every node:
# RUSTFS_COMPRESSION_ENABLED=true
# RUSTFS_COMPRESSION_MULTIPART_ENABLED=true
# RUSTFS_OBJECT_DATA_CACHE_ENABLE=true
# RUSTFS_COMPRESS_ENABLE=true (HTTP response compression)
# RUSTFS_SSE_S3_MASTER_KEY=<32-byte b64> (SSE-S3)
#
# Usage:
# ./rustfs-storage-test.sh --topology multi-multi -y
# ./rustfs-storage-test.sh --all-topologies -y --package-url <nightly deb URL>
# ./rustfs-storage-test.sh --topology multi-multi --dry-run
#
# Notes:
# - Requires ssh to the test nodes, and rc/aws/jq/curl/openssl on the runner.
# - rc exit code 7 means the command is gated/unsupported; those cases are
# reported as UNSUPPORTED, not FAIL.
#
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ==================== Configuration ====================
if [ -n "${RUSTFS_NODES:-}" ]; then
read -r -a NODES <<<"${RUSTFS_NODES}"
else
NODES=(vm000 vm001 vm002 vm003)
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
ADMIN_API_CODE_FILE="${TMPDIR:-/tmp}/rustfs-storage-api-code.$$"
SSE_S3_MASTER_KEY="${RUSTFS_SSE_S3_MASTER_KEY:-MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=}"
RUSTFS_CONFIG_FILE="/etc/default/rustfs"
RUSTFS_SERVICE="rustfs"
RUSTFS_PACKAGE_NAME="rustfs"
RUSTFS_USER="rustfs"
RUSTFS_ADDRESS=":9000"
RUSTFS_CONSOLE_ADDRESS=":9001"
RUSTFS_CONSOLE_ENABLE=true
RUSTFS_OBS_LOGGER_LEVEL=error
RUSTFS_OBS_LOG_DIRECTORY="/var/log/rustfs/"
TOPO_SINGLE_SINGLE="single-single"
TOPO_SINGLE_MULTI="single-multi"
TOPO_MULTI_MULTI="multi-multi"
TOPO_ILM_2X4="ilm-2x4"
ENDPOINT_SINGLE_SINGLE="http://rustfs-node1:9000"
ENDPOINT_SINGLE_MULTI="http://rustfs-node1:9000"
ENDPOINT_MULTI_MULTI="http://rustfs-node1:9000"
VOLUMES_SINGLE_SINGLE="/data/rustfs1/mnmd"
VOLUMES_SINGLE_MULTI="/data/rustfs{1...4}/mnmd"
VOLUMES_MULTI_MULTI="http://rustfs-node{1...4}:9000/data/rustfs{1...4}/mnmd"
VOLUMES_ILM_2X4="http://rustfs-node{1...2}:9000/data/rustfs{1...4}/mnmd"
ILM_TIER_ENDPOINT="http://rustfs-node3:9000"
SERVICE_TIMEOUT=300
# ==================== Runtime options ====================
DRY_RUN=0
ASSUME_YES=0
KEEP_ENV=0
LOG_FILE=""
SELECTED_TOPOLOGIES=()
CURRENT_TOPOLOGY=""
ENDPOINT=""
VOLUMES=""
VALIDATION_CASE=""
VALIDATION_SOURCE_CASE_ID=""
SELECTED_CASES=""
VALIDATION_ARTIFACTS_DIR=""
VALIDATION_CANDIDATE_MANIFEST=""
VALIDATION_TESTING_COMMIT=""
VALIDATION_BINARY_SHA256=""
VALIDATION_OBJECT_CLEANUP_STATUS=PASS
TEST_TMP="$(mktemp -d "${TMPDIR:-/tmp}/rustfs-storage.XXXXXX")"
trap 'rm -rf "${TEST_TMP}"; rm -f "${ADMIN_API_CODE_FILE}"' EXIT
# ==================== 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
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" waited=0
[ "${DRY_RUN}" -eq 1 ] && { log "DRY-RUN: wait ${RUSTFS_SERVICE} active on ${node}"; return 0; }
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" "systemctl is-active --quiet ${RUSTFS_SERVICE}" 2>/dev/null; then
log "${node}: ${RUSTFS_SERVICE} is active"; return 0
fi
sleep 5; waited=$((waited+5))
done
die "${node}: timed out waiting for ${RUSTFS_SERVICE} (${SERVICE_TIMEOUT}s)"
}
rustfs_config_body() {
local volumes="$1"
cat <<EOF
RUSTFS_ACCESS_KEY=${ACCESS_KEY}
RUSTFS_SECRET_KEY=${SECRET_KEY}
RUSTFS_VOLUMES="${volumes}"
RUSTFS_SSE_S3_MASTER_KEY=${SSE_S3_MASTER_KEY}
RUSTFS_COMPRESSION_ENABLED=true
RUSTFS_COMPRESSION_MULTIPART_ENABLED=true
RUSTFS_OBJECT_DATA_CACHE_ENABLE=true
RUSTFS_COMPRESS_ENABLE=true
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}"
EOF
if [ "${VALIDATION_CASE}" = "scanner.usage-convergence" ] || [ "${VALIDATION_CASE}" = "scanner.status-readiness" ]; then
printf 'RUSTFS_SCANNER_ENABLED=true\nRUSTFS_SCANNER_CYCLE=5\nRUSTFS_SCANNER_START_DELAY_SECS=0\n'
elif [[ "${VALIDATION_CASE}" == ilm.* ]]; then
if [ "${VALIDATION_CASE}" = ilm.immediate-transition-and-restore ]; then
printf 'RUSTFS_SCANNER_ENABLED=false\n'
else
printf 'RUSTFS_SCANNER_ENABLED=true\nRUSTFS_SCANNER_CYCLE=2\nRUSTFS_SCANNER_START_DELAY_SECS=0\n'
fi
printf 'RUSTFS_DATA_USAGE_UPDATE_DIR_CYCLES=1\nRUSTFS_ILM_DEBUG_DAY_SECS=10\nRUSTFS_ILM_PROCESS_TIME=1\n'
printf 'RUSTFS_API_STALE_UPLOADS_CLEANUP_INTERVAL=2s\n'
printf 'HTTP_PROXY=\nHTTPS_PROXY=\nALL_PROXY=\nhttp_proxy=\nhttps_proxy=\nall_proxy=\n'
fi
}
write_rustfs_config() {
local node="$1" volumes="$2" body
body="$(rustfs_config_body "${volumes}")"
log "${node}: writing config ${RUSTFS_CONFIG_FILE} (volumes=${volumes})"
{
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); fi\n' "${RUSTFS_CONFIG_FILE}" "${RUSTFS_CONFIG_FILE}" "${RUSTFS_CONFIG_FILE}"
printf '%s tee %s >/dev/null <<RUSTFS_EOF\n' '${SUDO}' "${RUSTFS_CONFIG_FILE}"
printf '%s' "${body}"
printf '\nRUSTFS_EOF\n'
printf '${SUDO} systemctl daemon-reload\n'
} | run_remote "${node}"
}
service_action() {
local action="$1" node="$2"
log "${node}: systemctl ${action} ${RUSTFS_SERVICE}"
[ "${DRY_RUN}" -eq 1 ] && return 0
ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" \
"if [ \"\$(id -u)\" -ne 0 ]; then sudo -n systemctl ${action} ${RUSTFS_SERVICE}; else systemctl ${action} ${RUSTFS_SERVICE}; fi" \
|| die "${node}: systemctl ${action} failed"
}
start_and_wait_nodes() {
local nodes=("$@") pids=() i=0 fail=0
for node in "${nodes[@]}"; do service_action start "${node}" & pids[$i]=$!; i=$((i+1)); done
if [ "${#pids[@]}" -gt 0 ]; then
for pid in "${pids[@]}"; do wait "${pid}" || fail=1; done
fi
[ "${fail}" -eq 0 ] || die "systemctl start failed on one or more nodes"
for node in "${nodes[@]}"; do wait_service_active "${node}"; done
}
cleanup_node() {
local node="$1"
log "cleanup: purge ${RUSTFS_PACKAGE_NAME} and remove data dirs 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' "${RUSTFS_SERVICE}"
printf 'if ${SUDO} dpkg -l %s 2>/dev/null | grep -q "^ii"; then ${SUDO} dpkg -P %s; fi\n' "${RUSTFS_PACKAGE_NAME}" "${RUSTFS_PACKAGE_NAME}"
printf 'for i in 1 2 3 4; do ${SUDO} rm -rf /data/rustfs${i}/mnmd; done\n'
printf '${SUDO} rm -rf /var/log/rustfs /var/lib/rustfs/kms /var/lib/rustfs/kms-backup\n'
} | run_remote "${node}"
}
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}"
}
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
}
# ==================== Topology / environment ====================
ilm_case_uses_tier() {
case "${VALIDATION_CASE}" in
ilm.transition-and-restore|ilm.immediate-transition-and-restore) return 0 ;;
*) return 1 ;;
esac
}
resolve_topology() {
case "$1" in
"${TOPO_SINGLE_SINGLE}") ENDPOINT="${ENDPOINT_SINGLE_SINGLE}"; VOLUMES="${VOLUMES_SINGLE_SINGLE}"; return 0 ;;
"${TOPO_SINGLE_MULTI}") ENDPOINT="${ENDPOINT_SINGLE_MULTI}"; VOLUMES="${VOLUMES_SINGLE_MULTI}"; return 0 ;;
"${TOPO_MULTI_MULTI}") ENDPOINT="${ENDPOINT_MULTI_MULTI}"; VOLUMES="${VOLUMES_MULTI_MULTI}"; return 0 ;;
"${TOPO_ILM_2X4}") ENDPOINT="${ENDPOINT_SINGLE_MULTI}"; VOLUMES="${VOLUMES_ILM_2X4}"; return 0 ;;
*) die "unknown topology: $1 (single-single|single-multi|multi-multi)" ;;
esac
}
topology_nodes() {
case "$1" in
"${TOPO_SINGLE_SINGLE}"|"${TOPO_SINGLE_MULTI}") printf '%s' "${NODES[0]}" ;;
"${TOPO_ILM_2X4}")
if ilm_case_uses_tier; then
printf '%s %s %s' "${NODES[0]}" "${NODES[1]}" "${NODES[2]}"
else
printf '%s %s' "${NODES[0]}" "${NODES[1]}"
fi ;;
*) printf '%s' "${NODES[*]}" ;;
esac
}
env_setup() {
local topo="$1" nodes_str nodes=() url script
resolve_topology "${topo}"
read -r -a nodes <<<"$(topology_nodes "${topo}")"
url="$(resolve_package_url)"
log "environment setup: topology=${topo} nodes=${nodes[*]} endpoint=${ENDPOINT}"
for node in "${NODES[@]}"; do cleanup_node "${node}"; done
script="$(cat <<EOF
set -euo pipefail
SUDO=""; [ "\$(id -u)" -ne 0 ] && SUDO="sudo -n"
\${SUDO} mkdir -p "${PACKAGES_DIR}"
pkg_tmp="\$(mktemp /tmp/rustfs-pkg.XXXXXX.deb)"
curl -fSL --retry 3 -o "\${pkg_tmp}" "${url}"
\${SUDO} install -m 0644 "\${pkg_tmp}" "${PACKAGES_DIR}/${PACKAGE_FILE}"
rm -f "\${pkg_tmp}"
if [ -n "${PACKAGE_SHA256}" ]; then
echo "${PACKAGE_SHA256} ${PACKAGES_DIR}/${PACKAGE_FILE}" | sha256sum -c - || exit 1
fi
ls -lh "${PACKAGES_DIR}/${PACKAGE_FILE}"
EOF
)"
printf '%s\n' "${script}" | run_remote_all
script="$(cat <<'EOF'
set -euo pipefail
SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"
${SUDO} dpkg -i --force-confold /home/rustfs/packages/rustfs.deb
${SUDO} systemctl daemon-reload
EOF
)"
for node in "${nodes[@]}"; do printf '%s\n' "${script}" | run_remote "${node}"; done
for node in "${nodes[@]}"; do
if ilm_case_uses_tier && [ "${node}" = "${NODES[2]}" ]; then
VALIDATION_CASE="" write_rustfs_config "${node}" "${VOLUMES_SINGLE_SINGLE}"
ensure_volume_dirs "${node}" "${VOLUMES_SINGLE_SINGLE}"
else
write_rustfs_config "${node}" "${VOLUMES}"
ensure_volume_dirs "${node}" "${VOLUMES}"
fi
done
start_and_wait_nodes "${nodes[@]}"
if [ "${DRY_RUN}" -eq 0 ]; then
local waited=0
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if curl -fsS --max-time 5 "${ENDPOINT}/minio/health/live" >/dev/null 2>&1; then
log "S3 endpoint ready: ${ENDPOINT}"; break
fi
sleep 5; waited=$((waited+5))
done
[ "${waited}" -lt "${SERVICE_TIMEOUT}" ] || die "S3 endpoint ${ENDPOINT} not ready"
if ilm_case_uses_tier; then
waited=0
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if curl --noproxy '*' -fsS --max-time 5 "${ILM_TIER_ENDPOINT}/minio/health/live" >/dev/null 2>&1; then
log "ILM warm tier ready: ${ILM_TIER_ENDPOINT}"; break
fi
sleep 5; waited=$((waited+5))
done
[ "${waited}" -lt "${SERVICE_TIMEOUT}" ] || die "ILM warm tier ${ILM_TIER_ENDPOINT} not ready"
fi
rc alias set local "${ENDPOINT}" "${ACCESS_KEY}" "${SECRET_KEY}" >/dev/null 2>&1 \
|| die "rc alias set failed for ${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
log "rc alias 'local' -> ${ENDPOINT}; aws env configured (region ${REGION})"
fi
}
env_teardown() {
local topo="$1" nodes_str nodes=()
read -r -a nodes <<<"$(topology_nodes "${topo}")"
log "environment teardown: ${topo}"
for node in "${NODES[@]}"; do cleanup_node "${node}"; done
}
# ==================== SigV4 admin API ====================
sha256_hex() {
printf '%s' "$1" | openssl dgst -sha256 -hex 2>/dev/null | awk '{print $NF}'
}
hmac_sha256_hex() {
# $1: key in hex, $2: ascii data
printf '%s' "$2" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$1" -hex 2>/dev/null | awk '{print $NF}'
}
hex_of_ascii() {
# $1: ascii string -> hex
printf '%s' "$1" | od -An -vtx1 | tr -d ' \n'
}
# 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 '&' -
}
# admin_api <method> <path> [<query>] [<body>] [discard]
admin_api() {
local method="$1" path="$2" query="${3:-}" body="${4:-}" discard="${5:-}"
local amz_date date_stamp host_port
local canonical_headers signed_headers canonical_request string_to_sign
local scope k_date k_region k_service k_signing signature auth
local url tmp code
if [ "${DRY_RUN}" -eq 1 ]; then
log "DRY-RUN: admin API ${method} ${API_ENDPOINT}${path}${query:+?${query}}"
printf '200' > "${ADMIN_API_CODE_FILE}"
return 0
fi
host_port="${API_ENDPOINT#*://}"
host_port="${host_port%%/*}"
amz_date="$(date -u +%Y%m%dT%H%M%SZ)"
date_stamp="${amz_date:0:8}"
query="$(canonical_query "${query}")"
canonical_headers="host:${host_port}
x-amz-content-sha256:UNSIGNED-PAYLOAD
x-amz-date:${amz_date}
"
signed_headers="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_date="$(hmac_sha256_hex "$(hex_of_ascii "AWS4${SECRET_KEY}")" "${date_stamp}")"
k_region="$(hmac_sha256_hex "${k_date}" "${SIGV4_REGION}")"
k_service="$(hmac_sha256_hex "${k_region}" "${SIGV4_SERVICE}")"
k_signing="$(hmac_sha256_hex "${k_service}" "aws4_request")"
signature="$(hmac_sha256_hex "${k_signing}" "${string_to_sign}")"
auth="AWS4-HMAC-SHA256 Credential=${ACCESS_KEY}/${scope}, SignedHeaders=${signed_headers}, Signature=${signature}"
url="http://${host_port}${path}${query:+?${query}}"
tmp="$(mktemp)"
local curl_body=()
if [ -n "${body}" ]; then
curl_body=(-d "${body}" -H "Content-Type: application/json")
fi
local out_file="${tmp}"
[ "${discard}" = "discard" ] && out_file="/dev/null"
code="$(curl -sS --max-time "${API_REQUEST_TIMEOUT}" -o "${out_file}" -w '%{http_code}' \
-H "Host: ${host_port}" \
-H "x-amz-content-sha256: UNSIGNED-PAYLOAD" \
-H "x-amz-date: ${amz_date}" \
-H "Authorization: ${auth}" \
"${curl_body[@]}" -X "${method}" "${url}")" || code="000"
printf '%s' "${code}" > "${ADMIN_API_CODE_FILE}"
if [ "${discard}" != "discard" ]; then
cat "${tmp}"
fi
rm -f "${tmp}"
}
admin_api_code() {
cat "${ADMIN_API_CODE_FILE}"
}
# ==================== Test harness ====================
PASS=0; FAIL=0; UNSUPPORTED=0
FAILED_TESTS=()
run_test() {
local id="$1" name="$2" fn="$3" out rc
if [ -n "${SELECTED_CASES:-}" ]; then
case ",${SELECTED_CASES:-}," in
*",${id},"*) ;;
*) return 0 ;;
esac
fi
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
}
validation_write_evidence() {
local evidence_dir="${VALIDATION_ARTIFACTS_DIR}/evidence/${VALIDATION_CASE}" item
mkdir -p "${evidence_dir}"
cp "${TEST_TMP}/test.out" "${evidence_dir}/test.log"
for item in $(validation_evidence_items); do
if [ -f "${TEST_TMP}/${item}" ]; then cp "${TEST_TMP}/${item}" "${evidence_dir}/${item}"; fi
done
if [[ "${VALIDATION_CASE}" == ilm.* ]] && [ -d "${TEST_TMP}/ilm-evidence" ]; then
cp -R "${TEST_TMP}/ilm-evidence" "${evidence_dir}/ilm"
fi
}
validation_evidence_items() {
case "${VALIDATION_CASE}" in
scanner.usage-convergence)
printf '%s\n' validation-fixture.json validation-list.json validation-baseline-usage.json validation-scanner.json validation-usage.json ;;
scanner.status-readiness)
printf '%s\n' validation-scanner-node1.json validation-scanner-node2.json validation-scanner-contract.json ;;
esac
}
validation_write_result() {
local verdict="$1" reason="$2" cleanup_status="$3" item
local profile=single-4disk
if [ "${VALIDATION_CASE}" = scanner.status-readiness ] || [[ "${VALIDATION_CASE}" == ilm.* ]]; then
profile=ilm-2x4
fi
local args=("${SCRIPT_DIR}/scripts/validation_result.py"
--case-id "${VALIDATION_CASE}" --profile "${profile}"
--result-file "${VALIDATION_ARTIFACTS_DIR}/cases/${VALIDATION_CASE}.json"
--verdict "${verdict}" --cleanup-status "${cleanup_status}")
if [ -n "${reason}" ]; then args+=(--reason "${reason}"); fi
if [ "${verdict}" != RUNNING ]; then
args+=(--candidate-manifest "${VALIDATION_CANDIDATE_MANIFEST}"
--rc-bin "$(command -v rc)" --testing-commit "${VALIDATION_TESTING_COMMIT}"
--binary-sha256 "${VALIDATION_BINARY_SHA256}"
--evidence "evidence/${VALIDATION_CASE}/test.log")
fi
if [ "${verdict}" = PASS ]; then
for item in $(validation_evidence_items); do
args+=(--evidence "evidence/${VALIDATION_CASE}/${item}")
done
if [[ "${VALIDATION_CASE}" == ilm.* ]]; then
local evidence_root="${VALIDATION_ARTIFACTS_DIR}/evidence/${VALIDATION_CASE}"
local evidence_file
while IFS= read -r -d '' evidence_file; do
args+=(--evidence "${evidence_file#"${VALIDATION_ARTIFACTS_DIR}/"}")
done < <(find "${evidence_root}/ilm" -type f -print0 | sort -z)
fi
fi
python3 "${args[@]}"
}
test_validation_ilm_case() {
local harness_dir="${TEST_TMP}/ilm-evidence" harness_rc=0
local -a ilm_args=()
if [ "${VALIDATION_CASE}" = ilm.restart-persistence ] || [ "${VALIDATION_CASE}" = ilm.immediate-transition-and-restore ]; then
ilm_args+=(--restart-hook "$(python3 -c 'import json,sys; print(json.dumps(sys.argv[1:]))' \
bash "${SCRIPT_DIR}/scripts/validation_ilm/restart_cluster.sh" "${NODES[0]}" "${NODES[1]}")")
fi
if ilm_case_uses_tier; then
ilm_args+=(--tier-endpoint "${ILM_TIER_ENDPOINT}"
--tier-access-key "${ACCESS_KEY}" --tier-secret-key "${SECRET_KEY}")
fi
python3 -B "${SCRIPT_DIR}/scripts/validation_ilm/ilm_behavior.py" \
--case "${VALIDATION_CASE}" \
--endpoint "${ENDPOINT}" \
--scanner-endpoint "http://rustfs-node1:9000" \
--scanner-endpoint "http://rustfs-node2:9000" \
--access-key "${ACCESS_KEY}" --secret-key "${SECRET_KEY}" \
--run-id "${VALIDATION_CASE}-$(date +%s)-$$" \
--evidence-dir "${harness_dir}" \
--rc-bin "$(command -v rc)" \
"${ilm_args[@]}" \
--cleanup-on-failure || harness_rc=$?
python3 -B "${SCRIPT_DIR}/scripts/validation_ilm/verify_result.py" \
"${VALIDATION_CASE}" "${harness_dir}" || return 1
[ "${harness_rc}" -eq 0 ]
}
rc_run() {
RC_OUT="$(rc "$@" 2>&1)"; RC_CODE=$?
}
assert_rc_ok() {
if [ "${RC_CODE}" -eq 7 ]; then echo "rc gated (exit 7): $*"; return 2; fi
[ "${RC_CODE}" -eq 0 ] || { echo "rc failed (exit ${RC_CODE}): $*"; echo "${RC_OUT}"; return 1; }
}
aws_run() {
AWS_OUT="$(aws --endpoint-url "${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; }
}
assert_aws_fails_with() {
local needle="$1"; shift
[ "${AWS_CODE}" -ne 0 ] || { echo "aws unexpectedly succeeded: $*"; return 1; }
printf '%s' "${AWS_OUT}" | grep -qiE "${needle}" \
|| { echo "aws error did not contain '${needle}': ${AWS_OUT}"; return 1; }
}
md5_of_file() { md5sum "$1" 2>/dev/null | awk '{print $1}'; }
new_bucket() {
local b="$1"
aws_run s3api create-bucket --bucket "${b}"
assert_aws_ok || return 1
}
rm_bucket() {
local b="$1"
aws_run s3api delete-bucket --bucket "${b}" 2>/dev/null || true
}
make_test_file() {
local path="$1" size="$2"
if [ "${size}" -eq 0 ]; then : > "${path}"; else head -c "${size}" /dev/urandom > "${path}"; fi
}
# Compressible payload (repeated pattern) of the requested byte size.
make_compressible_file() {
local path="$1" size="$2"
yes "compressible rustfs storage test pattern. " 2>/dev/null | head -c "${size}" > "${path}"
}
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'
for t in "${FAILED_TESTS[@]}"; do printf ' - %s\n' "${t}"; done
fi
}
TOPO_RESULTS=()
record_topology_result() {
local topo="$1"
TOPO_RESULTS+=("${topo}: PASS=${PASS} FAIL=${FAIL} UNSUPPORTED=${UNSUPPORTED}")
if [ "${#FAILED_TESTS[@]}" -gt 0 ]; then
local t
for t in "${FAILED_TESTS[@]}"; do TOPO_RESULTS+=(" - ${t}"); done
fi
}
final_summary() {
printf '\n========================================\n'
printf 'ALL TOPOLOGIES SUMMARY\n'
local line
for line in "${TOPO_RESULTS[@]}"; do printf '%s\n' "${line}"; done
printf '========================================\n'
}
# ==================== Disk helpers (SSH to nodes) ====================
# Sum all stored file bytes for a bucket across the current topology nodes.
bucket_physical_bytes() {
local bucket="$1" nodes_str nodes=() total=0 out
read -r -a nodes <<<"$(topology_nodes "${CURRENT_TOPOLOGY}")"
for node in "${nodes[@]}"; do
if [ "${DRY_RUN}" -eq 1 ]; then
printf '0\n'; return 0
fi
out="$(ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" \
"if [ \"\$(id -u)\" -ne 0 ]; then SUDO=\"sudo -n\"; else SUDO=\"\"; fi; \${SUDO} find /data/rustfs*/mnmd/${bucket} -type f -printf '%s\\n' 2>/dev/null | awk '{s+=\$1} END{print s+0}'")"
total=$((total + ${out:-0}))
done
printf '%s' "${total}"
}
# Count part.* files for a bucket across the current topology nodes.
bucket_part_count() {
local bucket="$1" nodes_str nodes=() total=0 out
read -r -a nodes <<<"$(topology_nodes "${CURRENT_TOPOLOGY}")"
for node in "${nodes[@]}"; do
if [ "${DRY_RUN}" -eq 1 ]; then
printf '0\n'; return 0
fi
out="$(ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" \
"if [ \"\$(id -u)\" -ne 0 ]; then SUDO=\"sudo -n\"; else SUDO=\"\"; fi; \${SUDO} find /data/rustfs*/mnmd/${bucket} -name 'part.*' 2>/dev/null | wc -l")"
total=$((total + ${out:-0}))
done
printf '%s' "${total}"
}
# ==================== Test cases ====================
run_all_tests() {
run_test STOR-101 "SingleObjectCompression" test_stor101
run_test STOR-102 "CompressionThresholdNegatives" test_stor102
run_test STOR-104 "ContentEncodingSkip" test_stor104
run_test STOR-105 "MultipartCompression" test_stor105
run_test STOR-106 "CompressedRangeGet" test_stor106
run_test STOR-107 "CompressionEncryption" test_stor107
run_test STOR-108 "CompressionVersioning" test_stor108
run_test STOR-110 "HttpResponseCompression" test_stor110
run_test STOR-111 "InlineDefaultThreshold" test_stor111
run_test STOR-113 "InlineOverwriteDelete" test_stor113
run_test STOR-115 "InlineEncryption" test_stor115
run_test STOR-117 "CacheStats" test_stor117
run_test STOR-118 "CacheFlush" test_stor118
run_test STOR-119 "CacheInvalidation" test_stor119
run_test STOR-125 "CopyRepresentation" test_stor125
run_test STOR-129 "BitrotSelfTest" test_stor129
run_test STOR-130 "StorageInfo" test_stor130
run_test STOR-131 "RcInfoConsistency" test_stor131
run_test STOR-132 "CompressedPhysicalVsLogical" test_stor132
run_test STOR-133 "InlineCapacity" test_stor133
run_test STOR-134 "AdminUsageConverges" test_stor134
run_test STOR-135 "DeepKeyListingResilience" test_stor135
}
test_stor134() { # admin usage APIs must respond promptly and converge to actual object counts (#1858 #2232 #5116)
local bucket="stor134-usage" i waited code body_file apid
new_bucket "${bucket}" || return 1
for i in $(seq 1 20); do
make_test_file "${TEST_TMP}/stor134-${i}" $((1024 + i))
aws_run s3api put-object --bucket "${bucket}" --key "obj-${i}" --body "${TEST_TMP}/stor134-${i}"
assert_aws_ok || { echo "put obj-${i} failed"; rm_bucket "${bucket}"; return 1; }
done
# The API must answer within 30s; a multi-minute hang is the #1858 signature.
body_file="${TEST_TMP}/stor134-usage.json"
admin_api GET "/rustfs/admin/v3/datausageinfo" "" "" > "${body_file}" 2>&1 &
apid=$!
waited=0
while kill -0 "${apid}" 2>/dev/null && [ "${waited}" -lt 30 ]; do
sleep 1
waited=$((waited + 1))
done
if kill -0 "${apid}" 2>/dev/null; then
kill "${apid}" 2>/dev/null || true
echo "datausageinfo did not respond within 30s (hang)"
rm_bucket "${bucket}"
return 1
fi
wait "${apid}" || true
code="$(admin_api_code)"
[ "${code}" = "200" ] || { echo "datausageinfo returned HTTP ${code}"; rm_bucket "${bucket}"; return 1; }
# Usage is scanner-derived and eventually consistent: poll until this
# bucket's own entry accounts for the seeded objects, or fail the way
# #2232/#5116 did (stale 0/0).
waited=0
while [ "${waited}" -lt 300 ]; do
if jq -e --arg b "${bucket}" \
'[.. | objects | select(has($b)) | .[$b]] | map((.objects_count? // .objects? // .Objects? // -1) >= 20) | any' \
"${body_file}" >/dev/null 2>&1; then
rm_bucket "${bucket}"
return 0
fi
sleep 15
waited=$((waited + 15))
admin_api GET "/rustfs/admin/v3/datausageinfo" "" "" > "${body_file}" 2>&1 || true
done
echo "STOR-134 observed datausageinfo (first 600 bytes):"
head -c 600 "${body_file}" 2>/dev/null || true
printf '\n'
echo "STOR-134 observed entries for ${bucket}:"
jq -c --arg b "${bucket}" '[.. | objects | select(has($b)) | .[$b]]' "${body_file}" 2>&1 | head -c 400 || true
printf '\n'
echo "usage never accounted for the 20 seeded objects (stale/zero usage signature)"
rm_bucket "${bucket}"
return 1
}
test_stor135() { # deep key listing must not crash the server (backlog#2809 backlog#3293)
local bucket="stor135-deep" deep_key
# 300 one-character segments + a leaf keeps the key within the S3 1024-byte
# limit while creating a directory tree deep enough to overflow a 2 MiB
# worker stack if the walk recurses without a depth bound.
deep_key="$(printf 'a/%.0s' $(seq 1 300))payload"
new_bucket "${bucket}" || return 1
make_test_file "${TEST_TMP}/stor135-payload" 100
aws_run s3api put-object --bucket "${bucket}" --key "${deep_key}" --body "${TEST_TMP}/stor135-payload"
assert_aws_ok || { echo "put-object of the deep key failed: ${AWS_OUT}"; rm_bucket "${bucket}"; return 1; }
# The listing must answer (with the key or a controlled error) without
# aborting the server process. A stack-overflow abort shows up as a
# connection failure here and an "overflowed its stack" line in the journal.
aws_run s3api list-objects-v2 --bucket "${bucket}"
if [ "${AWS_CODE}" -ne 0 ]; then
echo "list-objects-v2 failed (exit ${AWS_CODE}): ${AWS_OUT}"
echo "checking that the server is still alive after the listing failure"
aws_run s3api head-object --bucket "${bucket}" --key "normal-absent-key" 2>/dev/null
[ "${AWS_CODE}" -ne 0 ] || { echo "server accepted a head-object that should not exist"; rm_bucket "${bucket}"; return 1; }
# If the server is reachable the listing failure is a controlled error,
# which is acceptable; a crash would leave the endpoint unreachable.
aws_run s3api list-objects-v2 --bucket "${bucket}" --max-keys 1
if [ "${AWS_CODE}" -ne 0 ]; then
echo "server is unreachable after the deep-key listing (crash signature)"
rm_bucket "${bucket}"
return 1
fi
echo "listing returned a controlled error and the server survived"
rm_bucket "${bucket}"
return 0
fi
# The listing succeeded: the deep key must be present.
printf '%s' "${AWS_OUT}" | grep -q "${deep_key}" \
|| { echo "listing did not return the deep key"; rm_bucket "${bucket}"; return 1; }
# GET of the deep key must still work after the listing.
aws_run s3api get-object --bucket "${bucket}" --key "${deep_key}" "${TEST_TMP}/stor135-get"
assert_aws_ok || { echo "get-object of the deep key failed after listing: ${AWS_OUT}"; rm_bucket "${bucket}"; return 1; }
cmp -s "${TEST_TMP}/stor135-payload" "${TEST_TMP}/stor135-get" \
|| { echo "GET bytes differ from what was PUT"; rm_bucket "${bucket}"; return 1; }
aws_run s3api delete-object --bucket "${bucket}" --key "${deep_key}"
rm_bucket "${bucket}"
return 0
}
validation_scanner_usage_matches() {
local scanner_file="$1" usage_file="$2" bucket="$3" baseline="$4" bytes="$5" uploaded="$6"
jq -e --argjson uploaded "${uploaded}" \
'.enabled == true and .freshness.state == "fresh" and .metrics.last_cycle_result == "success" and .metrics.leader_lock_held_by_this_process == true and .cycle_schedule.execution_role == "leader" and .freshness.last_cycle_end_unix_secs >= $uploaded' \
"${scanner_file}" >/dev/null 2>&1 && \
jq -e --arg bucket "${bucket}" --argjson baseline "${baseline}" --argjson bytes "${bytes}" \
'.usage_snapshot_complete == true and .usage_snapshot_converged != false and .scanner_cycle > $baseline and .buckets_usage[$bucket].objects_count == 20 and .buckets_usage[$bucket].size == $bytes' \
"${usage_file}" >/dev/null 2>&1
}
test_validation_scanner_usage_convergence() {
local bucket="val-usage-${RANDOM}-$$" i key size sha expected_size=0 baseline_cycle=0
local upload_end deadline case_rc=0 cleanup_rc=0
local fixture_tsv="${TEST_TMP}/validation-fixture.tsv"
VALIDATION_OBJECT_CLEANUP_STATUS=PASS
: > "${fixture_tsv}"
new_bucket "${bucket}" || return 1
(
admin_api GET "/rustfs/admin/v3/datausageinfo" "" "" > "${TEST_TMP}/validation-baseline-usage.json"
[ "$(admin_api_code)" = 200 ] || { echo "baseline usage API failed"; exit 1; }
baseline_cycle="$(jq -er '.scanner_cycle // 0 | numbers' "${TEST_TMP}/validation-baseline-usage.json")" || exit 1
for i in $(seq 1 20); do
key="obj-${i}"
size=$((1024 + i))
make_test_file "${TEST_TMP}/${key}" "${size}"
sha="$(sha256sum "${TEST_TMP}/${key}" | awk '{print $1}')"
printf '%s\t%s\t%s\n' "${key}" "${size}" "${sha}" >> "${fixture_tsv}"
expected_size=$((expected_size + size))
aws_run s3api put-object --bucket "${bucket}" --key "${key}" --body "${TEST_TMP}/${key}"
assert_aws_ok || exit 1
done
jq -Rn --arg bucket "${bucket}" '[inputs | split("\t") | {key:.[0], size:(.[1]|tonumber), sha256:.[2]}] | {bucket:$bucket, objects:., expected_count:length, expected_size:(map(.size)|add)}' \
< "${fixture_tsv}" > "${TEST_TMP}/validation-fixture.json"
upload_end="$(date -u +%s)"
aws_run s3api list-objects-v2 --bucket "${bucket}"
assert_aws_ok || exit 1
printf '%s\n' "${AWS_OUT}" > "${TEST_TMP}/validation-list.json"
jq -e --slurpfile fixture "${TEST_TMP}/validation-fixture.json" \
'(.Contents // [] | map({key:.Key,size:.Size}) | sort_by(.key)) == ($fixture[0].objects | map({key,size}) | sort_by(.key))' \
"${TEST_TMP}/validation-list.json" >/dev/null || { echo "S3 fixture list differs from uploaded manifest"; exit 1; }
deadline=$((SECONDS + 300))
while [ "${SECONDS}" -lt "${deadline}" ]; do
admin_api GET "/rustfs/admin/v3/scanner/status" "" "" > "${TEST_TMP}/validation-scanner.json"
local scanner_code usage_code
scanner_code="$(admin_api_code)"
admin_api GET "/rustfs/admin/v3/datausageinfo" "" "" > "${TEST_TMP}/validation-usage.json"
usage_code="$(admin_api_code)"
if [ "${scanner_code}" = 200 ] && [ "${usage_code}" = 200 ] && \
validation_scanner_usage_matches "${TEST_TMP}/validation-scanner.json" "${TEST_TMP}/validation-usage.json" \
"${bucket}" "${baseline_cycle}" "${expected_size}" "${upload_end}"; then
echo "scanner completed after upload; usage converged to 20 objects and ${expected_size} bytes"
exit 0
fi
sleep 5
done
echo "scanner or usage did not converge within 300 seconds"
exit 1
) || case_rc=$?
for i in $(seq 1 20); do
aws_run s3api delete-object --bucket "${bucket}" --key "obj-${i}"
assert_aws_ok || cleanup_rc=1
done
aws_run s3api delete-bucket --bucket "${bucket}"
assert_aws_ok || cleanup_rc=1
if [ "${cleanup_rc}" -ne 0 ]; then
VALIDATION_OBJECT_CLEANUP_STATUS=FAIL
echo "validation bucket cleanup failed"
fi
[ "${case_rc}" -eq 0 ] && [ "${cleanup_rc}" -eq 0 ]
}
validation_scanner_status_ready() {
local node1="$1" node2="$2" started_at="$3"
jq -se --argjson started "${started_at}" '
length == 2 and
all(.[]; .enabled == true and
.runtime_config.cycle_interval_seconds == {value:5,source:"env"} and
.runtime_config.start_delay_seconds == {value:0,source:"env"}) and
([.[] | select(.metrics.leader_lock_held_by_this_process == true)] | length) == 1 and
any(.[]; .metrics.leader_lock_held_by_this_process == true and
.metrics.leader_lock_state == "acquired" and
.metrics.last_cycle_result == "success" and
.metrics.last_cycle_end_unix_secs >= $started and
.freshness.state == "fresh" and
.cycle_schedule.execution_role == "leader")' \
"${node1}" "${node2}" >/dev/null
}
test_validation_scanner_status_readiness() {
local started_at deadline status_code node endpoint index
started_at="$(date -u +%s)"
deadline=$((SECONDS + 120))
while [ "${SECONDS}" -lt "${deadline}" ]; do
status_code=0
for index in 1 2; do
node="${NODES[index-1]}"
endpoint="http://rustfs-node${index}:9000"
(API_ENDPOINT="${endpoint}"; admin_api GET /rustfs/admin/v3/scanner/status "" "" > "${TEST_TMP}/validation-scanner-node${index}.json"
[ "$(admin_api_code)" = 200 ]) || status_code=1
[ "${status_code}" -eq 0 ] || { echo "scanner status unavailable on ${node}"; break; }
done
if [ "${status_code}" -eq 0 ] && validation_scanner_status_ready \
"${TEST_TMP}/validation-scanner-node1.json" "${TEST_TMP}/validation-scanner-node2.json" "${started_at}"; then
jq -n --argjson started "${started_at}" --slurpfile node1 "${TEST_TMP}/validation-scanner-node1.json" \
--slurpfile node2 "${TEST_TMP}/validation-scanner-node2.json" \
'{started_at_unix:$started,cycle_interval_seconds:5,start_delay_seconds:0,
leader:([($node1[0],$node2[0]) | select(.metrics.leader_lock_held_by_this_process == true) |
{last_cycle_end_unix_secs:.metrics.last_cycle_end_unix_secs,last_cycle_result:.metrics.last_cycle_result}] | first)}' \
> "${TEST_TMP}/validation-scanner-contract.json"
return 0
fi
sleep 5
done
echo "two-node scanner runtime or successful new leader cycle did not meet the 120-second deadline"
return 1
}
test_stor101() {
new_bucket "stor101-b1" || return 1
make_compressible_file "${TEST_TMP}/stor101-v" 1048576
aws_run s3api put-object --bucket "stor101-b1" --key c.txt --body "${TEST_TMP}/stor101-v"
assert_aws_ok || return 1
aws_run s3api head-object --bucket "stor101-b1" --key c.txt
printf '%s' "${AWS_OUT}" | jq -e '.ContentLength == 1048576' >/dev/null \
|| { echo "HEAD length wrong: ${AWS_OUT}"; return 1; }