|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Tests of allowing a read only Upstairs with < 3 running downstairs |
| 4 | +# We do an initial RW fill, and record what data we expect |
| 5 | +# Then, stop and restart the downstairs as read only. |
| 6 | +# Loop over 1 missing downstairs, activate and verify our volume. |
| 7 | +# Loop over 2 missing downstairs, activate and verify our volume. |
| 8 | +set -o pipefail |
| 9 | +SECONDS=0 |
| 10 | + |
| 11 | +ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 12 | +BINDIR=${BINDIR:-$ROOT/target/debug} |
| 13 | + |
| 14 | +echo "$ROOT" |
| 15 | +cd "$ROOT" || (echo failed to cd "$ROOT"; exit 1) |
| 16 | + |
| 17 | +if pgrep -fl crucible-downstairs; then |
| 18 | + echo 'Downstairs already running?' >&2 |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +cds="$BINDIR/crucible-downstairs" |
| 23 | +crutest="$BINDIR/crutest" |
| 24 | +dsc="$BINDIR/dsc" |
| 25 | +for bin in $cds $crutest $dsc; do |
| 26 | + if [[ ! -f "$bin" ]]; then |
| 27 | + echo "Can't find crucible binary at $bin" >&2 |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | +done |
| 31 | + |
| 32 | +# Use the id of the current user to make a unique path |
| 33 | +user=$(id -u -n) |
| 34 | +# Downstairs regions go in this directory |
| 35 | +testdir="/var/tmp/test_read_only-$user" |
| 36 | +if [[ -d "$testdir" ]]; then |
| 37 | + rm -rf "$testdir" |
| 38 | +fi |
| 39 | + |
| 40 | +# Store log files we want to keep in /tmp/test_read_only-$user/.txt as this is what |
| 41 | +# buildomat will look for and archive |
| 42 | +test_output_dir="/tmp/test_read_only-$user" |
| 43 | +rm -rf "$test_output_dir" 2> /dev/null |
| 44 | +mkdir -p "$test_output_dir" |
| 45 | +log_prefix="${test_output_dir}/test_read_only" |
| 46 | +fail_log="${log_prefix}_fail.txt" |
| 47 | +rm -f "$fail_log" |
| 48 | +verify_file="${log_prefix}_verify" |
| 49 | +rm -f "$verify_file" |
| 50 | +test_log="${log_prefix}_log" |
| 51 | +rm -f "$test_log" |
| 52 | +dsc_output_dir="${test_output_dir}/dsc" |
| 53 | +mkdir -p "$dsc_output_dir" |
| 54 | +dsc_output="${test_output_dir}/dsc-out.txt" |
| 55 | +echo "dsc output goes to $dsc_output" |
| 56 | + |
| 57 | +region_count=3 |
| 58 | +args=() |
| 59 | +dsc_args=() |
| 60 | +dsc_create_args=() |
| 61 | +upstairs_key=$(openssl rand -base64 32) |
| 62 | +echo "Upstairs using key: $upstairs_key" | tee -a "$test_log" |
| 63 | + |
| 64 | +args+=( --key "$upstairs_key" ) |
| 65 | +args+=( --dsc "127.0.0.1:9998" ) |
| 66 | +dsc_create_args+=( --encrypted ) |
| 67 | +dsc_create_args+=( --cleanup ) |
| 68 | +dsc_args+=( --output-dir "$dsc_output_dir" ) |
| 69 | +dsc_args+=( --ds-bin "$cds" ) |
| 70 | +dsc_args+=( --region-dir "$testdir" ) |
| 71 | + |
| 72 | +# Control-C to cleanup. |
| 73 | +trap ctrl_c INT |
| 74 | +function ctrl_c() { |
| 75 | + echo "Stopping at your request" | tee -a "$test_log" |
| 76 | + ${dsc} cmd shutdown |
| 77 | + exit 1 |
| 78 | +} |
| 79 | + |
| 80 | +echo "Creating $region_count downstairs regions" |
| 81 | +echo "${dsc}" create "${dsc_create_args[@]}" --region-count "$region_count" --extent-size 10 --extent-count 5 "${dsc_args[@]}" > "$dsc_output" |
| 82 | +"${dsc}" create "${dsc_create_args[@]}" --region-count "$region_count" --extent-size 10 --extent-count 5 "${dsc_args[@]}" >> "$dsc_output" 2>&1 |
| 83 | + |
| 84 | +echo "Starting $region_count downstairs" |
| 85 | +echo "${dsc}" start "${dsc_args[@]}" --region-count "$region_count" >> "$dsc_output" |
| 86 | +"${dsc}" start "${dsc_args[@]}" --region-count "$region_count" >> "$dsc_output" 2>&1 & |
| 87 | +dsc_pid=$! |
| 88 | +echo "dsc started at PID: $dsc_pid" |
| 89 | + |
| 90 | +while "$dsc" cmd all-running | grep false > /dev/null ; do |
| 91 | + echo "Wait for all clients to be running." |
| 92 | + sleep 3 |
| 93 | +done |
| 94 | + |
| 95 | +echo "" |
| 96 | +echo "Begin tests, output goes to $test_log" |
| 97 | +gen=1 |
| 98 | + |
| 99 | +# Initial fill and creation of verify file for future use. |
| 100 | +echo "$crutest" generic -g $gen "${args[@]}" --stable --verify-out "$verify_file" -c 250 | tee -a "$test_log" |
| 101 | +if ! "$crutest" generic -g $gen "${args[@]}" --stable --verify-out "$verify_file" -c 250 >> "$test_log"; then |
| 102 | + echo "Failed initial fill" |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | +(( gen += 1 )) |
| 106 | + |
| 107 | +echo "Shutdown dsc" | tee -a "$test_log" |
| 108 | +"$dsc" cmd shutdown |
| 109 | +wait $dsc_pid |
| 110 | + |
| 111 | +echo "Starting dsc in read only mode with $region_count downstairs" | tee -a "$test_log" |
| 112 | +echo "${dsc}" start "${dsc_args[@]}" --read-only --region-count $region_count >> "$dsc_output" |
| 113 | +"${dsc}" start "${dsc_args[@]}" --read-only --region-count $region_count >> "$dsc_output" 2>&1 & |
| 114 | +dsc_pid=$! |
| 115 | +echo "dsc started at PID: $dsc_pid" | tee -a "$test_log" |
| 116 | + |
| 117 | +loop=0 |
| 118 | +while [[ "$loop" -lt 10 ]]; do |
| 119 | + echo "$(date) Begin loop $loop" | tee -a "$test_log" |
| 120 | + # Begin with all downstairs running |
| 121 | + "$dsc" cmd start-all | tee -a "$test_log" |
| 122 | + |
| 123 | + # In this First loop, we just turn off one downstairs and then verify our |
| 124 | + # volume with two downstairs running. |
| 125 | + for cid in {0..2}; do |
| 126 | + |
| 127 | + while "$dsc" cmd all-running | grep false > /dev/null ; do |
| 128 | + echo "Wait for all clients to be running." | tee -a "$test_log" |
| 129 | + sleep 3 |
| 130 | + done |
| 131 | + |
| 132 | + echo "Stop downstairs $cid" | tee -a "$test_log" |
| 133 | + "$dsc" cmd stop -c "$cid" | tee -a "$test_log" |
| 134 | + |
| 135 | + while ! "$dsc" cmd state -c "$cid" | grep Exit > /dev/null; do |
| 136 | + echo "Waiting for client $cid to stop" | tee -a "$test_log" |
| 137 | + sleep 3 |
| 138 | + done |
| 139 | + |
| 140 | + echo "Run verify test with downstairs $cid stopped" | tee -a "$test_log" |
| 141 | + echo "$crutest" verify -g "$gen" "${args[@]}" -q --verify-in "$verify_file" --read-only | tee -a "$test_log" |
| 142 | + if ! "$crutest" verify -g "$gen" "${args[@]}" -q --verify-in "$verify_file" --read-only >> "$test_log" 2>&1 ; then |
| 143 | + echo "Failed first test at loop $loop, cid: $cid" |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | + |
| 147 | + echo "Start downstairs $cid" | tee -a "$test_log" |
| 148 | + "$dsc" cmd start -c "$cid" | tee -a "$test_log" |
| 149 | + |
| 150 | + done |
| 151 | + |
| 152 | + while "$dsc" cmd all-running | grep false > /dev/null ; do |
| 153 | + echo "Wait for all clients to be running." | tee -a "$test_log" |
| 154 | + sleep 3 |
| 155 | + done |
| 156 | + |
| 157 | + # Begin the next loop with all downstairs stopped |
| 158 | + echo "Stopping all downstairs" | tee -a "$test_log" |
| 159 | + "$dsc" cmd stop-all |
| 160 | + |
| 161 | + # Second loop. Here we just start just one downstairs (leaving all the |
| 162 | + # other downstairs stopped) |
| 163 | + for cid in {0..2}; do |
| 164 | + |
| 165 | + echo "Start just downstairs $cid" | tee -a "$test_log" |
| 166 | + "$dsc" cmd start -c "$cid" |
| 167 | + |
| 168 | + # Wait for just our one downstairs to be running. |
| 169 | + for stopped_cid in {0..2}; do |
| 170 | + if [[ "$stopped_cid" -eq "$cid" ]]; then |
| 171 | + continue |
| 172 | + fi |
| 173 | + while ! "$dsc" cmd state -c "$stopped_cid" | grep Exit > /dev/null; do |
| 174 | + echo "Waiting for client $stopped_cid to stop" | tee -a "$test_log" |
| 175 | + sleep 3 |
| 176 | + done |
| 177 | + done |
| 178 | + |
| 179 | + echo "Run read only test with only downstairs $cid running" | tee -a "$test_log" |
| 180 | + echo "$crutest" verify -g "$gen" "${args[@]}" -q --verify-in "$verify_file" --read-only >> "$test_log" |
| 181 | + if ! "$crutest" verify -g "$gen" "${args[@]}" -q --verify-in "$verify_file" --read-only >> "$test_log" 2>&1 ; then |
| 182 | + echo "Failed second test at loop $loop, cid: $cid" |
| 183 | + exit 1 |
| 184 | + fi |
| 185 | + |
| 186 | + # stop downstairs $cid |
| 187 | + echo "Stop downstairs $cid" | tee -a "$test_log" |
| 188 | + "$dsc" cmd stop -c "$cid" |
| 189 | + |
| 190 | + done |
| 191 | + echo "$(date) End of loop $loop" | tee -a "$test_log" |
| 192 | + ((loop += 1)) |
| 193 | +done |
| 194 | + |
| 195 | +## loop done |
| 196 | +echo "Shutdown dsc" | tee -a "$test_log" |
| 197 | +"$dsc" cmd shutdown |
| 198 | +wait $dsc_pid |
| 199 | + |
| 200 | +duration=$SECONDS |
| 201 | +printf "Test with %d loops took: %d:%02d\n" \ |
| 202 | + "$loop" $((duration / 60)) $((duration % 60)) | tee -a "$test_log" |
0 commit comments