]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/osd-crush.sh
update sources to v12.1.1
[ceph.git] / ceph / src / test / mon / osd-crush.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
4 # Copyright (C) 2014, 2015 Red Hat <contact@redhat.com>
5 #
6 # Author: Loic Dachary <loic@dachary.org>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Library Public License for more details.
17 #
18 source $(dirname $0)/../detect-build-env-vars.sh
19 source $CEPH_ROOT/qa/workunits/ceph-helpers.sh
20
21 function run() {
22 local dir=$1
23 shift
24
25 export CEPH_MON="127.0.0.1:7104" # git grep '\<7104\>' : there must be only one
26 export CEPH_ARGS
27 CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
28 CEPH_ARGS+="--mon-host=$CEPH_MON "
29
30 local funcs=${@:-$(set | ${SED} -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
31 for func in $funcs ; do
32 setup $dir || return 1
33 $func $dir || return 1
34 teardown $dir || return 1
35 done
36 }
37
38 function TEST_crush_rule_create_simple() {
39 local dir=$1
40
41 run_mon $dir a || return 1
42
43 ceph --format xml osd crush rule dump replicated_rule | \
44 egrep '<op>take</op><item>[^<]+</item><item_name>default</item_name>' | \
45 grep '<op>choose_firstn</op><num>0</num><type>osd</type>' || return 1
46 local ruleset=ruleset0
47 local root=host1
48 ceph osd crush add-bucket $root host
49 local failure_domain=osd
50 ceph osd crush rule create-simple $ruleset $root $failure_domain || return 1
51 ceph osd crush rule create-simple $ruleset $root $failure_domain 2>&1 | \
52 grep "$ruleset already exists" || return 1
53 ceph --format xml osd crush rule dump $ruleset | \
54 egrep '<op>take</op><item>[^<]+</item><item_name>'$root'</item_name>' | \
55 grep '<op>choose_firstn</op><num>0</num><type>'$failure_domain'</type>' || return 1
56 ceph osd crush rule rm $ruleset || return 1
57 }
58
59 function TEST_crush_rule_dump() {
60 local dir=$1
61
62 run_mon $dir a || return 1
63
64 local ruleset=ruleset1
65 ceph osd crush rule create-erasure $ruleset || return 1
66 test $(ceph --format json osd crush rule dump $ruleset | \
67 jq ".rule_name == \"$ruleset\"") == true || return 1
68 test $(ceph --format json osd crush rule dump | \
69 jq "map(select(.rule_name == \"$ruleset\")) | length == 1") == true || return 1
70 ! ceph osd crush rule dump non_existent_ruleset || return 1
71 ceph osd crush rule rm $ruleset || return 1
72 }
73
74 function TEST_crush_rule_rm() {
75 local ruleset=erasure2
76
77 run_mon $dir a || return 1
78
79 ceph osd crush rule create-erasure $ruleset default || return 1
80 ceph osd crush rule ls | grep $ruleset || return 1
81 ceph osd crush rule rm $ruleset || return 1
82 ! ceph osd crush rule ls | grep $ruleset || return 1
83 }
84
85 function TEST_crush_rule_create_erasure() {
86 local dir=$1
87
88 run_mon $dir a || return 1
89 # should have at least one OSD
90 run_osd $dir 0 || return 1
91
92 local ruleset=ruleset3
93 #
94 # create a new ruleset with the default profile, implicitly
95 #
96 ceph osd crush rule create-erasure $ruleset || return 1
97 ceph osd crush rule create-erasure $ruleset 2>&1 | \
98 grep "$ruleset already exists" || return 1
99 ceph --format xml osd crush rule dump $ruleset | \
100 egrep '<op>take</op><item>[^<]+</item><item_name>default</item_name>' | \
101 grep '<op>chooseleaf_indep</op><num>0</num><type>host</type>' || return 1
102 ceph osd crush rule rm $ruleset || return 1
103 ! ceph osd crush rule ls | grep $ruleset || return 1
104 #
105 # create a new ruleset with the default profile, explicitly
106 #
107 ceph osd crush rule create-erasure $ruleset default || return 1
108 ceph osd crush rule ls | grep $ruleset || return 1
109 ceph osd crush rule rm $ruleset || return 1
110 ! ceph osd crush rule ls | grep $ruleset || return 1
111 #
112 # create a new ruleset and the default profile, implicitly
113 #
114 ceph osd erasure-code-profile rm default || return 1
115 ! ceph osd erasure-code-profile ls | grep default || return 1
116 ceph osd crush rule create-erasure $ruleset || return 1
117 CEPH_ARGS='' ceph --admin-daemon $dir/ceph-mon.a.asok log flush || return 1
118 grep 'profile set default' $dir/mon.a.log || return 1
119 ceph osd erasure-code-profile ls | grep default || return 1
120 ceph osd crush rule rm $ruleset || return 1
121 ! ceph osd crush rule ls | grep $ruleset || return 1
122 }
123
124 function check_ruleset_id_match_rule_id() {
125 local rule_name=$1
126 rule_id=`ceph osd crush rule dump $rule_name | grep "\"rule_id\":" | awk -F ":|," '{print int($2)}'`
127 ruleset_id=`ceph osd crush rule dump $rule_name | grep "\"ruleset\":"| awk -F ":|," '{print int($2)}'`
128 test $ruleset_id = $rule_id || return 1
129 }
130
131 function generate_manipulated_rules() {
132 local dir=$1
133 ceph osd crush add-bucket $root host
134 ceph osd crush rule create-simple test_rule1 $root osd firstn || return 1
135 ceph osd crush rule create-simple test_rule2 $root osd firstn || return 1
136 ceph osd getcrushmap -o $dir/original_map
137 crushtool -d $dir/original_map -o $dir/decoded_original_map
138 #manipulate the rulesets , to make the rule_id != ruleset_id
139 ${SED} -i 's/ruleset 0/ruleset 3/' $dir/decoded_original_map
140 ${SED} -i 's/ruleset 2/ruleset 0/' $dir/decoded_original_map
141 ${SED} -i 's/ruleset 1/ruleset 2/' $dir/decoded_original_map
142
143 crushtool -c $dir/decoded_original_map -o $dir/new_map
144 ceph osd setcrushmap -i $dir/new_map
145
146 ceph osd crush rule dump
147 }
148
149 function TEST_crush_ruleset_match_rule_when_creating() {
150 local dir=$1
151
152 run_mon $dir a || return 1
153
154 local root=host1
155
156 generate_manipulated_rules $dir
157
158 ceph osd crush rule create-simple special_rule_simple $root osd firstn || return 1
159
160 ceph osd crush rule dump
161 #show special_rule_simple has same rule_id and ruleset_id
162 check_ruleset_id_match_rule_id special_rule_simple || return 1
163 }
164
165 function TEST_add_ruleset_failed() {
166 local dir=$1
167
168 run_mon $dir a || return 1
169
170 local root=host1
171
172 ceph osd crush add-bucket $root host
173 ceph osd crush rule create-simple test_rule1 $root osd firstn || return 1
174 ceph osd crush rule create-simple test_rule2 $root osd firstn || return 1
175 ceph osd getcrushmap > $dir/crushmap || return 1
176 crushtool --decompile $dir/crushmap > $dir/crushmap.txt || return 1
177 for i in $(seq 3 255)
178 do
179 cat <<EOF
180 rule test_rule$i {
181 ruleset $i
182 type replicated
183 min_size 1
184 max_size 10
185 step take $root
186 step choose firstn 0 type osd
187 step emit
188 }
189 EOF
190 done >> $dir/crushmap.txt
191 crushtool --compile $dir/crushmap.txt -o $dir/crushmap || return 1
192 ceph osd setcrushmap -i $dir/crushmap || return 1
193 ceph osd crush rule create-simple test_rule_nospace $root osd firstn 2>&1 | grep "Error ENOSPC" || return 1
194
195 }
196
197 function TEST_crush_rename_bucket() {
198 local dir=$1
199
200 run_mon $dir a || return 1
201
202 ceph osd crush add-bucket host1 host
203 ceph osd tree
204 ! ceph osd tree | grep host2 || return 1
205 ceph osd crush rename-bucket host1 host2 || return 1
206 ceph osd tree
207 ceph osd tree | grep host2 || return 1
208 ceph osd crush rename-bucket host1 host2 || return 1 # idempotency
209 ceph osd crush rename-bucket nonexistent something 2>&1 | grep "Error ENOENT" || return 1
210 }
211
212 function TEST_crush_reject_empty() {
213 local dir=$1
214 run_mon $dir a || return 1
215 # should have at least one OSD
216 run_osd $dir 0 || return 1
217
218 local empty_map=$dir/empty_map
219 :> $empty_map.txt
220 crushtool -c $empty_map.txt -o $empty_map.map || return 1
221 expect_failure $dir "Error EINVAL" \
222 ceph osd setcrushmap -i $empty_map.map || return 1
223 }
224
225 function TEST_crush_tree() {
226 local dir=$1
227 run_mon $dir a || return 1
228
229 ceph osd crush tree --format=xml | \
230 $XMLSTARLET val -e -r $CEPH_ROOT/src/test/mon/osd-crush-tree.rng - || return 1
231 }
232
233 main osd-crush "$@"
234
235 # Local Variables:
236 # compile-command: "cd ../.. ; make -j4 && test/mon/osd-crush.sh"
237 # End: