3 # Copyright (C) 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:7220" # git grep '\<7220\>' : 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
42 run_mon
$dir a ||
return 1
44 local profile
=myprofile
46 # no key=value pairs : use the default configuration
48 ceph osd erasure-code-profile
set $profile 2>&1 ||
return 1
49 ceph osd erasure-code-profile get
$profile | \
50 grep plugin
=jerasure ||
return 1
51 ceph osd erasure-code-profile
rm $profile
53 # key=value pairs override the default
55 ceph osd erasure-code-profile
set $profile \
56 key
=value plugin
=example ||
return 1
57 ceph osd erasure-code-profile get
$profile | \
58 grep -e key
=value
-e plugin
=example ||
return 1
60 # --force is required to override an existing profile
62 ! ceph osd erasure-code-profile
set $profile > $dir/out
2>&1 ||
return 1
63 grep 'will not override' $dir/out ||
return 1
64 ceph osd erasure-code-profile
set $profile key
=other
--force ||
return 1
65 ceph osd erasure-code-profile get
$profile | \
66 grep key
=other ||
return 1
68 ceph osd erasure-code-profile
rm $profile # cleanup
75 run_mon
$dir a ||
return 1
77 local profile
=myprofile
78 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
79 ceph osd erasure-code-profile
set $profile 2>&1 ||
return 1
80 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
81 ceph
--format xml osd erasure-code-profile
ls | \
82 grep "<profile>$profile</profile>" ||
return 1
84 ceph osd erasure-code-profile
rm $profile # cleanup
91 run_mon
$dir a ||
return 1
93 local profile
=myprofile
94 ceph osd erasure-code-profile
set $profile 2>&1 ||
return 1
95 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
96 ceph osd erasure-code-profile
rm $profile ||
return 1
97 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
98 ceph osd erasure-code-profile
rm WRONG
2>&1 | \
99 grep "WRONG does not exist" ||
return 1
101 ceph osd erasure-code-profile
set $profile ||
return 1
102 ceph osd pool create poolname
12 12 erasure
$profile ||
return 1
103 ! ceph osd erasure-code-profile
rm $profile > $dir/out
2>&1 ||
return 1
104 grep "poolname.*using.*$profile" $dir/out ||
return 1
105 ceph osd pool delete poolname poolname
--yes-i-really-really-mean-it ||
return 1
106 ceph osd erasure-code-profile
rm $profile ||
return 1
108 ceph osd erasure-code-profile
rm $profile # cleanup
111 function TEST_get
() {
115 run_mon
$dir a ||
return 1
117 local default_profile
=default
118 ceph osd erasure-code-profile get
$default_profile | \
119 grep plugin
=jerasure ||
return 1
120 ceph
--format xml osd erasure-code-profile get
$default_profile | \
121 grep '<plugin>jerasure</plugin>' ||
return 1
122 ! ceph osd erasure-code-profile get WRONG
> $dir/out
2>&1 ||
return 1
123 grep -q "unknown erasure code profile 'WRONG'" $dir/out ||
return 1
126 function TEST_set_idempotent
() {
130 run_mon
$dir a ||
return 1
132 # The default profile is set using a code path different from
133 # ceph osd erasure-code-profile set: verify that it is idempotent,
134 # as if it was using the same code path.
136 ceph osd erasure-code-profile
set default k
=2 m
=1 2>&1 ||
return 1
139 # Because plugin=jerasure is the default, it uses a slightly
140 # different code path where defaults (m=1 for instance) are added
143 profile
=profileidempotent1
144 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
145 ceph osd erasure-code-profile
set $profile k
=2 ruleset-failure-domain
=osd
2>&1 ||
return 1
146 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
147 ceph osd erasure-code-profile
set $profile k
=2 ruleset-failure-domain
=osd
2>&1 ||
return 1
148 ceph osd erasure-code-profile
rm $profile # cleanup
151 # In the general case the profile is exactly what is on
153 profile
=profileidempotent2
154 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
155 ceph osd erasure-code-profile
set $profile plugin
=lrc k
=4 m
=2 l
=3 ruleset-failure-domain
=osd
2>&1 ||
return 1
156 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
157 ceph osd erasure-code-profile
set $profile plugin
=lrc k
=4 m
=2 l
=3 ruleset-failure-domain
=osd
2>&1 ||
return 1
158 ceph osd erasure-code-profile
rm $profile # cleanup
161 function TEST_format_invalid
() {
164 local profile
=profile
165 # osd_pool_default_erasure-code-profile is
166 # valid JSON but not of the expected type
168 --osd_pool_default_erasure-code-profile 1 ||
return 1
169 ! ceph osd erasure-code-profile
set $profile > $dir/out
2>&1 ||
return 1
171 grep 'must be a JSON object' $dir/out ||
return 1
174 function TEST_format_json
() {
177 # osd_pool_default_erasure-code-profile is JSON
178 expected
='"plugin":"example"'
180 --osd_pool_default_erasure-code-profile "{$expected}" ||
return 1
181 ceph
--format json osd erasure-code-profile get default | \
182 grep "$expected" ||
return 1
185 function TEST_format_plain
() {
188 # osd_pool_default_erasure-code-profile is plain text
189 expected
='"plugin":"example"'
191 --osd_pool_default_erasure-code-profile "plugin=example" ||
return 1
192 ceph
--format json osd erasure-code-profile get default | \
193 grep "$expected" ||
return 1
196 function TEST_profile_k_sanity
() {
198 local profile
=profile-sanity
200 run_mon
$dir a ||
return 1
202 expect_failure
$dir 'k must be a multiple of (k + m) / l' \
203 ceph osd erasure-code-profile
set $profile \
209 if erasure_code_plugin_exists isa
; then
210 expect_failure
$dir 'k=1 must be >= 2' \
211 ceph osd erasure-code-profile
set $profile \
216 echo "SKIP because plugin isa has not been built"
219 expect_failure
$dir 'k=1 must be >= 2' \
220 ceph osd erasure-code-profile
set $profile \
226 main osd-erasure-code-profile
"$@"
229 # compile-command: "cd ../.. ; make -j4 && test/mon/osd-erasure-code-profile.sh"