]> git.proxmox.com Git - ceph.git/blame - ceph/qa/standalone/crush/crush-choose-args.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / qa / standalone / crush / crush-choose-args.sh
CommitLineData
11fdf7f2 1#!/usr/bin/env bash
31f18b77
FG
2#
3# Copyright (C) 2017 Red Hat <contact@redhat.com>
4#
5# Author: Loic Dachary <loic@dachary.org>
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
c07f9fc5 18source $CEPH_ROOT/qa/standalone/ceph-helpers.sh
31f18b77
FG
19
20function run() {
21 local dir=$1
22 shift
23
24 export CEPH_MON="127.0.0.1:7131" # git grep '\<7131\>' : 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 CEPH_ARGS+="--crush-location=root=default,host=HOST "
29 CEPH_ARGS+="--osd-crush-initial-weight=3 "
224ce89b
WB
30 #
31 # Disable device auto class feature for now.
32 # The device class is non-deterministic and will
33 # crash the crushmap comparison below.
34 #
35 CEPH_ARGS+="--osd-class-update-on-start=false "
31f18b77
FG
36
37 local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
38 for func in $funcs ; do
39 setup $dir || return 1
40 $func $dir || return 1
41 teardown $dir || return 1
42 done
43}
44
45function TEST_choose_args_update() {
46 #
47 # adding a weighted OSD updates the weight up to the top
48 #
49 local dir=$1
50
51 run_mon $dir a || return 1
11fdf7f2 52 run_mgr $dir x || return 1
31f18b77
FG
53 run_osd $dir 0 || return 1
54
c07f9fc5 55 ceph osd set-require-min-compat-client luminous
31f18b77
FG
56 ceph osd getcrushmap > $dir/map || return 1
57 crushtool -d $dir/map -o $dir/map.txt || return 1
58 sed -i -e '/end crush map/d' $dir/map.txt
59 cat >> $dir/map.txt <<EOF
60# choose_args
61choose_args 0 {
62 {
63 bucket_id -1
64 weight_set [
11fdf7f2
TL
65 [ 2.000 ]
66 [ 2.000 ]
31f18b77
FG
67 ]
68 ids [ -10 ]
69 }
70 {
71 bucket_id -2
72 weight_set [
73 [ 2.000 ]
74 [ 2.000 ]
75 ]
76 ids [ -20 ]
77 }
78}
79
80# end crush map
81EOF
82 crushtool -c $dir/map.txt -o $dir/map-new || return 1
83 ceph osd setcrushmap -i $dir/map-new || return 1
11fdf7f2 84 ceph osd crush tree
31f18b77
FG
85
86 run_osd $dir 1 || return 1
11fdf7f2 87 ceph osd crush tree
31f18b77
FG
88 ceph osd getcrushmap > $dir/map-one-more || return 1
89 crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
90 cat $dir/map-one-more.txt
91 diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-3.txt || return 1
92
93 destroy_osd $dir 1 || return 1
11fdf7f2 94 ceph osd crush tree
31f18b77
FG
95 ceph osd getcrushmap > $dir/map-one-less || return 1
96 crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
c07f9fc5 97 diff -u $dir/map-one-less.txt $dir/map.txt || return 1
31f18b77
FG
98}
99
100function TEST_no_update_weight_set() {
101 #
102 # adding a zero weight OSD does not update the weight set at all
103 #
104 local dir=$1
105
106 ORIG_CEPH_ARGS="$CEPH_ARGS"
107 CEPH_ARGS+="--osd-crush-update-weight-set=false "
108
109 run_mon $dir a || return 1
11fdf7f2 110 run_mgr $dir x || return 1
31f18b77
FG
111 run_osd $dir 0 || return 1
112
c07f9fc5
FG
113 ceph osd set-require-min-compat-client luminous
114 ceph osd crush tree
31f18b77
FG
115 ceph osd getcrushmap > $dir/map || return 1
116 crushtool -d $dir/map -o $dir/map.txt || return 1
117 sed -i -e '/end crush map/d' $dir/map.txt
118 cat >> $dir/map.txt <<EOF
119# choose_args
120choose_args 0 {
121 {
122 bucket_id -1
123 weight_set [
c07f9fc5
FG
124 [ 2.000 ]
125 [ 1.000 ]
31f18b77
FG
126 ]
127 ids [ -10 ]
128 }
129 {
130 bucket_id -2
131 weight_set [
132 [ 2.000 ]
c07f9fc5 133 [ 1.000 ]
31f18b77
FG
134 ]
135 ids [ -20 ]
136 }
137}
138
139# end crush map
140EOF
141 crushtool -c $dir/map.txt -o $dir/map-new || return 1
142 ceph osd setcrushmap -i $dir/map-new || return 1
c07f9fc5 143 ceph osd crush tree
31f18b77
FG
144
145
146 run_osd $dir 1 || return 1
c07f9fc5 147 ceph osd crush tree
31f18b77
FG
148 ceph osd getcrushmap > $dir/map-one-more || return 1
149 crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
150 cat $dir/map-one-more.txt
151 diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-0.txt || return 1
152
153 destroy_osd $dir 1 || return 1
c07f9fc5 154 ceph osd crush tree
31f18b77
FG
155 ceph osd getcrushmap > $dir/map-one-less || return 1
156 crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
157 diff -u $dir/map-one-less.txt $dir/map.txt || return 1
158
159 CEPH_ARGS="$ORIG_CEPH_ARGS"
160}
161
11fdf7f2
TL
162function TEST_reweight() {
163 # reweight and reweight-compat behave appropriately
164 local dir=$1
165
166 ORIG_CEPH_ARGS="$CEPH_ARGS"
167 CEPH_ARGS+="--osd-crush-update-weight-set=false "
168
169 run_mon $dir a || return 1
170 run_mgr $dir x || return 1
171 run_osd $dir 0 || return 1
172 run_osd $dir 1 || return 1
173
174 ceph osd crush weight-set create-compat || return 1
175 ceph osd crush tree
176
177 ceph osd crush weight-set reweight-compat osd.0 2 || return 1
178 ceph osd crush tree
9f95a23c 179 ceph osd crush tree | grep host | grep '6.00000 5.00000' || return 1
11fdf7f2
TL
180
181 run_osd $dir 2 || return 1
182 ceph osd crush tree
9f95a23c 183 ceph osd crush tree | grep host | grep '9.00000 5.00000' || return 1
11fdf7f2
TL
184
185 ceph osd crush reweight osd.2 4
186 ceph osd crush tree
9f95a23c 187 ceph osd crush tree | grep host | grep '10.00000 5.00000' || return 1
11fdf7f2
TL
188
189 ceph osd crush weight-set reweight-compat osd.2 4
190 ceph osd crush tree
9f95a23c 191 ceph osd crush tree | grep host | grep '10.00000 9.00000' || return 1
11fdf7f2
TL
192}
193
194function TEST_move_bucket() {
195 local dir=$1
196
197 run_mon $dir a || return 1
198 run_mgr $dir x || return 1
199 run_osd $dir 0 || return 1
200 run_osd $dir 1 || return 1
201
202 ceph osd crush weight-set create-compat || return 1
203 ceph osd crush weight-set reweight-compat osd.0 2 || return 1
204 ceph osd crush weight-set reweight-compat osd.1 2 || return 1
205 ceph osd crush tree
9f95a23c 206 ceph osd crush tree | grep HOST | grep '6.00000 4.00000' || return 1
11fdf7f2
TL
207
208 # moving a bucket adjusts the weights
209 ceph osd crush add-bucket RACK rack root=default || return 1
210 ceph osd crush move HOST rack=RACK || return 1
211 ceph osd crush tree
9f95a23c
TL
212 ceph osd crush tree | grep HOST | grep '6.00000 4.00000' || return 1
213 ceph osd crush tree | grep RACK | grep '6.00000 4.00000' || return 1
11fdf7f2
TL
214
215 # weight-set reweight adjusts containing buckets
216 ceph osd crush weight-set reweight-compat osd.0 1 || return 1
217 ceph osd crush tree
9f95a23c
TL
218 ceph osd crush tree | grep HOST | grep '6.00000 3.00000' || return 1
219 ceph osd crush tree | grep RACK | grep '6.00000 3.00000' || return 1
11fdf7f2
TL
220
221 # moving a leaf resets its weight-set to the canonical weight...
222 ceph config set mon osd_crush_update_weight_set true || return 1
223 ceph osd crush add-bucket FOO host root=default || return 1
224 ceph osd crush move osd.0 host=FOO || return 1
225 ceph osd crush tree
9f95a23c
TL
226 ceph osd crush tree | grep osd.0 | grep '3.00000 3.00000' || return 1
227 ceph osd crush tree | grep HOST | grep '3.00000 2.00000' || return 1
228 ceph osd crush tree | grep RACK | grep '3.00000 2.00000' || return 1
11fdf7f2
TL
229
230 # ...or to zero.
231 ceph config set mon osd_crush_update_weight_set false || return 1
232 ceph osd crush move osd.1 host=FOO || return 1
233 ceph osd crush tree
9f95a23c
TL
234 ceph osd crush tree | grep osd.0 | grep '3.00000 3.00000' || return 1
235 ceph osd crush tree | grep osd.1 | grep '3.00000 0' || return 1
236 ceph osd crush tree | grep FOO | grep '6.00000 3.00000' || return 1
11fdf7f2
TL
237}
238
31f18b77
FG
239main crush-choose-args "$@"
240
241# Local Variables:
242# compile-command: "cd ../../../build ; ln -sf ../src/ceph-disk/ceph_disk/main.py bin/ceph-disk && make -j4 && ../src/test/crush/crush-choose-args.sh"
243# End: