]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/misc.sh
update sources to v12.1.1
[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 ceph osd pool create $TEST_POOL 8
44
45 local flag
46 for flag in nodelete nopgchange nosizechange write_fadvise_dontneed noscrub nodeep-scrub; do
47 ceph osd pool set $TEST_POOL $flag 0 || return 1
48 ! ceph osd dump | grep 'pool ' | grep $flag || return 1
49 ceph osd pool set $TEST_POOL $flag 1 || return 1
50 ceph osd dump | grep 'pool ' | grep $flag || return 1
51 ceph osd pool set $TEST_POOL $flag false || return 1
52 ! ceph osd dump | grep 'pool ' | grep $flag || return 1
53 ceph osd pool set $TEST_POOL $flag false || return 1
54 # check that setting false twice does not toggle to true (bug)
55 ! ceph osd dump | grep 'pool ' | grep $flag || return 1
56 ceph osd pool set $TEST_POOL $flag true || return 1
57 ceph osd dump | grep 'pool ' | grep $flag || return 1
58 # cleanup
59 ceph osd pool set $TEST_POOL $flag 0 || return 1
60 done
61
62 local size=$(ceph osd pool get $TEST_POOL size|awk '{print $2}')
63 local min_size=$(ceph osd pool get $TEST_POOL min_size|awk '{print $2}')
64
65 ceph osd pool set $TEST_POOL scrub_min_interval 123456 || return 1
66 ceph osd dump | grep 'pool ' | grep 'scrub_min_interval 123456' || return 1
67 ceph osd pool set $TEST_POOL scrub_min_interval 0 || return 1
68 ceph osd dump | grep 'pool ' | grep 'scrub_min_interval' && return 1
69 ceph osd pool set $TEST_POOL scrub_max_interval 123456 || return 1
70 ceph osd dump | grep 'pool ' | grep 'scrub_max_interval 123456' || return 1
71 ceph osd pool set $TEST_POOL scrub_max_interval 0 || return 1
72 ceph osd dump | grep 'pool ' | grep 'scrub_max_interval' && return 1
73 ceph osd pool set $TEST_POOL deep_scrub_interval 123456 || return 1
74 ceph osd dump | grep 'pool ' | grep 'deep_scrub_interval 123456' || return 1
75 ceph osd pool set $TEST_POOL deep_scrub_interval 0 || return 1
76 ceph osd dump | grep 'pool ' | grep 'deep_scrub_interval' && return 1
77
78 #replicated pool size restrict in 1 and 10
79 ! ceph osd pool set $TEST_POOL 11 || return 1
80 #replicated pool min_size must be between in 1 and size
81 ! ceph osd pool set $TEST_POOL min_size $(expr $size + 1) || return 1
82 ! ceph osd pool set $TEST_POOL min_size 0 || return 1
83
84 local ecpool=erasepool
85 ceph osd pool create $ecpool 12 12 erasure default || return 1
86 #erasue pool size=k+m, min_size=k
87 local size=$(ceph osd pool get $ecpool size|awk '{print $2}')
88 local min_size=$(ceph osd pool get $ecpool min_size|awk '{print $2}')
89 local k=$(expr $min_size - 1) # default min_size=k+1
90 #erasure pool size can't change
91 ! ceph osd pool set $ecpool size $(expr $size + 1) || return 1
92 #erasure pool min_size must be between in k and size
93 ceph osd pool set $ecpool min_size $(expr $k + 1) || return 1
94 ! ceph osd pool set $ecpool min_size $(expr $k - 1) || return 1
95 ! ceph osd pool set $ecpool min_size $(expr $size + 1) || return 1
96
97 teardown $dir || return 1
98 }
99
100 function TEST_mon_add_to_single_mon() {
101 local dir=$1
102
103 fsid=$(uuidgen)
104 MONA=127.0.0.1:7117 # git grep '\<7117\>' : there must be only one
105 MONB=127.0.0.1:7118 # git grep '\<7118\>' : there must be only one
106 CEPH_ARGS_orig=$CEPH_ARGS
107 CEPH_ARGS="--fsid=$fsid --auth-supported=none "
108 CEPH_ARGS+="--mon-initial-members=a "
109 CEPH_ARGS+="--mon-host=$MONA "
110
111 setup $dir || return 1
112 run_mon $dir a --public-addr $MONA || return 1
113 # wait for the quorum
114 timeout 120 ceph -s > /dev/null || return 1
115 run_mon $dir b --public-addr $MONB || return 1
116 teardown $dir || return 1
117
118 setup $dir || return 1
119 run_mon $dir a --public-addr $MONA || return 1
120 # without the fix of #5454, mon.a will assert failure at seeing the MMonJoin
121 # from mon.b
122 run_mon $dir b --public-addr $MONB || return 1
123 # wait for the quorum
124 timeout 120 ceph -s > /dev/null || return 1
125 local num_mons
126 num_mons=$(ceph mon dump --format=json 2>/dev/null | jq ".mons | length") || return 1
127 [ $num_mons == 2 ] || return 1
128 # no reason to take more than 120 secs to get this submitted
129 timeout 120 ceph mon add b $MONB || return 1
130 teardown $dir || return 1
131 }
132
133 function TEST_no_segfault_for_bad_keyring() {
134 local dir=$1
135 setup $dir || return 1
136 # create a client.admin key and add it to ceph.mon.keyring
137 ceph-authtool --create-keyring $dir/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'
138 ceph-authtool --create-keyring $dir/ceph.client.admin.keyring --gen-key -n client.admin --cap mon 'allow *'
139 ceph-authtool $dir/ceph.mon.keyring --import-keyring $dir/ceph.client.admin.keyring
140 CEPH_ARGS_TMP="--fsid=$(uuidgen) --mon-host=127.0.0.1:7102 --auth-supported=cephx "
141 CEPH_ARGS_orig=$CEPH_ARGS
142 CEPH_ARGS="$CEPH_ARGS_TMP --keyring=$dir/ceph.mon.keyring "
143 run_mon $dir a
144 # create a bad keyring and make sure no segfault occurs when using the bad keyring
145 echo -e "[client.admin]\nkey = BQAUlgtWoFePIxAAQ9YLzJSVgJX5V1lh5gyctg==" > $dir/bad.keyring
146 CEPH_ARGS="$CEPH_ARGS_TMP --keyring=$dir/bad.keyring"
147 ceph osd dump 2> /dev/null
148 # 139(11|128) means segfault and core dumped
149 [ $? -eq 139 ] && return 1
150 CEPH_ARGS=$CEPH_ARGS_orig
151 teardown $dir || return 1
152 }
153
154 function TEST_mon_features() {
155 local dir=$1
156 setup $dir || return 1
157
158 fsid=$(uuidgen)
159 MONA=127.0.0.1:7127 # git grep '\<7127\>' ; there must be only one
160 MONB=127.0.0.1:7128 # git grep '\<7128\>' ; there must be only one
161 MONC=127.0.0.1:7129 # git grep '\<7129\>' ; there must be only one
162 CEPH_ARGS_orig=$CEPH_ARGS
163 CEPH_ARGS="--fsid=$fsid --auth-supported=none "
164 CEPH_ARGS+="--mon-initial-members=a,b,c "
165 CEPH_ARGS+="--mon-host=$MONA,$MONB,$MONC "
166 CEPH_ARGS+="--mon-debug-no-initial-persistent-features "
167 CEPH_ARGS+="--mon-debug-no-require-luminous "
168
169 run_mon $dir a --public-addr $MONA || return 1
170 run_mon $dir b --public-addr $MONB || return 1
171 timeout 120 ceph -s > /dev/null || return 1
172
173 # expect monmap to contain 3 monitors (a, b, and c)
174 jqinput="$(ceph mon_status --format=json 2>/dev/null)"
175 jq_success "$jqinput" '.monmap.mons | length == 3' || return 1
176 # quorum contains two monitors
177 jq_success "$jqinput" '.quorum | length == 2' || return 1
178 # quorum's monitor features contain kraken and luminous
179 jqfilter='.features.quorum_mon[]|select(. == "kraken")'
180 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
181 jqfilter='.features.quorum_mon[]|select(. == "luminous")'
182 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
183
184 # monmap must have no persistent features set, because we
185 # don't currently have a quorum made out of all the monitors
186 # in the monmap.
187 jqfilter='.monmap.features.persistent | length == 0'
188 jq_success "$jqinput" "$jqfilter" || return 1
189
190 # nor do we have any optional features, for that matter.
191 jqfilter='.monmap.features.optional | length == 0'
192 jq_success "$jqinput" "$jqfilter" || return 1
193
194 # validate 'mon feature ls'
195
196 jqinput="$(ceph mon feature ls --format=json 2>/dev/null)"
197 # 'kraken' and 'luminous' are supported
198 jqfilter='.all.supported[] | select(. == "kraken")'
199 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
200 jqfilter='.all.supported[] | select(. == "luminous")'
201 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
202
203 # start third monitor
204 run_mon $dir c --public-addr $MONC || return 1
205
206 wait_for_quorum 300 3 || return 1
207
208 timeout 300 ceph -s > /dev/null || return 1
209
210 jqinput="$(ceph mon_status --format=json 2>/dev/null)"
211 # expect quorum to have all three monitors
212 jqfilter='.quorum | length == 3'
213 jq_success "$jqinput" "$jqfilter" || return 1
214 # quorum's monitor features contain kraken and luminous
215 jqfilter='.features.quorum_mon[]|select(. == "kraken")'
216 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
217 jqfilter='.features.quorum_mon[]|select(. == "luminous")'
218 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
219
220 # monmap must have no both 'kraken' and 'luminous' persistent
221 # features set.
222 jqfilter='.monmap.features.persistent | length == 2'
223 jq_success "$jqinput" "$jqfilter" || return 1
224 jqfilter='.monmap.features.persistent[]|select(. == "kraken")'
225 jq_success "$jqinput" "$jqfilter" "kraken" || return 1
226 jqfilter='.monmap.features.persistent[]|select(. == "luminous")'
227 jq_success "$jqinput" "$jqfilter" "luminous" || return 1
228
229 CEPH_ARGS=$CEPH_ARGS_orig
230 # that's all folks. thank you for tuning in.
231 teardown $dir || return 1
232 }
233
234 main misc "$@"
235
236 # Local Variables:
237 # compile-command: "cd ../.. ; make -j4 && test/mon/misc.sh"
238 # End: