3 # Copyright (C) 2019 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.
17 source $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
23 export CEPH_MON
="127.0.0.1:7102" # git grep '\<7102\>' : there must be only one
25 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
26 CEPH_ARGS
+="--mon-host=$CEPH_MON "
28 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
29 for func
in $funcs ; do
30 $func $dir ||
return 1
37 function TEST_balancer
() {
40 setup
$dir ||
return 1
41 run_mon
$dir a ||
return 1
42 run_mgr
$dir x ||
return 1
43 run_osd
$dir 0 ||
return 1
44 run_osd
$dir 1 ||
return 1
45 run_osd
$dir 2 ||
return 1
46 create_pool
$TEST_POOL1 8
47 create_pool
$TEST_POOL2 8
49 wait_for_clean ||
return 1
52 ceph osd set-require-min-compat-client luminous
53 ceph balancer status ||
return 1
54 eval MODE
=$
(ceph balancer status | jq
'.mode')
55 test $MODE = "none" ||
return 1
56 ACTIVE
=$
(ceph balancer status | jq
'.active')
57 test $ACTIVE = "false" ||
return 1
59 ceph balancer
ls ||
return 1
60 PLANS
=$
(ceph balancer
ls)
61 test "$PLANS" = "[]" ||
return 1
62 ceph balancer
eval ||
return 1
63 EVAL
="$(ceph balancer eval)"
64 test "$EVAL" = "current cluster score 0.000000 (lower is better)"
65 ceph balancer eval-verbose ||
return 1
67 ceph balancer pool add
$TEST_POOL1 ||
return 1
68 ceph balancer pool add
$TEST_POOL2 ||
return 1
69 ceph balancer pool
ls ||
return 1
70 eval POOL
=$
(ceph balancer pool
ls | jq
'sort | .[0]')
71 test "$POOL" = "$TEST_POOL1" ||
return 1
72 eval POOL
=$
(ceph balancer pool
ls | jq
'sort | .[1]')
73 test "$POOL" = "$TEST_POOL2" ||
return 1
74 ceph balancer pool
rm $TEST_POOL1 ||
return 1
75 ceph balancer pool
rm $TEST_POOL2 ||
return 1
76 ceph balancer pool
ls ||
return 1
77 ceph balancer pool add
$TEST_POOL1 ||
return 1
79 ceph balancer mode crush-compat ||
return 1
80 ceph balancer status ||
return 1
81 eval MODE
=$
(ceph balancer status | jq
'.mode')
82 test $MODE = "crush-compat" ||
return 1
83 ! ceph balancer optimize plan_crush
$TEST_POOL1 ||
return 1
84 ceph balancer status ||
return 1
85 eval RESULT
=$
(ceph balancer status | jq
'.optimize_result')
86 test "$RESULT" = "Distribution is already perfect" ||
return 1
88 ceph balancer on ||
return 1
89 ACTIVE
=$
(ceph balancer status | jq
'.active')
90 test $ACTIVE = "true" ||
return 1
92 ceph balancer status ||
return 1
93 ceph balancer off ||
return 1
94 ACTIVE
=$
(ceph balancer status | jq
'.active')
95 test $ACTIVE = "false" ||
return 1
98 ceph balancer
reset ||
return 1
100 ceph balancer mode upmap ||
return 1
101 ceph balancer status ||
return 1
102 eval MODE
=$
(ceph balancer status | jq
'.mode')
103 test $MODE = "upmap" ||
return 1
104 ! ceph balancer optimize plan_upmap
$TEST_POOL ||
return 1
105 ceph balancer status ||
return 1
106 eval RESULT
=$
(ceph balancer status | jq
'.optimize_result')
107 test "$RESULT" = "Unable to find further optimization, or pool(s) pg_num is decreasing, or distribution is already perfect" ||
return 1
109 ceph balancer on ||
return 1
110 ACTIVE
=$
(ceph balancer status | jq
'.active')
111 test $ACTIVE = "true" ||
return 1
113 ceph balancer status ||
return 1
114 ceph balancer off ||
return 1
115 ACTIVE
=$
(ceph balancer status | jq
'.active')
116 test $ACTIVE = "false" ||
return 1
118 teardown
$dir ||
return 1
121 function TEST_balancer2
() {
125 TOTAL_PGS
=$
(expr $TEST_PGS1 + $TEST_PGS2)
128 # Integer average of PGS per OSD (70.8), so each OSD >= this
129 FINAL_PER_OSD1
=$
(expr \
( $TEST_PGS1 \
* $DEFAULT_REPLICAS \
) / $OSDS)
130 # Integer average of PGS per OSD (150)
131 FINAL_PER_OSD2
=$
(expr \
( \
( $TEST_PGS1 + $TEST_PGS2 \
) \
* $DEFAULT_REPLICAS \
) / $OSDS)
133 CEPH_ARGS
+="--osd_pool_default_pg_autoscale_mode=off "
134 CEPH_ARGS
+="--debug_osd=20 "
135 setup
$dir ||
return 1
136 run_mon
$dir a ||
return 1
137 run_mgr
$dir x ||
return 1
138 for i
in $
(seq 0 $
(expr $OSDS - 1))
140 run_osd
$dir $i ||
return 1
143 ceph osd set-require-min-compat-client luminous
144 ceph config
set mgr mgr
/balancer
/upmap_max_deviation
1
145 ceph balancer mode upmap ||
return 1
146 ceph balancer on ||
return 1
147 ceph config
set mgr mgr
/balancer
/sleep_interval
5
149 create_pool
$TEST_POOL1 $TEST_PGS1
151 wait_for_clean ||
return 1
153 # Wait up to 2 minutes
158 if grep -q "Optimization plan is almost perfect" $dir/mgr.x.log
164 test $OK = "yes" ||
return 1
165 # Plan is found, but PGs still need to move
167 wait_for_clean ||
return 1
170 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[0].pgs')
171 test $PGS -ge $FINAL_PER_OSD1 ||
return 1
172 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[1].pgs')
173 test $PGS -ge $FINAL_PER_OSD1 ||
return 1
174 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[2].pgs')
175 test $PGS -ge $FINAL_PER_OSD1 ||
return 1
176 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[3].pgs')
177 test $PGS -ge $FINAL_PER_OSD1 ||
return 1
178 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[4].pgs')
179 test $PGS -ge $FINAL_PER_OSD1 ||
return 1
181 create_pool
$TEST_POOL2 $TEST_PGS2
183 # Wait up to 2 minutes
188 COUNT
=$
(grep "Optimization plan is almost perfect" $dir/mgr.x.log |
wc -l)
195 test $OK = "yes" ||
return 1
196 # Plan is found, but PGs still need to move
198 wait_for_clean ||
return 1
201 # We should be with plus or minus 2 of FINAL_PER_OSD2
202 # This is because here each pool is balanced independently
203 MIN
=$
(expr $FINAL_PER_OSD2 - 2)
204 MAX
=$
(expr $FINAL_PER_OSD2 + 2)
205 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[0].pgs')
206 test $PGS -ge $MIN -a $PGS -le $MAX ||
return 1
207 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[1].pgs')
208 test $PGS -ge $MIN -a $PGS -le $MAX ||
return 1
209 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[2].pgs')
210 test $PGS -ge $MIN -a $PGS -le $MAX ||
return 1
211 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[3].pgs')
212 test $PGS -ge $MIN -a $PGS -le $MAX ||
return 1
213 PGS
=$
(ceph osd df
--format=json-pretty | jq
'.nodes[4].pgs')
214 test $PGS -ge $MIN -a $PGS -le $MAX ||
return 1
216 teardown
$dir ||
return 1
222 # compile-command: "make -j4 && ../qa/run-standalone.sh balancer.sh"