|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (C) 2024 IBM <[email protected]> |
| 4 | +# |
| 5 | +# Author: Shraddha Agrawal <[email protected]> |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Library Public License as published by |
| 9 | +# the Free Software Foundation; either version 2, or (at your option) |
| 10 | +# any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Library Public License for more details. |
| 16 | +# |
| 17 | + |
| 18 | +source $CEPH_ROOT/qa/standalone/ceph-helpers.sh |
| 19 | + |
| 20 | +function run() { |
| 21 | + local dir=$1 |
| 22 | + shift |
| 23 | + |
| 24 | + export CEPH_MON="127.0.0.1:7124" # git grep '\<7124\>' : there must be only one |
| 25 | + export CEPH_ARGS |
| 26 | + CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " |
| 27 | + CEPH_ARGS+="--mon-host=$CEPH_MON " |
| 28 | + |
| 29 | + local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')} |
| 30 | + for func in $funcs ; do |
| 31 | + setup $dir || return 1 |
| 32 | + $func $dir || return 1 |
| 33 | + teardown $dir || return 1 |
| 34 | + done |
| 35 | +} |
| 36 | + |
| 37 | +function TEST_availablity_score() { |
| 38 | + local dir=$1 |
| 39 | + |
| 40 | + run_mon $dir a || return 1 |
| 41 | + run_mgr $dir x || return 1 |
| 42 | + run_osd $dir 0 || return 1 |
| 43 | + run_osd $dir 1 || return 1 |
| 44 | + run_osd $dir 2 || return 1 |
| 45 | + |
| 46 | + ceph config set osd osd_recovery_delay_start 10000 |
| 47 | + ceph config get osd.* osd_recovery_delay_start |
| 48 | + ceph osd pool create foo 64 |
| 49 | + ceph osd pool set foo size 2 --yes-i-really-mean-it |
| 50 | + |
| 51 | + WAIT_FOR_CLEAN_TIMEOUT=60 wait_for_clean |
| 52 | + ceph osd pool stats |
| 53 | + |
| 54 | + ceph -s |
| 55 | + ceph health | grep HEALTH_OK || return 1 |
| 56 | + ceph osd pool availability-status |
| 57 | + AVAILABILITY_STATUS=$(ceph osd pool availability-status | grep -w "foo") |
| 58 | + SCORE=$(echo "$AVAILABILITY_STATUS" | awk '{print $7}') |
| 59 | + IS_AVAILABLE=$(echo "$AVAILABILITY_STATUS" | awk '{print $8}') |
| 60 | + if [ $IS_AVAILABLE -ne 1 ]; then |
| 61 | + echo "Failed: Pool is not available in availabilty status" |
| 62 | + fi |
| 63 | + |
| 64 | + # write some objects |
| 65 | + for i in $(seq 1 10); do |
| 66 | + rados --pool foo put object_id$i /etc/group; |
| 67 | + done |
| 68 | + |
| 69 | + # kill OSD 0 |
| 70 | + kill_daemons $dir TERM osd.0 >&2 < /dev/null || return 1 |
| 71 | + sleep 10 |
| 72 | + ceph -s |
| 73 | + ceph osd pool availability-status |
| 74 | + |
| 75 | + #write more objects |
| 76 | + for i in $(seq 1 20); do |
| 77 | + rados --pool foo put object_id$i /etc/group; |
| 78 | + done |
| 79 | + |
| 80 | + # bring osd 0 back up |
| 81 | + activate_osd $dir 0 || return 1 |
| 82 | + ceph -s |
| 83 | + ceph osd pool availability-status |
| 84 | + |
| 85 | + # kill osd 1 |
| 86 | + kill_daemons $dir TERM osd.1 >&2 < /dev/null || return 1 |
| 87 | + ceph -s |
| 88 | + ceph osd pool availability-status |
| 89 | + |
| 90 | + # wait for 10 seconds so availability score is refreshed |
| 91 | + # check ceph heath and availability score |
| 92 | + sleep 10 |
| 93 | + ceph -s |
| 94 | + ceph osd pool availability-status |
| 95 | + AVAILABILITY_STATUS=$(ceph osd pool availability-status | grep -w "foo") |
| 96 | + IS_AVAILABLE=$(echo "$AVAILABILITY_STATUS" | awk '{print $8}') |
| 97 | + NEW_SCORE=$(echo "$AVAILABILITY_STATUS" | awk '{print $7}') |
| 98 | + if [ $IS_AVAILABLE -ne 0 ]; then |
| 99 | + echo "Failed: Pool is available in availabilty status when unfound objects present" |
| 100 | + return 1 |
| 101 | + fi |
| 102 | + if (( $(echo "$NEW_SCORE >= $SCORE" | bc -l) )); then |
| 103 | + echo "Failed: Availability score for the pool did not drop" |
| 104 | + return 1 |
| 105 | + fi |
| 106 | + |
| 107 | + echo "TEST PASSED" |
| 108 | + return 0 |
| 109 | +} |
| 110 | + |
| 111 | +main availability "$@" |
0 commit comments