You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.2 KiB

  1. #!/bin/bash -e
  2. set -E
  3. set -o pipefail
  4. set -x
  5. if [ ! -x "$PWD/minio" ]; then
  6. echo "minio executable binary not found in current directory"
  7. exit 1
  8. fi
  9. WORK_DIR="$(mktemp -d)"
  10. MINIO_CONFIG_DIR="$WORK_DIR/.minio"
  11. MINIO=("$PWD/minio" --config-dir "$MINIO_CONFIG_DIR" server)
  12. function start_minio() {
  13. start_port=$1
  14. export MINIO_ROOT_USER=minio
  15. export MINIO_ROOT_PASSWORD=minio123
  16. unset MINIO_KMS_AUTO_ENCRYPTION # do not auto-encrypt objects
  17. unset MINIO_CI_CD
  18. unset CI
  19. args=()
  20. for i in $(seq 1 4); do
  21. args+=("http://localhost:$((start_port + i))${WORK_DIR}/mnt/disk$i/ ")
  22. done
  23. for i in $(seq 1 4); do
  24. "${MINIO[@]}" --address ":$((start_port + i))" ${args[@]} 2>&1 >"${WORK_DIR}/server$i.log" &
  25. done
  26. # Wait until all nodes return 403
  27. for i in $(seq 1 4); do
  28. while [ "$(curl -m 1 -s -o /dev/null -w "%{http_code}" http://localhost:$((start_port + i)))" -ne "403" ]; do
  29. echo -n "."
  30. sleep 1
  31. done
  32. done
  33. }
  34. # Prepare fake disks with losetup
  35. function prepare_block_devices() {
  36. set -e
  37. mkdir -p ${WORK_DIR}/disks/ ${WORK_DIR}/mnt/
  38. sudo modprobe loop
  39. for i in 1 2 3 4; do
  40. dd if=/dev/zero of=${WORK_DIR}/disks/img.${i} bs=1M count=2000
  41. device=$(sudo losetup --find --show ${WORK_DIR}/disks/img.${i})
  42. sudo mkfs.ext4 -F ${device}
  43. mkdir -p ${WORK_DIR}/mnt/disk${i}/
  44. sudo mount ${device} ${WORK_DIR}/mnt/disk${i}/
  45. sudo chown "$(id -u):$(id -g)" ${device} ${WORK_DIR}/mnt/disk${i}/
  46. done
  47. set +e
  48. }
  49. # Start a distributed MinIO setup, unmount one disk and check if it is formatted
  50. function main() {
  51. start_port=$(shuf -i 10000-65000 -n 1)
  52. start_minio ${start_port}
  53. # Unmount the disk, after the unmount the device id
  54. # /tmp/xxx/mnt/disk4 will be the same as '/' and it
  55. # will be detected as root disk
  56. while [ "$u" != "0" ]; do
  57. sudo umount ${WORK_DIR}/mnt/disk4/
  58. u=$?
  59. sleep 1
  60. done
  61. # Wait until MinIO self heal kicks in
  62. sleep 60
  63. if [ -f ${WORK_DIR}/mnt/disk4/.minio.sys/format.json ]; then
  64. echo "A root disk is formatted unexpectedely"
  65. cat "${WORK_DIR}/server4.log"
  66. exit -1
  67. fi
  68. }
  69. function cleanup() {
  70. pkill minio
  71. sudo umount ${WORK_DIR}/mnt/disk{1..3}/
  72. sudo rm /dev/minio-loopdisk*
  73. rm -rf "$WORK_DIR"
  74. }
  75. (prepare_block_devices)
  76. (main "$@")
  77. rv=$?
  78. cleanup
  79. exit "$rv"