]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/misc.sh
2002ecd8944c77dbef25eb22050e1a094085d05c
[ceph.git] / ceph / src / test / mon / misc.sh
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:7102" # git grep '\<7102\>' : 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 $func $dir || return 1
33 done
34 }
35
36 TEST_POOL=rbd
37
38 function TEST_osd_pool_get_set() {
39 local dir=$1
40
41 setup $dir || return 1
42 run_mon $dir a || return 1
43
44 local flag
45 for flag in nodelete nopgchange nosizechange write_fadvise_dontneed noscrub nodeep-scrub; do
46 ceph osd pool set $TEST_POOL $flag 0 || return 1
47 ! ceph osd dump | grep 'pool ' | grep $flag || return 1
48 ceph osd pool set $TEST_POOL $flag 1 || return 1
49 ceph osd dump | grep 'pool ' | grep $flag || return 1
50 ceph osd pool set $TEST_POOL $flag false || return 1
51 ! ceph osd dump | grep 'pool ' | grep $flag || return 1
52 ceph osd pool set $TEST_POOL $flag false || return 1
53 # check that setting false twice does not toggle to true (bug)
54 ! ceph osd dump | grep 'pool ' | grep $flag || return 1
55 ceph osd pool set $TEST_POOL $flag true || return 1
56 ceph osd dump | grep 'pool ' | grep $flag || return 1
57 # cleanup
58 ceph osd pool set $TEST_POOL $flag 0 || return 1
59 done
60
61 local size=$(ceph osd pool get $TEST_POOL size|awk '{print $2}')
62 local min_size=$(ceph osd pool get $TEST_POOL min_size|awk '{print $2}')
63
64 ceph osd pool set $TEST_POOL scrub_min_interval 123456 || return 1
65 ceph osd dump | grep 'pool ' | grep 'scrub_min_interval 123456' || return 1
66 ceph osd pool set $TEST_POOL scrub_min_interval 0 || return 1
67 ceph osd dump | grep 'pool ' | grep 'scrub_min_interval' && return 1
68 ceph osd pool set $TEST_POOL scrub_max_interval 123456 || return 1
69 ceph osd dump | grep 'pool ' | grep 'scrub_max_interval 123456' || return 1
70 ceph osd pool set $TEST_POOL scrub_max_interval 0 || return 1
71 ceph osd dump | grep 'pool ' | grep 'scrub_max_interval' && return 1
72 ceph osd pool set $TEST_POOL deep_scrub_interval 123456 || return 1
73 ceph osd dump | grep 'pool ' | grep 'deep_scrub_interval 123456' || return 1
74 ceph osd pool set $TEST_POOL deep_scrub_interval 0 || return 1
75 ceph osd dump | grep 'pool ' | grep 'deep_scrub_interval' && return 1
76
77 #replicated pool size restrict in 1 and 10
78 ! ceph osd pool set $TEST_POOL 11 || return 1
79 #replicated pool min_size must be between in 1 and size
80 ! ceph osd pool set $TEST_POOL min_size $(expr $size + 1) || return 1
81 ! ceph osd pool set $TEST_POOL min_size 0 || return 1
82
83 local ecpool=erasepool
84 ceph osd pool create $ecpool 12 12 erasure default || return 1
85 #erasue pool size=k+m, min_size=k
86 local size=$(ceph osd pool get $ecpool size|awk '{print $2}')
87 local min_size=$(ceph osd pool get $ecpool min_size|awk '{print $2}')
88 local k=$(expr $min_size - 1) # default min_size=k+1
89 #erasure pool size can't change
90 ! ceph osd pool set $ecpool size $(expr $size + 1) || return 1
91 #erasure pool min_size must be between in k and size
92 ceph osd pool set $ecpool min_size $(expr $k + 1) || return 1
93 ! ceph osd pool set $ecpool min_size $(expr $k - 1) || return 1
94 ! ceph osd pool set $ecpool min_size $(expr $size + 1) || return 1
95
96 teardown $dir || return 1
97 }
98
99 function TEST_mon_add_to_single_mon() {
100 local dir=$1
101
102 fsid=$(uuidgen)
103 MONA=127.0.0.1:7117 # git grep '\<7117\>' : there must be only one
104 MONB=127.0.0.1:7118 # git grep '\<7118\>' : there must be only one
105 CEPH_ARGS_orig=$CEPH_ARGS
106 CEPH_ARGS="--fsid=$fsid --auth-supported=none "
107 CEPH_ARGS+="--mon-initial-members=a "
108 CEPH_ARGS+="--mon-host=$MONA "
109
110 setup $dir || return 1
111 run_mon $dir a --public-addr $MONA || return 1
112 # wait for the quorum
113 timeout 120 ceph -s > /dev/null || return 1
114 run_mon $dir b --public-addr $MONB || return 1
115 teardown $dir || return 1
116
117 setup $dir || return 1
118 run_mon $dir a --public-addr $MONA || return 1
119 # without the fix of #5454, mon.a will assert failure at seeing the MMonJoin
120 # from mon.b
121 run_mon $dir b --public-addr $MONB || return 1
122 # wait for the quorum
123 timeout 120 ceph -s > /dev/null || return 1
124 local num_mons
125 num_mons=$(ceph mon dump --format=json 2>/dev/null | jq ".mons | length") || return 1
126 [ $num_mons == 2 ] || return 1
127 # no reason to take more than 120 secs to get this submitted
128 timeout 120 ceph mon add b $MONB || return 1
129 teardown $dir || return 1
130 }
131
132 function TEST_no_segfault_for_bad_keyring() {
133 local dir=$1
134 setup $dir || return 1
135 # create a client.admin key and add it to ceph.mon.keyring
136 ceph-authtool --create-keyring $dir/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'
137 ceph-authtool --create-keyring $dir/ceph.client.admin.keyring --gen-key -n client.admin --cap mon 'allow *'
138 ceph-authtool $dir/ceph.mon.keyring --import-keyring $dir/ceph.client.admin.keyring
139 CEPH_ARGS_TMP="--fsid=$(uuidgen) --mon-host=127.0.0.1:7102 --auth-supported=cephx "
140 CEPH_ARGS_orig=$CEPH_ARGS
141 CEPH_ARGS="$CEPH_ARGS_TMP --keyring=$dir/ceph.mon.keyring "
142 run_mon $dir a
143 # create a bad keyring and make sure no segfault occurs when using the bad keyring
144 echo -e "[client.admin]\nkey = BQAUlgtWoFePIxAAQ9YLzJSVgJX5V1lh5gyctg==" > $dir/bad.keyring
145 CEPH_ARGS="$CEPH_ARGS_TMP --keyring=$dir/bad.keyring"
146 ceph osd dump 2> /dev/null
147 # 139(11|128) means segfault and core dumped
148 [ $? -eq 139 ] && return 1
149 CEPH_ARGS=$CEPH_ARGS_orig
150 teardown $dir || return 1
151 }
152
153 function jq_success() {
154 input="$1"
155 filter="$2"
156 expects="\"$3\""
157
158 in_escaped=$(printf %s "$input" | sed "s/'/'\\\\''/g")
159 filter_escaped=$(printf %s "$filter" | sed "s/'/'\\\\''/g")
160
161 ret=$(echo "$in_escaped" | jq "$filter_escaped")
162 if [[ "$ret" == "true" ]]; then
163 return 0
164 elif [[ -n "$expects" ]]; then
165 if [[ "$ret" == "$expects" ]]; then
166 return 0
167 fi
168 fi
169 return 1
170 input=$1
171 filter=$2
172 expects="$3"
173
174 ret="$(echo $input | jq \"$filter\")"
175 if [[ "$ret" == "true" ]]; then
176 return 0
177 elif [[ -n "$expects" && "$ret" == "$expects" ]]; then
178 return 0
179 fi
180 return 1
181 }
182
183 function TEST_mon_features() {
184 local dir=$1
185 setup $dir || return 1
186
187 fsid=$(uuidgen)
188 MONA=127.0.0.1:7127 # git grep '\<7127\>' ; there must be only one
189 MONB=127.0.0.1:7128 # git grep '\<7128\>' ; there must be only one
190 MONC=127.0.0.1:7129 # git grep '\<7129\>' ; there must be only one
191 CEPH_ARGS_orig=$CEPH_ARGS
192 CEPH_ARGS="--fsid=$fsid --auth-supported=none "
193 CEPH_ARGS+="--mon-initial-members=a,b,c "
194 CEPH_ARGS+="--mon-host=$MONA,$MONB,$MONC "
195 CEPH_ARGS+="--mon-debug-no-initial-persistent-features "
196 CEPH_ARGS+="--mon-debug-no-require-luminous "
197
198 run_mon $dir a --public-addr $MONA || return 1
199 run_mon $dir b --public-addr $MONB || return 1
200 timeout 120 ceph -s > /dev/null || return 1
201
202 # NOTE:
203 # jq only support --exit-status|-e from version 1.4 forwards, which makes
204 # returning on error waaaay prettier and straightforward.
205 # However, the current automated upstream build is running with v1.3,
206 # which has no idea what -e is. Hence the convoluted error checking we
207 # need. Sad.
208 # The next time someone changes this code, please check if v1.4 is now
209 # a thing, and, if so, please change these to use -e. Thanks.
210
211 # jq '.all.supported | select([.[] == "foo"] | any)'
212
213 # expect monmap to contain 3 monitors (a, b, and c)
214 jqinput="$(ceph mon_status --format=json 2>/dev/null)"
215 jq_success "$jqinput" '.monmap.mons | length == 3' || return 1
216 # quorum contains two monitors
217 jq_success "$jqinput" '.quorum | length == 2' || return 1
218 # quorum's monitor features contain kraken and luminous
219 jqfilter='.features.quorum_mon[]|select(. == "kraken")'
220 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
221 jqfilter='.features.quorum_mon[]|select(. == "luminous")'
222 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
223
224 # monmap must have no persistent features set, because we
225 # don't currently have a quorum made out of all the monitors
226 # in the monmap.
227 jqfilter='.monmap.features.persistent | length == 0'
228 jq_success "$jqinput" "$jqfilter" || return 1
229
230 # nor do we have any optional features, for that matter.
231 jqfilter='.monmap.features.optional | length == 0'
232 jq_success "$jqinput" "$jqfilter" || return 1
233
234 # validate 'mon feature list'
235
236 jqinput="$(ceph mon feature list --format=json 2>/dev/null)"
237 # 'kraken' and 'luminous' are supported
238 jqfilter='.all.supported[] | select(. == "kraken")'
239 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
240 jqfilter='.all.supported[] | select(. == "luminous")'
241 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
242
243 # start third monitor
244 run_mon $dir c --public-addr $MONC || return 1
245
246 wait_for_quorum 300 3 || return 1
247
248 timeout 300 ceph -s > /dev/null || return 1
249
250 jqinput="$(ceph mon_status --format=json 2>/dev/null)"
251 # expect quorum to have all three monitors
252 jqfilter='.quorum | length == 3'
253 jq_success "$jqinput" "$jqfilter" || return 1
254 # quorum's monitor features contain kraken and luminous
255 jqfilter='.features.quorum_mon[]|select(. == "kraken")'
256 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
257 jqfilter='.features.quorum_mon[]|select(. == "luminous")'
258 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
259
260 # monmap must have no both 'kraken' and 'luminous' persistent
261 # features set.
262 jqfilter='.monmap.features.persistent | length == 2'
263 jq_success "$jqinput" "$jqfilter" || return 1
264 jqfilter='.monmap.features.persistent[]|select(. == "kraken")'
265 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
266 jqfilter='.monmap.features.persistent[]|select(. == "luminous")'
267 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
268
269 CEPH_ARGS=$CEPH_ARGS_orig
270 # that's all folks. thank you for tuning in.
271 teardown $dir || return 1
272 }
273
274 main misc "$@"
275
276 # Local Variables:
277 # compile-command: "cd ../.. ; make -j4 && test/mon/misc.sh"
278 # End: