Repository navigation
Expand file tree
/
Copy pathrustfs-tier-test.sh
More file actions
executable file
·3470 lines (3215 loc) · 144 KB
/
Copy pathrustfs-tier-test.sh
File metadata and controls
executable file
·3470 lines (3215 loc) · 144 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-tier-test.sh
# RustFS data tiering / event notification / security audit test suite
# (backlog #2024: TIER-101..112, EVT-101..108, AUD-101..107)
#
# Topologies (peer RustFS as the warm tier, both installed from the same deb):
# 1. single-single (vm000 = source 1 disk, vm001 = target 1 disk)
# 2. single-multi (vm000 = source 4 disks, vm001 = target 4 disks)
#
# External services on the admin host (heal):
# - webhook receiver (python3 HTTP server on :18080, /hook + /audit paths)
# - MQTT broker (mosquitto on :1883) with a subscriber on rustfs/events
#
# Each case has an explicit pass criterion and reports PASS / FAIL /
# UNSUPPORTED with error detail on failure.
#
# Usage:
# ./rustfs-tier-test.sh --all-topologies -y --package-url <deb url>
# ./rustfs-tier-test.sh --topology single-single -y --version 1.0.0-rc.4-preview.1
#
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Per-run temp dir (shared runners may leave stale /tmp files owned by other users).
# Tests may inject an isolated directory while sourcing this file.
if [ -n "${RUSTFS_TIER_TEST_TMP:-}" ]; then
TEST_TMP="${RUSTFS_TIER_TEST_TMP}"
TEST_TMP_OWNED=0
mkdir -p "${TEST_TMP}"
else
TEST_TMP="$(mktemp -d "${TMPDIR:-/tmp}/rustfs-test.XXXXXX")"
TEST_TMP_OWNED=1
fi
CASE_ACTIVE=0
CASE_CLEANUP_RUNNING=0
CASE_CLEANUP_DONE=0
LOG_CAPTURE_ACTIVE=0
LOG_CAPTURE_PID=""
LOG_CAPTURE_DIR=""
LOG_PIPE=""
LOG_CAPTURE_STOP_FILE=""
LOG_CAPTURE_OUTPUT_REDIRECTED=0
LOG_CAPTURE_ANCHOR_OPEN=0
LOG_CAPTURE_SAVED_FDS_OPEN=0
LOG_CAPTURE_PENDING_STATUS=0
LOG_CAPTURE_ANCHOR_FD=""
LOG_CAPTURE_STDOUT_FD=""
LOG_CAPTURE_STDERR_FD=""
LOG_CAPTURE_SUCCESS_TICKS=600
LOG_CAPTURE_FAILURE_TICKS=100
log_capture_phase() { :; }
next_free_log_fd() {
local candidate
for ((candidate=10; candidate<100; candidate++)); do
if ! { : >&"${candidate}"; } 2>/dev/null; then
printf '%s' "${candidate}"
return 0
fi
done
return 1
}
close_log_fd() {
local descriptor="$1"
[ -n "${descriptor}" ] || return 0
case "${descriptor}" in
*[!0-9]*) return 1 ;;
esac
eval "exec ${descriptor}>&-"
}
log_capture_job_is_active() {
local expected="$1" job_pid snapshot
[ -n "${LOG_CAPTURE_DIR:-}" ] && [ -d "${LOG_CAPTURE_DIR}" ] || return 1
# A signal-killed child can linger in the job table until the next jobs/wait
# refresh: the OS-level liveness check below catches it immediately.
kill -0 "${expected}" 2>/dev/null || return 1
snapshot="${LOG_CAPTURE_DIR}/jobs"
# This must execute in the current shell: only it owns the authoritative job
# table. Completed jobs disappear, while running and stopped jobs remain.
jobs -p > "${snapshot}" || return 1
while IFS= read -r job_pid; do
[ "${job_pid}" = "${expected}" ] && return 0
done < "${snapshot}"
return 1
}
reap_log_process_if_done() {
local pid="$1" process_status
log_capture_job_is_active "${pid}" && return 124
# If the OS still has this PID but Bash does not own it as an active job, do
# not wait or signal: fail bounded instead of risking a recycled PID.
kill -0 "${pid}" 2>/dev/null && return 125
if wait "${pid}"; then process_status=0; else process_status=$?; fi
return "${process_status}"
}
wait_for_log_process_exit_bounded() {
local pid="$1" ticks="$2" i process_status
for ((i=0; i<ticks; i++)); do
if ! log_capture_job_is_active "${pid}"; then
if reap_log_process_if_done "${pid}"; then process_status=0; else process_status=$?; fi
return "${process_status}"
fi
sleep 0.05
done
return 124
}
abort_pending_log_start() {
local pending_status="${LOG_CAPTURE_PENDING_STATUS:-0}"
[ "${pending_status}" -ne 0 ] || return 0
trap 'exit 130' INT
trap 'exit 143' TERM
if [ -n "${LOG_CAPTURE_PID:-}" ] \
&& log_capture_job_is_active "${LOG_CAPTURE_PID}"; then
kill -CONT "${LOG_CAPTURE_PID}" 2>/dev/null || true
kill -TERM "${LOG_CAPTURE_PID}" 2>/dev/null || true
fi
exit "${pending_status}"
}
request_log_capture_stop() {
python3 -c '
import os, sys
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
flags |= getattr(os, "O_CLOEXEC", 0)
descriptor = os.open(sys.argv[1], flags, 0o600)
os.close(descriptor)
' "$1"
}
finish_log_process_bounded() {
local pid="$1" suite_status="$2" stop_status="$3"
local ticks="${LOG_CAPTURE_SUCCESS_TICKS}" i process_status
[ "${suite_status}" -eq 0 ] || ticks="${LOG_CAPTURE_FAILURE_TICKS}"
for ((i=0; i<ticks; i++)); do
if ! log_capture_job_is_active "${pid}"; then
if reap_log_process_if_done "${pid}"; then process_status=0; else process_status=$?; fi
[ "${process_status}" -ne 0 ] || process_status="${stop_status}"
return "${process_status}"
fi
sleep 0.05
done
if ! log_capture_job_is_active "${pid}"; then
if reap_log_process_if_done "${pid}"; then process_status=0; else process_status=$?; fi
[ "${process_status}" -ne 0 ] || process_status="${stop_status}"
return "${process_status}"
fi
kill -CONT "${pid}" 2>/dev/null || true
kill -TERM "${pid}" 2>/dev/null || true
for ((i=0; i<20; i++)); do
if ! log_capture_job_is_active "${pid}"; then
# The helper exited on TERM. Harvest the real status: a graceful 0 or
# stop_status means the log is intact and the escalation was just slow
# politeness, not a failure. Keep signal deaths distinct from the
# timeout sentinel so a crashed logger cannot be hidden by the suite.
if reap_log_process_if_done "${pid}"; then process_status=0; else process_status=$?; fi
[ "${process_status}" -ne 0 ] || process_status="${stop_status}"
return "${process_status}"
fi
sleep 0.05
done
log_capture_job_is_active "${pid}" || return 124
kill -CONT "${pid}" 2>/dev/null || true
kill -KILL "${pid}" 2>/dev/null || true
for ((i=0; i<20; i++)); do
if ! log_capture_job_is_active "${pid}"; then
# SIGKILL is force majeure; the log tail may be truncated, so keep 124
# here - but only here.
reap_log_process_if_done "${pid}" >/dev/null 2>&1 || true
return 124
fi
sleep 0.05
done
return 124
}
finish_log_capture() {
local suite_status="${1:-0}" logger_status=0 stop_status=0
if [ "${LOG_CAPTURE_ACTIVE:-0}" -eq 1 ]; then
# Publish the stop request before closing the last shell-owned FIFO writer,
# so the logger cannot observe EOF before it sees the authenticated request.
if [ -n "${LOG_CAPTURE_PID:-}" ] && [ -n "${LOG_CAPTURE_STOP_FILE:-}" ]; then
request_log_capture_stop "${LOG_CAPTURE_STOP_FILE}" || stop_status=74
fi
if [ "${LOG_CAPTURE_OUTPUT_REDIRECTED:-0}" -eq 1 ]; then
exec 1>&- 2>&-
LOG_CAPTURE_OUTPUT_REDIRECTED=0
fi
if [ -n "${LOG_CAPTURE_PID:-}" ] && [ -n "${LOG_CAPTURE_STOP_FILE:-}" ]; then
if finish_log_process_bounded \
"${LOG_CAPTURE_PID}" "${suite_status}" "${stop_status}"; then
logger_status=0
else
logger_status=$?
fi
elif [ -n "${LOG_CAPTURE_PID:-}" ]; then
logger_status=74
fi
if [ "${LOG_CAPTURE_ANCHOR_OPEN:-0}" -eq 1 ]; then
close_log_fd "${LOG_CAPTURE_ANCHOR_FD}" || true
LOG_CAPTURE_ANCHOR_OPEN=0
fi
if [ "${LOG_CAPTURE_SAVED_FDS_OPEN:-0}" -eq 1 ]; then
close_log_fd "${LOG_CAPTURE_STDOUT_FD}" || true
close_log_fd "${LOG_CAPTURE_STDERR_FD}" || true
LOG_CAPTURE_SAVED_FDS_OPEN=0
fi
LOG_CAPTURE_ACTIVE=0
if [ -n "${LOG_CAPTURE_DIR:-}" ] && [ -d "${LOG_CAPTURE_DIR}" ]; then
rm -f -- "${LOG_CAPTURE_DIR}/stream" "${LOG_CAPTURE_DIR}/ready" \
"${LOG_CAPTURE_DIR}/stop" "${LOG_CAPTURE_DIR}/jobs" \
"${LOG_CAPTURE_DIR}"/ready.*.tmp 2>/dev/null || true
rmdir -- "${LOG_CAPTURE_DIR}" 2>/dev/null || true
fi
fi
if [ "${suite_status}" -ne 0 ]; then
return "${suite_status}"
fi
return "${logger_status}"
}
suite_exit() {
local exit_code="${1:-$?}"
trap - EXIT INT TERM
trap '' PIPE
if [ "${CASE_ACTIVE:-0}" -eq 1 ] && declare -F case_cleanup >/dev/null 2>&1; then
case_cleanup "signal-or-exit" >> "${TEST_TMP}/test.out" 2>&1 || true
fi
if [ "${VALIDATION_ENV_ACTIVE:-0}" -eq 1 ]; then
VALIDATION_ENV_ACTIVE=0
env_teardown "${CURRENT_TOPOLOGY}" || exit_code=1
fi
if declare -F mqtt_stop >/dev/null; then mqtt_stop || exit_code=1; fi
if declare -F mqtt_broker_stop >/dev/null; then mqtt_broker_stop || exit_code=1; fi
if finish_log_capture "${exit_code}"; then
exit_code=0
else
exit_code=$?
# The log-capture helper being force-killed after its bounded grace period
# (a straggler producer holding the FIFO write end) says nothing about the
# suite result - the case verdicts already carry the product signal. A red
# run with all-green cases is noise (see the 09-21 run 35560597650).
if [ "${exit_code}" -eq 124 ]; then
log "log capture helper timed out; suite result stands"
exit_code=0
fi
fi
if [ "${TEST_TMP_OWNED:-0}" -eq 1 ] && [ -n "${TEST_TMP:-}" ] && [ -d "${TEST_TMP}" ]; then
rm -rf -- "${TEST_TMP}"
fi
exit "${exit_code}"
}
trap 'suite_exit $?' EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
# ==================== Configuration ====================
NODES=(vm000 vm001 vm002 vm003)
SOURCE_NODE="${NODES[0]}"
TARGET_NODE="${NODES[1]}"
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:-}"
ACCESS_KEY="${RUSTFS_ACCESS_KEY:-rustfs@test}"
SECRET_KEY="${RUSTFS_SECRET_KEY:-rustfs@test}"
REGION="us-east-1"
# Heal-local receiver + MQTT broker (reachable from vm000/001/002 at 10.0.0.4).
HEAL_IP="${RUSTFS_HEAL_IP:-10.0.0.4}"
RECEIVER_PORT="${RUSTFS_RECEIVER_PORT:-18080}"
NOTIFY_ENDPOINT="http://${HEAL_IP}:${RECEIVER_PORT}/hook"
AUDIT_ENDPOINT="http://${HEAL_IP}:${RECEIVER_PORT}/audit"
NOTIFY_TOKEN="notify-token"
AUDIT_TOKEN="audit-token"
MQTT_PORT="${RUSTFS_MQTT_PORT:-1883}"
MQTT_MODE="${RUSTFS_TIER_MQTT_MODE:-auto}"
MQTT_BROKER="tcp://${HEAL_IP}:${MQTT_PORT}"
MQTT_TOPIC="rustfs/events"
MQTT_SUB_PID=""
MQTT_BROKER_OWNED=0
MQTT_DOCKER=(docker)
MQTT_CIDFILE=""
RECEIVER_SCRIPT="${TEST_TMP}/rustfs-receiver.py"
RECEIVER_PIDFILE="${TEST_TMP}/rustfs-receiver.pid"
MQTT_PIDFILE="${TEST_TMP}/rustfs-mqtt-sub.pid"
NOTIFY_EVENTS="${TEST_TMP}/rustfs-notify-events.jsonl"
AUDIT_EVENTS="${TEST_TMP}/rustfs-audit-events.jsonl"
MQTT_EVENTS="${TEST_TMP}/rustfs-mqtt-events.jsonl"
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=warn
RUSTFS_OBS_LOG_DIRECTORY="/var/log/rustfs/"
TOPO_SINGLE_SINGLE="single-single"
TOPO_SINGLE_MULTI="single-multi"
SOURCE_ENDPOINT_SINGLE_SINGLE="http://rustfs-node1:9000"
SOURCE_ENDPOINT_SINGLE_MULTI="http://rustfs-node1:9000"
TARGET_ENDPOINT="http://rustfs-node2:9000"
VOLUMES_SINGLE_SINGLE="/data/rustfs1/mnmd"
VOLUMES_SINGLE_MULTI="/data/rustfs{1...4}/mnmd"
SERVICE_TIMEOUT=300
TIER_NAME="WARM"
TIER_BUCKET="tier-warm"
API_ENDPOINT="${SOURCE_ENDPOINT_SINGLE_SINGLE}"
SIGV4_REGION="${REGION}"
SIGV4_SERVICE="s3"
API_REQUEST_TIMEOUT=120
COMMAND_TIMEOUT=360
CLEANUP_TIMEOUT=60
SOURCE_BUCKET_DELETE_TIMEOUT=30
SOURCE_BUCKET_DELETE_ATTEMPT_TIMEOUT=5
SOURCE_BUCKET_DELETE_RETRY_INTERVAL=2
REMOTE_PROBE_TIMEOUT=15
REMOTE_STATE_TIMEOUT=60
REMOTE_PROBE_INTERVAL=3
ADMIN_API_CODE_FILE="${TEST_TMP}/rustfs-tier-api-code"
# ==================== Runtime options ====================
DRY_RUN=0
ASSUME_YES=0
KEEP_ENV=0
LOG_FILE=""
SELECTED_TOPOLOGIES=()
ENDPOINT=""
VOLUMES=""
CURRENT_TOPOLOGY=""
CURRENT_CASE_ID=""
CURRENT_CASE_NAME=""
CASE_FAILURE_KIND=""
CASE_FAILURE_DETAIL=""
CASE_LOG_PATH=""
REMOTE_KEY_COUNT=""
AWS_OUT=""
AWS_CODE=0
RUN_TOKEN="$(date -u +%y%m%d%H%M%S)-$$"
RC_BIN_REQUEST="${RUSTFS_RC_BIN:-rc}"
RC_BIN=""
RC_SHA256=""
RC_VERSION=""
RC_CONFIG_DIR="${TEST_TMP}/rc-config"
ARTIFACTS_DIR="${RUSTFS_TIER_ARTIFACTS_DIR:-${TEST_TMP}/artifacts}"
RESULTS_DIR=""
RESULT_LOG_DIR=""
PROVENANCE_FILE=""
RESIDUE_FILE=""
VALIDATION_CASE=""
VALIDATION_SOURCE_CASE_ID=""
SELECTED_CASES=""
VALIDATION_ARTIFACTS_DIR=""
VALIDATION_CANDIDATE_MANIFEST=""
VALIDATION_TESTING_COMMIT=""
VALIDATION_BINARY_SHA256=""
VALIDATION_ENV_ACTIVE=0
# ==================== 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"
}
start_log_capture() {
local helper ready=0 i logger_status=0
[ -n "${LOG_FILE}" ] || return 0
command -v python3 >/dev/null 2>&1 || die "missing command: python3 (secure log capture); install it first"
helper="$(python3 -c 'import os,sys; print(os.path.join(os.path.dirname(os.path.realpath(sys.argv[1])), "rustfs-tier-log-capture.py"))' "${BASH_SOURCE[0]}")"
[ -f "${helper}" ] || die "missing secure log capture helper: ${helper}"
# During initialization, remember INT/TERM and finish constructing a state
# that suite_exit can always tear down. The pending status is delivered as
# soon as the saved output descriptors have been closed.
LOG_CAPTURE_PENDING_STATUS=0
trap 'LOG_CAPTURE_PENDING_STATUS=130' INT
trap 'LOG_CAPTURE_PENDING_STATUS=143' TERM
log_capture_phase begin
abort_pending_log_start
if ! LOG_CAPTURE_DIR="$(mktemp -d "${TEST_TMP}/rustfs-tier-log.XXXXXX")"; then
trap 'exit 130' INT
trap 'exit 143' TERM
if [ "${LOG_CAPTURE_PENDING_STATUS}" -ne 0 ]; then
exit "${LOG_CAPTURE_PENDING_STATUS}"
fi
die "cannot create log capture state under ${TEST_TMP}"
fi
LOG_CAPTURE_ACTIVE=1
log_capture_phase control-dir
abort_pending_log_start
chmod 700 "${LOG_CAPTURE_DIR}" || die "cannot secure log capture state: ${LOG_CAPTURE_DIR}"
LOG_PIPE="${LOG_CAPTURE_DIR}/stream"
LOG_CAPTURE_STOP_FILE="${LOG_CAPTURE_DIR}/stop"
mkfifo -m 600 "${LOG_PIPE}" || die "cannot create the log synchronization pipe: ${LOG_PIPE}"
log_capture_phase fifo
abort_pending_log_start
LOG_CAPTURE_ANCHOR_FD="$(next_free_log_fd)" || die "cannot reserve a descriptor for log capture"
eval "exec ${LOG_CAPTURE_ANCHOR_FD}<>\"\${LOG_PIPE}\"" \
|| die "cannot open the log synchronization pipe"
LOG_CAPTURE_ANCHOR_OPEN=1
log_capture_phase anchor
abort_pending_log_start
LOG_CAPTURE_STDOUT_FD="$(next_free_log_fd)" || die "cannot reserve the original stdout"
eval "exec ${LOG_CAPTURE_STDOUT_FD}>&1" || die "cannot preserve the original stdout"
LOG_CAPTURE_STDERR_FD="$(next_free_log_fd)" || die "cannot reserve the original stderr"
eval "exec ${LOG_CAPTURE_STDERR_FD}>&2" || die "cannot preserve the original stderr"
LOG_CAPTURE_SAVED_FDS_OPEN=1
log_capture_phase saved
abort_pending_log_start
log_capture_phase active
abort_pending_log_start
(
close_log_fd "${LOG_CAPTURE_ANCHOR_FD}"
close_log_fd "${LOG_CAPTURE_STDOUT_FD}"
close_log_fd "${LOG_CAPTURE_STDERR_FD}"
exec python3 -u "${helper}" \
--log-file "${LOG_FILE}" \
--status-file "${LOG_CAPTURE_DIR}/ready" \
--stop-file "${LOG_CAPTURE_STOP_FILE}"
) < "${LOG_PIPE}" 1>&"${LOG_CAPTURE_STDOUT_FD}" 2>&"${LOG_CAPTURE_STDERR_FD}" &
LOG_CAPTURE_PID=$!
log_capture_phase launched
abort_pending_log_start
for ((i=0; i<100; i++)); do
abort_pending_log_start
if [ -s "${LOG_CAPTURE_DIR}/ready" ]; then
ready=1
break
fi
if ! log_capture_job_is_active "${LOG_CAPTURE_PID}"; then
if reap_log_process_if_done "${LOG_CAPTURE_PID}"; then
logger_status=0
else
logger_status=$?
fi
[ "${logger_status}" -eq 124 ] || LOG_CAPTURE_PID=""
break
fi
sleep 0.05 || true
done
if [ "${ready}" -ne 1 ]; then
trap 'exit 130' INT
trap 'exit 143' TERM
[ "${logger_status}" -ne 0 ] || logger_status=124
die "secure log capture failed to initialize (status=${logger_status})"
fi
log_capture_phase ready
abort_pending_log_start
# Bash 3.2 can terminate immediately when a builtin writes to a dead FIFO,
# bypassing EXIT. Convert SIGPIPE to an ordinary exit so suite_exit always
# runs case cleanup and removes the capture state.
trap 'exit 141' PIPE
exec > "${LOG_PIPE}" 2>&1
LOG_CAPTURE_OUTPUT_REDIRECTED=1
close_log_fd "${LOG_CAPTURE_ANCHOR_FD}"
LOG_CAPTURE_ANCHOR_OPEN=0
# The current shell job table is the stable direct-child identity. Never call
# wait while that job is running or stopped.
if log_capture_job_is_active "${LOG_CAPTURE_PID}"; then
logger_status=124
kill -CONT "${LOG_CAPTURE_PID}" 2>/dev/null || true
else
if reap_log_process_if_done "${LOG_CAPTURE_PID}"; then
logger_status=0
else
logger_status=$?
fi
[ "${logger_status}" -ne 0 ] && [ "${logger_status}" -ne 127 ] || logger_status=74
LOG_CAPTURE_PID=""
exec 1>&"${LOG_CAPTURE_STDOUT_FD}"
exec 2>&"${LOG_CAPTURE_STDERR_FD}"
LOG_CAPTURE_OUTPUT_REDIRECTED=0
trap 'exit 130' INT
trap 'exit 143' TERM
printf '\033[1;31m[ERROR]\033[0m secure log capture exited during startup (status=%s)\n' \
"${logger_status}" >&2
exit "${logger_status}"
fi
log_capture_phase redirected
abort_pending_log_start
close_log_fd "${LOG_CAPTURE_STDOUT_FD}"
close_log_fd "${LOG_CAPTURE_STDERR_FD}"
LOG_CAPTURE_SAVED_FDS_OPEN=0
log_capture_phase saved-closed
abort_pending_log_start
trap 'exit 130' INT
trap 'exit 143' TERM
if [ "${LOG_CAPTURE_PENDING_STATUS}" -ne 0 ]; then
exit "${LOG_CAPTURE_PENDING_STATUS}"
fi
}
sha256_file() {
openssl dgst -sha256 -r "$1" 2>/dev/null | awk '{print $1}'
}
run_bounded() {
local seconds="$1"
shift
timeout --signal=TERM --kill-after=5 "${seconds}" "$@"
}
run_hard_bounded() {
local seconds="$1"
shift
python3 - "$seconds" "$@" <<'PY'
import os
import signal
import subprocess
import sys
timeout = float(sys.argv[1])
process = subprocess.Popen(sys.argv[2:], start_new_session=True)
try:
status = process.wait(timeout=timeout)
except subprocess.TimeoutExpired:
os.killpg(process.pid, signal.SIGKILL)
process.wait()
raise SystemExit(137)
raise SystemExit(status if status >= 0 else 128 - status)
PY
}
bounded_safe_excerpt() {
local value="$1" limit="${2:-512}"
if { [ -n "${ACCESS_KEY:-}" ] && [[ "${value}" == *"${ACCESS_KEY}"* ]]; } \
|| { [ -n "${SECRET_KEY:-}" ] && [[ "${value}" == *"${SECRET_KEY}"* ]]; } \
|| printf '%s' "${value}" | grep -qiE 'authorization:|x-amz-credential|aws_access_key_id|aws_secret_access_key|accesskeyid|secretaccesskey'; then
printf '<redacted: credential-like content>'
return 0
fi
value="${value//$'\r'/ }"
value="${value//$'\n'/ }"
value="${value//$'\t'/ }"
while [[ "${value}" == *" "* ]]; do value="${value// / }"; done
if [ "${#value}" -gt "${limit}" ]; then
printf '%s...<truncated>' "${value:0:${limit}}"
else
printf '%s' "${value}"
fi
}
record_case_failure() {
local kind="$1" detail="$2"
[ -z "${CASE_FAILURE_KIND}" ] || return 0
[[ "${kind}" =~ ^[a-z0-9_]+$ ]] || kind=unknown_failure
CASE_FAILURE_KIND="${kind}"
CASE_FAILURE_DETAIL="$(bounded_safe_excerpt "${detail}" 2048)"
printf 'case failure: kind=%s detail=%s\n' "${CASE_FAILURE_KIND}" "${CASE_FAILURE_DETAIL}" >&2
}
init_artifacts() {
RESULTS_DIR="${ARTIFACTS_DIR}/cases"
RESULT_LOG_DIR="${ARTIFACTS_DIR}/logs"
PROVENANCE_FILE="${ARTIFACTS_DIR}/provenance.json"
RESIDUE_FILE="${ARTIFACTS_DIR}/residue.jsonl"
# A persistent receipt lets the caller recover an owned container after
# process cancellation or a failed Docker cleanup.
MQTT_CIDFILE="${ARTIFACTS_DIR}/mqtt-container-id"
mkdir -p "${RESULTS_DIR}" "${RESULT_LOG_DIR}"
if find "${RESULTS_DIR}" -maxdepth 1 -type f -name '*.json' -print -quit | grep -q .; then
die "artifacts case directory is not empty; use a unique --artifacts-dir: ${RESULTS_DIR}"
fi
: > "${RESIDUE_FILE}"
}
resolve_rc_binary() {
local candidate
if [[ "${RC_BIN_REQUEST}" == */* ]]; then
candidate="${RC_BIN_REQUEST}"
else
candidate="$(command -v "${RC_BIN_REQUEST}" 2>/dev/null || true)"
fi
if [ "${DRY_RUN}" -eq 1 ] && [ -z "${candidate}" ]; then
RC_BIN="${RC_BIN_REQUEST}"
RC_VERSION="dry-run (binary not resolved)"
RC_SHA256=""
else
[ -n "${candidate}" ] || die "missing command: ${RC_BIN_REQUEST} (RustFS client CLI)"
[ -x "${candidate}" ] || die "rc binary is not executable: ${candidate}"
RC_BIN="$(python3 -c 'import os,sys; print(os.path.realpath(sys.argv[1]))' "${candidate}")"
RC_SHA256="$(sha256_file "${RC_BIN}")"
[ -n "${RC_SHA256}" ] || die "failed to calculate rc SHA-256: ${RC_BIN}"
RC_VERSION="$(run_bounded 30 "${RC_BIN}" --version 2>&1 | head -1)" \
|| die "failed to read rc version from ${RC_BIN}"
fi
mkdir -p "${RC_CONFIG_DIR}"
export RC_CONFIG_DIR
}
write_provenance() {
jq -n \
--arg schema_version "1" \
--arg run_token "${RUN_TOKEN}" \
--arg rc_path "${RC_BIN}" \
--arg rc_version "${RC_VERSION}" \
--arg rc_sha256 "${RC_SHA256}" \
--arg rc_config_dir "${RC_CONFIG_DIR}" \
--arg expected_rc_sha256 "${RUSTFS_EXPECTED_RC_SHA256:-}" \
--arg package_url "$(resolve_package_url)" \
--arg generated_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{
schema_version: ($schema_version | tonumber),
run_token: $run_token,
generated_at: $generated_at,
package_url: $package_url,
rc: {
path: $rc_path,
version: $rc_version,
sha256: $rc_sha256,
config_dir: $rc_config_dir,
expected_sha256: $expected_rc_sha256
}
}' > "${PROVENANCE_FILE}"
}
verify_rc_digest() {
local expected="${RUSTFS_EXPECTED_RC_SHA256:-}"
[ -z "${expected}" ] && return 0
[ "${DRY_RUN}" -eq 0 ] || die "RUSTFS_EXPECTED_RC_SHA256 cannot be verified in dry-run mode"
expected="$(printf '%s' "${expected}" | tr '[:upper:]' '[:lower:]')"
if [ "${RC_SHA256}" != "${expected}" ]; then
die "rc SHA-256 mismatch: expected ${expected}, got ${RC_SHA256} (${RC_BIN})"
fi
}
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}"
}
wait_service_active() {
local node="$1" waited=0
[ "${DRY_RUN}" -eq 1 ] && 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"
local mqtt_enabled=true
if [ "${VALIDATION_CASE}" = events.delivery ] || [ "${VALIDATION_CASE}" = audit.request-correlation ]; then
mqtt_enabled=false
fi
cat <<EOF
RUSTFS_ACCESS_KEY=${ACCESS_KEY}
RUSTFS_SECRET_KEY=${SECRET_KEY}
RUSTFS_VOLUMES="${volumes}"
RUSTFS_NOTIFY_WEBHOOK_ENABLE_PRIMARY=true
RUSTFS_NOTIFY_WEBHOOK_ENDPOINT_PRIMARY=${NOTIFY_ENDPOINT}
RUSTFS_NOTIFY_WEBHOOK_AUTH_TOKEN_PRIMARY=${NOTIFY_TOKEN}
RUSTFS_NOTIFY_WEBHOOK_QUEUE_DIR_PRIMARY=/var/lib/rustfs/notify-webhook
RUSTFS_NOTIFY_MQTT_ENABLE_PRIMARY=${mqtt_enabled}
RUSTFS_NOTIFY_MQTT_BROKER_PRIMARY=${MQTT_BROKER}
RUSTFS_NOTIFY_MQTT_TOPIC_PRIMARY=${MQTT_TOPIC}
RUSTFS_NOTIFY_MQTT_QOS_PRIMARY=1
RUSTFS_NOTIFY_MQTT_QUEUE_DIR_PRIMARY=/var/lib/rustfs/notify-mqtt
RUSTFS_AUDIT_WEBHOOK_ENABLE_PRIMARY=true
RUSTFS_AUDIT_WEBHOOK_ENDPOINT_PRIMARY=${AUDIT_ENDPOINT}
RUSTFS_AUDIT_WEBHOOK_AUTH_TOKEN_PRIMARY=${AUDIT_TOKEN}
RUSTFS_AUDIT_WEBHOOK_QUEUE_DIR_PRIMARY=/var/lib/rustfs/audit-webhook
RUSTFS_OUTBOUND_ALLOW_ORIGINS=http://${HEAL_IP}:${RECEIVER_PORT},http://${HEAL_IP}:19999,http://rustfs-node2:9000,http://10.0.0.5:9000
RUSTFS_KMS_ENABLE=true
RUSTFS_KMS_BACKEND=local
RUSTFS_KMS_KEY_DIR=/var/lib/rustfs/kms
RUSTFS_KMS_LOCAL_MASTER_KEY=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=
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
}
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/notify-webhook /var/lib/rustfs/notify-mqtt /var/lib/rustfs/audit-webhook /var/lib/rustfs/kms\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
printf '${SUDO} mkdir -p /var/lib/rustfs/notify-webhook /var/lib/rustfs/notify-mqtt /var/lib/rustfs/audit-webhook /var/lib/rustfs/kms\n'
printf '${SUDO} chown -R %s:%s /var/lib/rustfs/notify-webhook /var/lib/rustfs/notify-mqtt /var/lib/rustfs/audit-webhook /var/lib/rustfs/kms\n' "${RUSTFS_USER}" "${RUSTFS_USER}"
} | 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
}
# ==================== Admin API (SigV4, optional JSON body) ====================
sha256_hex() { printf '%s' "$1" | openssl dgst -sha256 -hex 2>/dev/null | awk '{print $NF}'; }
hmac_sha256_hex() { printf '%s' "$2" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$1" -hex 2>/dev/null | awk '{print $NF}'; }
hex_of_ascii() { 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() {
local method="$1" path="$2" query="${3:-}" body="${4:-}"
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}}${body:+ body=${body}}"
printf '200' > "${ADMIN_API_CODE_FILE}"
return 0
fi
local payload_hash="UNSIGNED-PAYLOAD"
if [ -n "${body}" ]; then
payload_hash="$(sha256_hex "${body}")"
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:${payload_hash}
x-amz-date:${amz_date}
"
signed_headers="host;x-amz-content-sha256;x-amz-date"
canonical_request="${method}
${path}
${query}
${canonical_headers}
${signed_headers}
${payload_hash}"
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_args=()
[ -n "${body}" ] && curl_args+=(--data-binary "${body}")
code="$(curl -sS --max-time "${API_REQUEST_TIMEOUT}" -o "${tmp}" -w '%{http_code}' \
-H "Host: ${host_port}" \
-H "x-amz-content-sha256: ${payload_hash}" \
-H "x-amz-date: ${amz_date}" \
-H "Authorization: ${auth}" \
${curl_args[@]+"${curl_args[@]}"} \
-X "${method}" "${url}")" || code="000"
printf '%s' "${code}" > "${ADMIN_API_CODE_FILE}"
cat "${tmp}"
rm -f "${tmp}"
}
admin_api_code() { cat "${ADMIN_API_CODE_FILE}"; }
get_first_arn() {
local raw arn
raw="$(admin_api GET /rustfs/admin/v3/target/arns "")"
# Prefer the webhook target so assertions run against the webhook receiver.
arn="$(printf '%s' "${raw}" | jq -r '.[] | select(test("webhook"; "i")) | .' 2>/dev/null | head -1)"
if [ -z "${arn}" ]; then
arn="$(printf '%s' "${raw}" | jq -r '.[0] // empty' 2>/dev/null)"
fi
if [ -z "${arn}" ]; then
echo "target/arns returned: ${raw}" >&2
fi
printf '%s' "${arn}"
}
# ==================== Webhook receiver + MQTT subscriber (heal-local) ====================
receiver_install() {
[ "${DRY_RUN}" -eq 1 ] && return 0
cat > "${RECEIVER_SCRIPT}" <<'PYEOF'
#!/usr/bin/env python3
import json, os, sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
NOTIFY = os.environ.get("RUSTFS_NOTIFY_EVENTS", "/tmp/rustfs-notify-events.jsonl")
AUDIT = os.environ.get("RUSTFS_AUDIT_EVENTS", "/tmp/rustfs-audit-events.jsonl")
class H(BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def _record(self, path):
length = int(self.headers.get("Content-Length") or 0)
body = self.rfile.read(length).decode("utf-8", "replace") if length else ""
if path == "/hook":
with open(NOTIFY, "a") as f:
f.write(body + "\n")
elif path == "/audit":
with open(AUDIT, "a") as f:
f.write(body + "\n")
self.send_response(200)
self.send_header("Content-Length", "0")
self.end_headers()
def do_POST(self):
self._record(self.path)
def do_GET(self):
self.send_response(200)
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"ok")
port = int(sys.argv[1]) if len(sys.argv) > 1 else 18080
ThreadingHTTPServer(("0.0.0.0", port), H).serve_forever()
PYEOF
chmod +x "${RECEIVER_SCRIPT}"
: > "${NOTIFY_EVENTS}"
: > "${AUDIT_EVENTS}"
: > "${MQTT_EVENTS}"
}
receiver_start() {
[ "${DRY_RUN}" -eq 1 ] && return 0
receiver_stop
RUSTFS_NOTIFY_EVENTS="${NOTIFY_EVENTS}" RUSTFS_AUDIT_EVENTS="${AUDIT_EVENTS}" \
nohup python3 "${RECEIVER_SCRIPT}" "${RECEIVER_PORT}" >"${TEST_TMP}/rustfs-receiver.log" 2>&1 &
echo $! > "${RECEIVER_PIDFILE}"
local waited=0
while [ "${waited}" -lt 30 ]; do
if curl -sf --max-time 3 "http://127.0.0.1:${RECEIVER_PORT}/health" >/dev/null 2>&1; then
log "webhook receiver up on :${RECEIVER_PORT}"
return 0
fi