]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/osd-pool-create.sh
bump version to 12.1.1-pve1 while rebasing patches
[ceph.git] / ceph / src / test / mon / osd-pool-create.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2013, 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:7105" # git grep '\<7105\>' : 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 # Before http://tracker.ceph.com/issues/8307 the invalid profile was created
39 function TEST_erasure_invalid_profile() {
40 local dir=$1
41 run_mon $dir a || return 1
42 local poolname=pool_erasure
43 local notaprofile=not-a-valid-erasure-code-profile
44 ! ceph osd pool create $poolname 12 12 erasure $notaprofile || return 1
45 ! ceph osd erasure-code-profile ls | grep $notaprofile || return 1
46 }
47
48 function TEST_erasure_crush_rule() {
49 local dir=$1
50 run_mon $dir a || return 1
51 #
52 # choose the crush ruleset used with an erasure coded pool
53 #
54 local crush_ruleset=myruleset
55 ! ceph osd crush rule ls | grep $crush_ruleset || return 1
56 ceph osd crush rule create-erasure $crush_ruleset
57 ceph osd crush rule ls | grep $crush_ruleset
58 local poolname
59 poolname=pool_erasure1
60 ! ceph --format json osd dump | grep '"crush_rule":1' || return 1
61 ceph osd pool create $poolname 12 12 erasure default $crush_ruleset
62 ceph --format json osd dump | grep '"crush_rule":1' || return 1
63 #
64 # a crush ruleset by the name of the pool is implicitly created
65 #
66 poolname=pool_erasure2
67 ceph osd erasure-code-profile set myprofile
68 ceph osd pool create $poolname 12 12 erasure myprofile
69 ceph osd crush rule ls | grep $poolname || return 1
70 #
71 # a non existent crush ruleset given in argument is an error
72 # http://tracker.ceph.com/issues/9304
73 #
74 poolname=pool_erasure3
75 ! ceph osd pool create $poolname 12 12 erasure myprofile INVALIDRULESET || return 1
76 }
77
78 function TEST_erasure_code_profile_default() {
79 local dir=$1
80 run_mon $dir a || return 1
81 ceph osd erasure-code-profile rm default || return 1
82 ! ceph osd erasure-code-profile ls | grep default || return 1
83 ceph osd pool create $poolname 12 12 erasure default
84 ceph osd erasure-code-profile ls | grep default || return 1
85 }
86
87 function TEST_erasure_crush_stripe_unit() {
88 local dir=$1
89 # the default stripe unit is used to initialize the pool
90 run_mon $dir a --public-addr $CEPH_MON
91 stripe_unit=$(ceph-conf --show-config-value osd_pool_erasure_code_stripe_unit)
92 eval local $(ceph osd erasure-code-profile get myprofile | grep k=)
93 stripe_width = $((stripe_unit * k))
94 ceph osd pool create pool_erasure 12 12 erasure
95 ceph --format json osd dump | tee $dir/osd.json
96 grep '"stripe_width":'$stripe_width $dir/osd.json > /dev/null || return 1
97 }
98
99 function TEST_erasure_crush_stripe_unit_padded() {
100 local dir=$1
101 # setting osd_pool_erasure_code_stripe_unit modifies the stripe_width
102 # and it is padded as required by the default plugin
103 profile+=" plugin=jerasure"
104 profile+=" technique=reed_sol_van"
105 k=4
106 profile+=" k=$k"
107 profile+=" m=2"
108 actual_stripe_unit=2048
109 desired_stripe_unit=$((actual_stripe_unit - 1))
110 actual_stripe_width=$((actual_stripe_unit * k))
111 run_mon $dir a \
112 --osd_pool_erasure_code_stripe_unit $desired_stripe_unit \
113 --osd_pool_default_erasure_code_profile "$profile" || return 1
114 ceph osd pool create pool_erasure 12 12 erasure
115 ceph osd dump | tee $dir/osd.json
116 grep "stripe_width $actual_stripe_width" $dir/osd.json > /dev/null || return 1
117 }
118
119 function TEST_erasure_code_pool() {
120 local dir=$1
121 run_mon $dir a || return 1
122 ceph --format json osd dump > $dir/osd.json
123 local expected='"erasure_code_profile":"default"'
124 ! grep "$expected" $dir/osd.json || return 1
125 ceph osd pool create erasurecodes 12 12 erasure
126 ceph --format json osd dump | tee $dir/osd.json
127 grep "$expected" $dir/osd.json > /dev/null || return 1
128
129 ceph osd pool create erasurecodes 12 12 erasure 2>&1 | \
130 grep 'already exists' || return 1
131 ceph osd pool create erasurecodes 12 12 2>&1 | \
132 grep 'cannot change to type replicated' || return 1
133 }
134
135 function TEST_replicated_pool_with_ruleset() {
136 local dir=$1
137 run_mon $dir a
138 local ruleset=ruleset0
139 local root=host1
140 ceph osd crush add-bucket $root host
141 local failure_domain=osd
142 local poolname=mypool
143 ceph osd crush rule create-simple $ruleset $root $failure_domain || return 1
144 ceph osd crush rule ls | grep $ruleset
145 ceph osd pool create $poolname 12 12 replicated $ruleset 2>&1 | \
146 grep "pool 'mypool' created" || return 1
147 rule_id=`ceph osd crush rule dump $ruleset | grep "rule_id" | awk -F[' ':,] '{print $4}'`
148 ceph osd pool get $poolname crush_rule 2>&1 | \
149 grep "crush_rule: $rule_id" || return 1
150 #non-existent crush ruleset
151 ceph osd pool create newpool 12 12 replicated non-existent 2>&1 | \
152 grep "doesn't exist" || return 1
153 }
154
155 function TEST_erasure_code_pool_lrc() {
156 local dir=$1
157 run_mon $dir a || return 1
158
159 ceph osd erasure-code-profile set LRCprofile \
160 plugin=lrc \
161 mapping=DD_ \
162 layers='[ [ "DDc", "" ] ]' || return 1
163
164 ceph --format json osd dump > $dir/osd.json
165 local expected='"erasure_code_profile":"LRCprofile"'
166 local poolname=erasurecodes
167 ! grep "$expected" $dir/osd.json || return 1
168 ceph osd pool create $poolname 12 12 erasure LRCprofile
169 ceph --format json osd dump | tee $dir/osd.json
170 grep "$expected" $dir/osd.json > /dev/null || return 1
171 ceph osd crush rule ls | grep $poolname || return 1
172 }
173
174 function TEST_replicated_pool() {
175 local dir=$1
176 run_mon $dir a || return 1
177 ceph osd pool create replicated 12 12 replicated replicated_rule 2>&1 | \
178 grep "pool 'replicated' created" || return 1
179 ceph osd pool create replicated 12 12 replicated replicated_rule 2>&1 | \
180 grep 'already exists' || return 1
181 # default is replicated
182 ceph osd pool create replicated1 12 12 2>&1 | \
183 grep "pool 'replicated1' created" || return 1
184 # default is replicated, pgp_num = pg_num
185 ceph osd pool create replicated2 12 2>&1 | \
186 grep "pool 'replicated2' created" || return 1
187 ceph osd pool create replicated 12 12 erasure 2>&1 | \
188 grep 'cannot change to type erasure' || return 1
189 }
190
191 function TEST_no_pool_delete() {
192 local dir=$1
193 run_mon $dir a || return 1
194 ceph osd pool create foo 1 || return 1
195 ceph tell mon.a injectargs -- --no-mon-allow-pool-delete || return 1
196 ! ceph osd pool delete foo foo --yes-i-really-really-mean-it || return 1
197 ceph tell mon.a injectargs -- --mon-allow-pool-delete || return 1
198 ceph osd pool delete foo foo --yes-i-really-really-mean-it || return 1
199 }
200
201 function TEST_utf8_cli() {
202 local dir=$1
203 run_mon $dir a || return 1
204 # Hopefully it's safe to include literal UTF-8 characters to test
205 # the fix for http://tracker.ceph.com/issues/7387. If it turns out
206 # to not be OK (when is the default encoding *not* UTF-8?), maybe
207 # the character '黄' can be replaced with the escape $'\xe9\xbb\x84'
208 ceph osd pool create 黄 1024 2>&1 | \
209 grep "pool '黄' created" || return 1
210 ceph osd lspools 2>&1 | \
211 grep "黄" || return 1
212 ceph -f json-pretty osd dump | \
213 python -c "import json; import sys; json.load(sys.stdin)" || return 1
214 ceph osd pool delete 黄 黄 --yes-i-really-really-mean-it
215 }
216
217 main osd-pool-create "$@"
218
219 # Local Variables:
220 # compile-command: "cd ../.. ; make -j4 && test/mon/osd-pool-create.sh"
221 # End: