3 # Copyright (C) 2018 Red Hat <contact@redhat.com>
5 # Author: David Zafman <dzafman@redhat.com>
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)
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.
18 source $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
24 export CEPH_MON
="127.0.0.1:7221" # git grep '\<7221\>' : there must be only one
26 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
27 CEPH_ARGS
+="--mon-host=$CEPH_MON "
28 CEPH_ARGS
+="--osd_max_backfills=10 "
30 export poolprefix
=test
32 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
33 for func
in $funcs ; do
34 setup
$dir ||
return 1
35 $func $dir ||
return 1
36 teardown
$dir ||
return 1
41 function get_num_in_state
() {
44 expression
+="select(contains(\"${state}\"))"
45 ceph
--format json pg dump pgs
2>/dev
/null | \
46 jq
".pg_stats | [.[] | .state | $expression] | length"
50 function wait_for_state
() {
54 local -a delays
=($
(get_timeout_delays
$2 5))
57 flush_pg_stats ||
return 1
58 while test $
(get_num_pgs
) == 0 ; do
63 cur_in_state
=$
(get_num_in_state
${state})
64 test $cur_in_state = "0" && break
65 if test $cur_in_state != $num_in_state ; then
67 num_in_state
=$cur_in_state
68 elif (( $loop >= ${#delays[*]} )) ; then
72 sleep ${delays[$loop]}
79 function wait_for_recovery_toofull
() {
81 wait_for_state recovery_toofull
$timeout
85 # Create 1 pools with size 1
86 # set ful-ratio to 50%
87 # Write data 600 5K (3000K)
88 # Inject fake_statfs_for_testing to 3600K (83% full)
89 # Incresase the pool size to 2
90 # The pool shouldn't have room to recovery
91 function TEST_recovery_test_simple
() {
96 run_mon
$dir a ||
return 1
97 run_mgr
$dir x ||
return 1
100 for osd
in $
(seq 0 $
(expr $OSDS - 1))
102 run_osd
$dir $osd ||
return 1
105 ceph osd set-nearfull-ratio
.40
106 ceph osd set-backfillfull-ratio
.45
107 ceph osd set-full-ratio
.50
109 for p
in $
(seq 1 $pools)
111 create_pool
"${poolprefix}$p" 1 1
112 ceph osd pool
set "${poolprefix}$p" size
1
115 wait_for_clean ||
return 1
117 dd if=/dev
/urandom of
=$dir/datafile bs
=1024 count
=5
118 for o
in $
(seq 1 $objects)
120 rados
-p "${poolprefix}$p" put obj
$o $dir/datafile
123 for o
in $
(seq 0 $
(expr $OSDS - 1))
125 ceph tell osd.
$o injectargs
'--fake_statfs_for_testing 3686400' ||
return 1
131 for p
in $
(seq 1 $pools)
133 ceph osd pool
set "${poolprefix}$p" size
2
136 # If this times out, we'll detected errors below
137 wait_for_recovery_toofull
30
140 if [ "$(ceph pg dump pgs | grep +recovery_toofull | wc -l)" != "1" ];
142 echo "One pool should have been in recovery_toofull"
143 ERRORS
="$(expr $ERRORS + 1)"
148 ceph status
--format=json-pretty
> $dir/stat.json
150 eval SEV
=$
(jq
'.health.checks.PG_RECOVERY_FULL.severity' $dir/stat.json
)
151 if [ "$SEV" != "HEALTH_ERR" ]; then
152 echo "PG_RECOVERY_FULL severity $SEV not HEALTH_ERR"
153 ERRORS
="$(expr $ERRORS + 1)"
155 eval MSG
=$
(jq
'.health.checks.PG_RECOVERY_FULL.summary.message' $dir/stat.json
)
156 if [ "$MSG" != "Full OSDs blocking recovery: 1 pg recovery_toofull" ]; then
157 echo "PG_RECOVERY_FULL message '$MSG' mismatched"
158 ERRORS
="$(expr $ERRORS + 1)"
162 if [ $ERRORS != "0" ];
167 for i
in $
(seq 1 $pools)
169 delete_pool
"${poolprefix}$i"
171 kill_daemons
$dir ||
return 1
175 main osd-recovery-space
"$@"
178 # compile-command: "make -j4 && ../qa/run-standalone.sh osd-recovery-space.sh"