]> git.proxmox.com Git - ceph.git/blame - ceph/qa/standalone/mon/osd-crush.sh
import quincy beta 17.1.0
[ceph.git] / ceph / qa / standalone / mon / osd-crush.sh
CommitLineData
11fdf7f2 1#!/usr/bin/env bash
7c673cae
FG
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#
c07f9fc5 18source $CEPH_ROOT/qa/standalone/ceph-helpers.sh
7c673cae
FG
19
20function run() {
21 local dir=$1
22 shift
23
24 export CEPH_MON="127.0.0.1:7104" # git grep '\<7104\>' : 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
37function TEST_crush_rule_create_simple() {
38 local dir=$1
39
40 run_mon $dir a || return 1
41
31f18b77 42 ceph --format xml osd crush rule dump replicated_rule | \
7c673cae
FG
43 egrep '<op>take</op><item>[^<]+</item><item_name>default</item_name>' | \
44 grep '<op>choose_firstn</op><num>0</num><type>osd</type>' || return 1
20effc67 45 local rule=rule0
7c673cae
FG
46 local root=host1
47 ceph osd crush add-bucket $root host
48 local failure_domain=osd
20effc67
TL
49 ceph osd crush rule create-simple $rule $root $failure_domain || return 1
50 ceph osd crush rule create-simple $rule $root $failure_domain 2>&1 | \
51 grep "$rule already exists" || return 1
52 ceph --format xml osd crush rule dump $rule | \
7c673cae
FG
53 egrep '<op>take</op><item>[^<]+</item><item_name>'$root'</item_name>' | \
54 grep '<op>choose_firstn</op><num>0</num><type>'$failure_domain'</type>' || return 1
20effc67 55 ceph osd crush rule rm $rule || return 1
7c673cae
FG
56}
57
58function TEST_crush_rule_dump() {
59 local dir=$1
60
61 run_mon $dir a || return 1
62
20effc67
TL
63 local rule=rule1
64 ceph osd crush rule create-erasure $rule || return 1
65 test $(ceph --format json osd crush rule dump $rule | \
66 jq ".rule_name == \"$rule\"") == true || return 1
31f18b77 67 test $(ceph --format json osd crush rule dump | \
20effc67
TL
68 jq "map(select(.rule_name == \"$rule\")) | length == 1") == true || return 1
69 ! ceph osd crush rule dump non_existent_rule || return 1
70 ceph osd crush rule rm $rule || return 1
7c673cae
FG
71}
72
73function TEST_crush_rule_rm() {
20effc67 74 local rule=erasure2
7c673cae
FG
75
76 run_mon $dir a || return 1
77
20effc67
TL
78 ceph osd crush rule create-erasure $rule default || return 1
79 ceph osd crush rule ls | grep $rule || return 1
80 ceph osd crush rule rm $rule || return 1
81 ! ceph osd crush rule ls | grep $rule || return 1
7c673cae
FG
82}
83
84function TEST_crush_rule_create_erasure() {
85 local dir=$1
86
87 run_mon $dir a || return 1
88 # should have at least one OSD
89 run_osd $dir 0 || return 1
90
20effc67 91 local rule=rule3
7c673cae 92 #
20effc67 93 # create a new rule with the default profile, implicitly
7c673cae 94 #
20effc67
TL
95 ceph osd crush rule create-erasure $rule || return 1
96 ceph osd crush rule create-erasure $rule 2>&1 | \
97 grep "$rule already exists" || return 1
98 ceph --format xml osd crush rule dump $rule | \
7c673cae
FG
99 egrep '<op>take</op><item>[^<]+</item><item_name>default</item_name>' | \
100 grep '<op>chooseleaf_indep</op><num>0</num><type>host</type>' || return 1
20effc67
TL
101 ceph osd crush rule rm $rule || return 1
102 ! ceph osd crush rule ls | grep $rule || return 1
7c673cae 103 #
20effc67 104 # create a new rule with the default profile, explicitly
7c673cae 105 #
20effc67
TL
106 ceph osd crush rule create-erasure $rule default || return 1
107 ceph osd crush rule ls | grep $rule || return 1
108 ceph osd crush rule rm $rule || return 1
109 ! ceph osd crush rule ls | grep $rule || return 1
7c673cae 110 #
20effc67 111 # create a new rule and the default profile, implicitly
7c673cae
FG
112 #
113 ceph osd erasure-code-profile rm default || return 1
114 ! ceph osd erasure-code-profile ls | grep default || return 1
20effc67 115 ceph osd crush rule create-erasure $rule || return 1
c07f9fc5 116 CEPH_ARGS='' ceph --admin-daemon $(get_asok_path mon.a) log flush || return 1
7c673cae
FG
117 grep 'profile set default' $dir/mon.a.log || return 1
118 ceph osd erasure-code-profile ls | grep default || return 1
20effc67
TL
119 ceph osd crush rule rm $rule || return 1
120 ! ceph osd crush rule ls | grep $rule || return 1
7c673cae
FG
121}
122
20effc67 123function TEST_add_rule_failed() {
7c673cae
FG
124 local dir=$1
125
126 run_mon $dir a || return 1
127
128 local root=host1
129
130 ceph osd crush add-bucket $root host
131 ceph osd crush rule create-simple test_rule1 $root osd firstn || return 1
132 ceph osd crush rule create-simple test_rule2 $root osd firstn || return 1
133 ceph osd getcrushmap > $dir/crushmap || return 1
134 crushtool --decompile $dir/crushmap > $dir/crushmap.txt || return 1
135 for i in $(seq 3 255)
136 do
137 cat <<EOF
138rule test_rule$i {
20effc67 139 id $i
7c673cae 140 type replicated
7c673cae
FG
141 step take $root
142 step choose firstn 0 type osd
143 step emit
144}
145EOF
146 done >> $dir/crushmap.txt
147 crushtool --compile $dir/crushmap.txt -o $dir/crushmap || return 1
148 ceph osd setcrushmap -i $dir/crushmap || return 1
149 ceph osd crush rule create-simple test_rule_nospace $root osd firstn 2>&1 | grep "Error ENOSPC" || return 1
150
151}
152
153function TEST_crush_rename_bucket() {
154 local dir=$1
155
156 run_mon $dir a || return 1
157
158 ceph osd crush add-bucket host1 host
31f18b77 159 ceph osd tree
7c673cae
FG
160 ! ceph osd tree | grep host2 || return 1
161 ceph osd crush rename-bucket host1 host2 || return 1
31f18b77 162 ceph osd tree
7c673cae
FG
163 ceph osd tree | grep host2 || return 1
164 ceph osd crush rename-bucket host1 host2 || return 1 # idempotency
165 ceph osd crush rename-bucket nonexistent something 2>&1 | grep "Error ENOENT" || return 1
166}
167
11fdf7f2 168function TEST_crush_ls_node() {
7c673cae
FG
169 local dir=$1
170 run_mon $dir a || return 1
11fdf7f2
TL
171 ceph osd crush add-bucket default1 root
172 ceph osd crush add-bucket host1 host
173 ceph osd crush move host1 root=default1
174 ceph osd crush ls default1 | grep host1 || return 1
175 ceph osd crush ls default2 2>&1 | grep "Error ENOENT" || return 1
176}
177
178function TEST_crush_reject_empty() {
179 local dir=$1
f67539c2 180 run_mon $dir a --osd_pool_default_size=1 --mon_allow_pool_size_one=true || return 1
7c673cae
FG
181 # should have at least one OSD
182 run_osd $dir 0 || return 1
c07f9fc5 183 create_rbd_pool || return 1
7c673cae
FG
184
185 local empty_map=$dir/empty_map
186 :> $empty_map.txt
187 crushtool -c $empty_map.txt -o $empty_map.map || return 1
188 expect_failure $dir "Error EINVAL" \
189 ceph osd setcrushmap -i $empty_map.map || return 1
190}
191
7c673cae
FG
192main osd-crush "$@"
193
194# Local Variables:
195# compile-command: "cd ../.. ; make -j4 && test/mon/osd-crush.sh"
196# End: