]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/bin/bash |
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 | # | |
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:7220" # git grep '\<7220\>' : 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 | function TEST_set() { | |
39 | local dir=$1 | |
40 | local id=$2 | |
41 | ||
42 | run_mon $dir a || return 1 | |
43 | ||
44 | local profile=myprofile | |
45 | # | |
46 | # no key=value pairs : use the default configuration | |
47 | # | |
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 | |
52 | # | |
53 | # key=value pairs override the default | |
54 | # | |
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 | |
59 | # | |
60 | # --force is required to override an existing profile | |
61 | # | |
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 | |
67 | ||
68 | ceph osd erasure-code-profile rm $profile # cleanup | |
69 | } | |
70 | ||
71 | function TEST_ls() { | |
72 | local dir=$1 | |
73 | local id=$2 | |
74 | ||
75 | run_mon $dir a || return 1 | |
76 | ||
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 | |
83 | ||
84 | ceph osd erasure-code-profile rm $profile # cleanup | |
85 | } | |
86 | ||
87 | function TEST_rm() { | |
88 | local dir=$1 | |
89 | local id=$2 | |
90 | ||
91 | run_mon $dir a || return 1 | |
92 | ||
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 | |
100 | ||
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 | |
107 | ||
108 | ceph osd erasure-code-profile rm $profile # cleanup | |
109 | } | |
110 | ||
111 | function TEST_get() { | |
112 | local dir=$1 | |
113 | local id=$2 | |
114 | ||
115 | run_mon $dir a || return 1 | |
116 | ||
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 | |
124 | } | |
125 | ||
126 | function TEST_set_idempotent() { | |
127 | local dir=$1 | |
128 | local id=$2 | |
129 | ||
130 | run_mon $dir a || return 1 | |
131 | # | |
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. | |
135 | # | |
136 | ceph osd erasure-code-profile set default k=2 m=1 2>&1 || return 1 | |
137 | local profile | |
138 | # | |
139 | # Because plugin=jerasure is the default, it uses a slightly | |
140 | # different code path where defaults (m=1 for instance) are added | |
141 | # implicitly. | |
142 | # | |
143 | profile=profileidempotent1 | |
144 | ! ceph osd erasure-code-profile ls | grep $profile || return 1 | |
224ce89b | 145 | ceph osd erasure-code-profile set $profile k=2 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae | 146 | ceph osd erasure-code-profile ls | grep $profile || return 1 |
224ce89b | 147 | ceph osd erasure-code-profile set $profile k=2 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae FG |
148 | ceph osd erasure-code-profile rm $profile # cleanup |
149 | ||
150 | # | |
151 | # In the general case the profile is exactly what is on | |
152 | # | |
153 | profile=profileidempotent2 | |
154 | ! ceph osd erasure-code-profile ls | grep $profile || return 1 | |
224ce89b | 155 | ceph osd erasure-code-profile set $profile plugin=lrc k=4 m=2 l=3 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae | 156 | ceph osd erasure-code-profile ls | grep $profile || return 1 |
224ce89b | 157 | ceph osd erasure-code-profile set $profile plugin=lrc k=4 m=2 l=3 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae FG |
158 | ceph osd erasure-code-profile rm $profile # cleanup |
159 | } | |
160 | ||
161 | function TEST_format_invalid() { | |
162 | local dir=$1 | |
163 | ||
164 | local profile=profile | |
165 | # osd_pool_default_erasure-code-profile is | |
166 | # valid JSON but not of the expected type | |
167 | run_mon $dir a \ | |
168 | --osd_pool_default_erasure-code-profile 1 || return 1 | |
169 | ! ceph osd erasure-code-profile set $profile > $dir/out 2>&1 || return 1 | |
170 | cat $dir/out | |
171 | grep 'must be a JSON object' $dir/out || return 1 | |
172 | } | |
173 | ||
174 | function TEST_format_json() { | |
175 | local dir=$1 | |
176 | ||
177 | # osd_pool_default_erasure-code-profile is JSON | |
178 | expected='"plugin":"example"' | |
179 | run_mon $dir a \ | |
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 | |
183 | } | |
184 | ||
185 | function TEST_format_plain() { | |
186 | local dir=$1 | |
187 | ||
188 | # osd_pool_default_erasure-code-profile is plain text | |
189 | expected='"plugin":"example"' | |
190 | run_mon $dir a \ | |
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 | |
194 | } | |
195 | ||
196 | function TEST_profile_k_sanity() { | |
197 | local dir=$1 | |
198 | local profile=profile-sanity | |
199 | ||
200 | run_mon $dir a || return 1 | |
201 | ||
202 | expect_failure $dir 'k must be a multiple of (k + m) / l' \ | |
203 | ceph osd erasure-code-profile set $profile \ | |
204 | plugin=lrc \ | |
205 | l=1 \ | |
206 | k=1 \ | |
207 | m=1 || return 1 | |
208 | ||
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 \ | |
212 | plugin=isa \ | |
213 | k=1 \ | |
214 | m=1 || return 1 | |
215 | else | |
216 | echo "SKIP because plugin isa has not been built" | |
217 | fi | |
218 | ||
219 | expect_failure $dir 'k=1 must be >= 2' \ | |
220 | ceph osd erasure-code-profile set $profile \ | |
221 | plugin=jerasure \ | |
222 | k=1 \ | |
223 | m=1 || return 1 | |
224 | } | |
225 | ||
226 | main osd-erasure-code-profile "$@" | |
227 | ||
228 | # Local Variables: | |
229 | # compile-command: "cd ../.. ; make -j4 && test/mon/osd-erasure-code-profile.sh" | |
230 | # End: |