3 # Copyright (C) 2013, 2014 Cloudwatt <libre.licensing@cloudwatt.com>
4 # Copyright (C) 2014, 2015 Red Hat <contact@redhat.com>
6 # Author: Loic Dachary <loic@dachary.org>
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)
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.
18 source $
(dirname $0)/..
/detect-build-env-vars.sh
19 source $CEPH_ROOT/qa
/workunits
/ceph-helpers.sh
25 export CEPH_MON
="127.0.0.1:7105" # git grep '\<7105\>' : there must be only one
27 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
28 CEPH_ARGS
+="--mon-host=$CEPH_MON "
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
38 # Before http://tracker.ceph.com/issues/8307 the invalid profile was created
39 function TEST_erasure_invalid_profile
() {
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
48 function TEST_erasure_crush_rule
() {
50 run_mon
$dir a ||
return 1
52 # choose the crush ruleset used with an erasure coded pool
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
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
64 # a crush ruleset by the name of the pool is implicitly created
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
71 # a non existent crush ruleset given in argument is an error
72 # http://tracker.ceph.com/issues/9304
74 poolname
=pool_erasure3
75 ! ceph osd pool create
$poolname 12 12 erasure myprofile INVALIDRULESET ||
return 1
78 function TEST_erasure_code_profile_default
() {
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
87 function TEST_erasure_crush_stripe_unit
() {
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
99 function TEST_erasure_crush_stripe_unit_padded
() {
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"
108 actual_stripe_unit
=2048
109 desired_stripe_unit
=$
((actual_stripe_unit
- 1))
110 actual_stripe_width
=$
((actual_stripe_unit
* k
))
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
119 function TEST_erasure_code_pool
() {
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
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
135 function TEST_replicated_pool_with_ruleset
() {
138 local ruleset
=ruleset0
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
155 function TEST_erasure_code_pool_lrc
() {
157 run_mon
$dir a ||
return 1
159 ceph osd erasure-code-profile
set LRCprofile \
162 layers
='[ [ "DDc", "" ] ]' ||
return 1
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
174 function TEST_replicated_pool
() {
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
191 function TEST_no_pool_delete
() {
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
201 function TEST_utf8_cli
() {
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 | \
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
217 main osd-pool-create
"$@"
220 # compile-command: "cd ../.. ; make -j4 && test/mon/osd-pool-create.sh"