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 $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
24 export CEPH_MON
="127.0.0.1:7220" # git grep '\<7220\>' : there must be only one
26 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
27 CEPH_ARGS
+="--mon-host=$CEPH_MON "
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
41 run_mon
$dir a ||
return 1
43 local profile
=myprofile
45 # no key=value pairs : use the default configuration
47 ceph osd erasure-code-profile
set $profile 2>&1 ||
return 1
48 ceph osd erasure-code-profile get
$profile | \
49 grep plugin
=jerasure ||
return 1
50 ceph osd erasure-code-profile
rm $profile
52 # key=value pairs override the default
54 ceph osd erasure-code-profile
set $profile \
55 key
=value plugin
=isa ||
return 1
56 ceph osd erasure-code-profile get
$profile | \
57 grep -e key
=value
-e plugin
=isa ||
return 1
59 # --force is required to override an existing profile
61 ! ceph osd erasure-code-profile
set $profile > $dir/out
2>&1 ||
return 1
62 grep 'will not override' $dir/out ||
return 1
63 ceph osd erasure-code-profile
set $profile key
=other
--force ||
return 1
64 ceph osd erasure-code-profile get
$profile | \
65 grep key
=other ||
return 1
67 ceph osd erasure-code-profile
rm $profile # cleanup
74 run_mon
$dir a ||
return 1
76 local profile
=myprofile
77 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
78 ceph osd erasure-code-profile
set $profile 2>&1 ||
return 1
79 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
80 ceph
--format xml osd erasure-code-profile
ls | \
81 grep "<profile>$profile</profile>" ||
return 1
83 ceph osd erasure-code-profile
rm $profile # cleanup
90 run_mon
$dir a ||
return 1
92 local profile
=myprofile
93 ceph osd erasure-code-profile
set $profile 2>&1 ||
return 1
94 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
95 ceph osd erasure-code-profile
rm $profile ||
return 1
96 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
97 ceph osd erasure-code-profile
rm WRONG
2>&1 | \
98 grep "WRONG does not exist" ||
return 1
100 ceph osd erasure-code-profile
set $profile ||
return 1
101 ceph osd pool create poolname
12 12 erasure
$profile ||
return 1
102 ! ceph osd erasure-code-profile
rm $profile > $dir/out
2>&1 ||
return 1
103 grep "poolname.*using.*$profile" $dir/out ||
return 1
104 ceph osd pool delete poolname poolname
--yes-i-really-really-mean-it ||
return 1
105 ceph osd erasure-code-profile
rm $profile ||
return 1
107 ceph osd erasure-code-profile
rm $profile # cleanup
110 function TEST_get
() {
114 run_mon
$dir a ||
return 1
116 local default_profile
=default
117 ceph osd erasure-code-profile get
$default_profile | \
118 grep plugin
=jerasure ||
return 1
119 ceph
--format xml osd erasure-code-profile get
$default_profile | \
120 grep '<plugin>jerasure</plugin>' ||
return 1
121 ! ceph osd erasure-code-profile get WRONG
> $dir/out
2>&1 ||
return 1
122 grep -q "unknown erasure code profile 'WRONG'" $dir/out ||
return 1
125 function TEST_set_idempotent
() {
129 run_mon
$dir a ||
return 1
131 # The default profile is set using a code path different from
132 # ceph osd erasure-code-profile set: verify that it is idempotent,
133 # as if it was using the same code path.
135 ceph osd erasure-code-profile
set default k
=2 m
=1 2>&1 ||
return 1
138 # Because plugin=jerasure is the default, it uses a slightly
139 # different code path where defaults (m=1 for instance) are added
142 profile
=profileidempotent1
143 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
144 ceph osd erasure-code-profile
set $profile k
=2 crush-failure-domain
=osd
2>&1 ||
return 1
145 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
146 ceph osd erasure-code-profile
set $profile k
=2 crush-failure-domain
=osd
2>&1 ||
return 1
147 ceph osd erasure-code-profile
rm $profile # cleanup
150 # In the general case the profile is exactly what is on
152 profile
=profileidempotent2
153 ! ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
154 ceph osd erasure-code-profile
set $profile plugin
=lrc k
=4 m
=2 l
=3 crush-failure-domain
=osd
2>&1 ||
return 1
155 ceph osd erasure-code-profile
ls |
grep $profile ||
return 1
156 ceph osd erasure-code-profile
set $profile plugin
=lrc k
=4 m
=2 l
=3 crush-failure-domain
=osd
2>&1 ||
return 1
157 ceph osd erasure-code-profile
rm $profile # cleanup
160 function TEST_format_invalid
() {
163 local profile
=profile
164 # osd_pool_default_erasure-code-profile is
165 # valid JSON but not of the expected type
167 --osd_pool_default_erasure-code-profile 1 ||
return 1
168 ! ceph osd erasure-code-profile
set $profile > $dir/out
2>&1 ||
return 1
170 grep 'must be a JSON object' $dir/out ||
return 1
173 function TEST_format_json
() {
176 # osd_pool_default_erasure-code-profile is JSON
177 expected
='"plugin":"isa"'
179 --osd_pool_default_erasure-code-profile "{$expected}" ||
return 1
180 ceph
--format json osd erasure-code-profile get default | \
181 grep "$expected" ||
return 1
184 function TEST_format_plain
() {
187 # osd_pool_default_erasure-code-profile is plain text
188 expected
='"plugin":"isa"'
190 --osd_pool_default_erasure-code-profile "plugin=isa" ||
return 1
191 ceph
--format json osd erasure-code-profile get default | \
192 grep "$expected" ||
return 1
195 function TEST_profile_k_sanity
() {
197 local profile
=profile-sanity
199 run_mon
$dir a ||
return 1
201 expect_failure
$dir 'k must be a multiple of (k + m) / l' \
202 ceph osd erasure-code-profile
set $profile \
208 if erasure_code_plugin_exists isa
; then
209 expect_failure
$dir 'k=1 must be >= 2' \
210 ceph osd erasure-code-profile
set $profile \
215 echo "SKIP because plugin isa has not been built"
218 expect_failure
$dir 'k=1 must be >= 2' \
219 ceph osd erasure-code-profile
set $profile \
225 main osd-erasure-code-profile
"$@"
228 # compile-command: "cd ../.. ; make -j4 && test/mon/osd-erasure-code-profile.sh"