]>
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 | # | |
c07f9fc5 | 18 | source $CEPH_ROOT/qa/standalone/ceph-helpers.sh |
7c673cae FG |
19 | |
20 | function run() { | |
21 | local dir=$1 | |
22 | shift | |
23 | ||
24 | export CEPH_MON="127.0.0.1:7220" # git grep '\<7220\>' : there must be only one | |
25 | export CEPH_ARGS | |
26 | CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " | |
27 | CEPH_ARGS+="--mon-host=$CEPH_MON " | |
28 | ||
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 | |
34 | done | |
35 | } | |
36 | ||
37 | function TEST_set() { | |
38 | local dir=$1 | |
39 | local id=$2 | |
40 | ||
41 | run_mon $dir a || return 1 | |
42 | ||
43 | local profile=myprofile | |
44 | # | |
45 | # no key=value pairs : use the default configuration | |
46 | # | |
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 | |
51 | # | |
52 | # key=value pairs override the default | |
53 | # | |
54 | ceph osd erasure-code-profile set $profile \ | |
c07f9fc5 | 55 | key=value plugin=isa || return 1 |
7c673cae | 56 | ceph osd erasure-code-profile get $profile | \ |
c07f9fc5 | 57 | grep -e key=value -e plugin=isa || return 1 |
7c673cae FG |
58 | # |
59 | # --force is required to override an existing profile | |
60 | # | |
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 | |
66 | ||
67 | ceph osd erasure-code-profile rm $profile # cleanup | |
68 | } | |
69 | ||
70 | function TEST_ls() { | |
71 | local dir=$1 | |
72 | local id=$2 | |
73 | ||
74 | run_mon $dir a || return 1 | |
75 | ||
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 | |
82 | ||
83 | ceph osd erasure-code-profile rm $profile # cleanup | |
84 | } | |
85 | ||
86 | function TEST_rm() { | |
87 | local dir=$1 | |
88 | local id=$2 | |
89 | ||
90 | run_mon $dir a || return 1 | |
91 | ||
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 | |
99 | ||
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 | |
106 | ||
107 | ceph osd erasure-code-profile rm $profile # cleanup | |
108 | } | |
109 | ||
110 | function TEST_get() { | |
111 | local dir=$1 | |
112 | local id=$2 | |
113 | ||
114 | run_mon $dir a || return 1 | |
115 | ||
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 | |
123 | } | |
124 | ||
125 | function TEST_set_idempotent() { | |
126 | local dir=$1 | |
127 | local id=$2 | |
128 | ||
129 | run_mon $dir a || return 1 | |
130 | # | |
c07f9fc5 | 131 | # The default profile is set using a code path different from |
7c673cae FG |
132 | # ceph osd erasure-code-profile set: verify that it is idempotent, |
133 | # as if it was using the same code path. | |
134 | # | |
135 | ceph osd erasure-code-profile set default k=2 m=1 2>&1 || return 1 | |
136 | local profile | |
137 | # | |
138 | # Because plugin=jerasure is the default, it uses a slightly | |
139 | # different code path where defaults (m=1 for instance) are added | |
140 | # implicitly. | |
141 | # | |
142 | profile=profileidempotent1 | |
143 | ! ceph osd erasure-code-profile ls | grep $profile || return 1 | |
224ce89b | 144 | ceph osd erasure-code-profile set $profile k=2 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae | 145 | ceph osd erasure-code-profile ls | grep $profile || return 1 |
224ce89b | 146 | ceph osd erasure-code-profile set $profile k=2 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae FG |
147 | ceph osd erasure-code-profile rm $profile # cleanup |
148 | ||
149 | # | |
150 | # In the general case the profile is exactly what is on | |
151 | # | |
152 | profile=profileidempotent2 | |
153 | ! ceph osd erasure-code-profile ls | grep $profile || return 1 | |
224ce89b | 154 | ceph osd erasure-code-profile set $profile plugin=lrc k=4 m=2 l=3 crush-failure-domain=osd 2>&1 || return 1 |
7c673cae | 155 | ceph osd erasure-code-profile ls | grep $profile || return 1 |
224ce89b | 156 | 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 |
157 | ceph osd erasure-code-profile rm $profile # cleanup |
158 | } | |
159 | ||
160 | function TEST_format_invalid() { | |
161 | local dir=$1 | |
162 | ||
163 | local profile=profile | |
164 | # osd_pool_default_erasure-code-profile is | |
165 | # valid JSON but not of the expected type | |
166 | run_mon $dir a \ | |
167 | --osd_pool_default_erasure-code-profile 1 || return 1 | |
168 | ! ceph osd erasure-code-profile set $profile > $dir/out 2>&1 || return 1 | |
169 | cat $dir/out | |
170 | grep 'must be a JSON object' $dir/out || return 1 | |
171 | } | |
172 | ||
173 | function TEST_format_json() { | |
174 | local dir=$1 | |
175 | ||
176 | # osd_pool_default_erasure-code-profile is JSON | |
c07f9fc5 | 177 | expected='"plugin":"isa"' |
7c673cae FG |
178 | run_mon $dir a \ |
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 | |
182 | } | |
183 | ||
184 | function TEST_format_plain() { | |
185 | local dir=$1 | |
186 | ||
187 | # osd_pool_default_erasure-code-profile is plain text | |
c07f9fc5 | 188 | expected='"plugin":"isa"' |
7c673cae | 189 | run_mon $dir a \ |
c07f9fc5 | 190 | --osd_pool_default_erasure-code-profile "plugin=isa" || return 1 |
7c673cae FG |
191 | ceph --format json osd erasure-code-profile get default | \ |
192 | grep "$expected" || return 1 | |
193 | } | |
194 | ||
195 | function TEST_profile_k_sanity() { | |
196 | local dir=$1 | |
197 | local profile=profile-sanity | |
198 | ||
199 | run_mon $dir a || return 1 | |
200 | ||
201 | expect_failure $dir 'k must be a multiple of (k + m) / l' \ | |
202 | ceph osd erasure-code-profile set $profile \ | |
203 | plugin=lrc \ | |
204 | l=1 \ | |
205 | k=1 \ | |
206 | m=1 || return 1 | |
207 | ||
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 \ | |
211 | plugin=isa \ | |
212 | k=1 \ | |
213 | m=1 || return 1 | |
214 | else | |
215 | echo "SKIP because plugin isa has not been built" | |
216 | fi | |
217 | ||
218 | expect_failure $dir 'k=1 must be >= 2' \ | |
219 | ceph osd erasure-code-profile set $profile \ | |
220 | plugin=jerasure \ | |
221 | k=1 \ | |
222 | m=1 || return 1 | |
223 | } | |
224 | ||
225 | main osd-erasure-code-profile "$@" | |
226 | ||
227 | # Local Variables: | |
228 | # compile-command: "cd ../.. ; make -j4 && test/mon/osd-erasure-code-profile.sh" | |
229 | # End: |