3 # Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
4 # Copyright (C) 2014, 2015, 2016 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.
19 # ceph-disk.sh is launched by tox which expects tox.ini in current
20 # directory. so we cannot run ceph-disk.sh in build directory directly,
21 # and hence not able to use detect-build-env-vars.sh to set the build
23 if [ -z "$CEPH_ROOT" ] ||
[ -z "$CEPH_BIN" ] ||
[ -z "$CEPH_LIB" ]; then
24 CEPH_ROOT
=`readlink -f $(dirname $0)/../../..`
26 CEPH_LIB
=$CEPH_ROOT/.libs
28 source $CEPH_ROOT/qa
/workunits
/ceph-helpers.sh
32 PS4
='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
34 export PATH
=$CEPH_BIN:.
:$PATH # make sure program from sources are preferred
35 export LD_LIBRARY_PATH
=$CEPH_LIB
36 : ${CEPH_DISK:=ceph-disk}
38 CEPH_DISK_ARGS
+=" --verbose"
39 CEPH_DISK_ARGS
+=" --prepend-to-path="
41 if [ `uname` != FreeBSD
]; then
44 PROCDIR
="/compat/linux"
48 timeout
=$
(which timeout
)
52 uuidgen
=$
(which uuidgen
)
58 touch $dir/ceph.conf
# so ceph-disk think ceph is the cluster
63 if ! test -e $dir ; then
67 if [ `uname` != FreeBSD
] && \
68 [ $
(stat
-f -c '%T' .
) == "btrfs" ]; then
72 grep " $(pwd)/$dir/" < ${PROCDIR}/proc
/mounts |
while read mounted rest
; do
78 function command_fixture
() {
83 local fpath
=`readlink -f $(which $command)`
84 [ "$fpath" = `readlink -f $CEPH_BIN/$command` ] ||
[ "$fpath" = `readlink -f $(pwd)/$command` ] ||
return 1
86 cat > $dir/$command <<EOF
88 touch $dir/used-$command
89 exec $CEPH_BIN/$command "\$@"
91 chmod +x
$dir/$command
94 function tweak_path
() {
102 command_fixture
$dir ceph-conf ||
return 1
103 command_fixture
$dir ceph-osd ||
return 1
105 test_activate_dir
$dir ||
return 1
107 [ ! -f $dir/used-ceph-conf
] ||
return 1
108 [ ! -f $dir/used-ceph-osd
] ||
return 1
114 command_fixture
$dir ceph-conf ||
return 1
115 command_fixture
$dir ceph-osd ||
return 1
117 $tweaker $dir test_activate_dir ||
return 1
119 [ -f $dir/used-ceph-osd
] ||
return 1
124 function use_prepend_to_path
() {
129 ceph_disk_args
+=" --statedir=$dir"
130 ceph_disk_args
+=" --sysconfdir=$dir"
131 ceph_disk_args
+=" --prepend-to-path=$dir"
132 ceph_disk_args
+=" --verbose"
133 CEPH_DISK_ARGS
="$ceph_disk_args" \
134 "$@" $dir ||
return 1
137 function test_prepend_to_path
() {
140 tweak_path
$dir use_prepend_to_path ||
return 1
143 function use_path
() {
147 "$@" $dir ||
return 1
150 function test_path
() {
153 tweak_path
$dir use_path ||
return 1
156 function test_no_path
() {
159 ( export PATH
=..
/ceph-detect-init
/virtualenv
/bin
:virtualenv
/bin
:$CEPH_BIN:/usr
/bin
:/bin
:/usr
/local
/bin
; test_activate_dir
$dir) ||
return 1
162 function test_mark_init
() {
168 local osd_data
=$dir/dir
171 local osd_uuid
=$
($uuidgen)
175 ${CEPH_DISK} $CEPH_DISK_ARGS \
176 prepare
--osd-uuid $osd_uuid $osd_data ||
return 1
178 ${CEPH_DISK} $CEPH_DISK_ARGS \
183 $osd_data ||
return 1
185 test -f $osd_data/$
(ceph-detect-init
) ||
return 1
187 if test systemd
= $
(ceph-detect-init
) ; then
192 $timeout $TIMEOUT ${CEPH_DISK} $CEPH_DISK_ARGS \
195 --mark-init=$expected \
197 $osd_data ||
return 1
199 ! test -f $osd_data/$
(ceph-detect-init
) ||
return 1
200 test -f $osd_data/$expected ||
return 1
203 function test_zap
() {
205 local osd_data
=$dir/dir
208 ${CEPH_DISK} $CEPH_DISK_ARGS zap
$osd_data 2>&1 |
grep -q 'not full block device' ||
return 1
213 # ceph-disk prepare returns immediately on success if the magic file
214 # exists in the --osd-data directory.
215 function test_activate_dir_magic
() {
217 local uuid
=$
($uuidgen)
218 local osd_data
=$dir/osd
220 echo a failure to create the fsid
file implies the magic
file is not created
222 mkdir
-p $osd_data/fsid
223 CEPH_ARGS
="--fsid $uuid" \
224 ${CEPH_DISK} $CEPH_DISK_ARGS prepare
$osd_data > $dir/out
2>&1
225 grep --quiet 'Is a directory' $dir/out ||
return 1
226 ! [ -f $osd_data/magic
] ||
return 1
229 echo successfully prepare the OSD
231 CEPH_ARGS
="--fsid $uuid" \
232 ${CEPH_DISK} $CEPH_DISK_ARGS prepare
$osd_data 2>&1 |
tee $dir/out
233 grep --quiet 'Preparing osd data dir' $dir/out ||
return 1
234 grep --quiet $uuid $osd_data/ceph_fsid ||
return 1
235 [ -f $osd_data/magic
] ||
return 1
237 echo will not override an existing OSD
239 CEPH_ARGS
="--fsid $($uuidgen)" \
240 ${CEPH_DISK} $CEPH_DISK_ARGS prepare
$osd_data 2>&1 |
tee $dir/out
241 grep --quiet 'Data dir .* already exists' $dir/out ||
return 1
242 grep --quiet $uuid $osd_data/ceph_fsid ||
return 1
245 function test_pool_read_write
() {
249 $timeout $TIMEOUT ceph osd pool
set $TEST_POOL size
1 ||
return 1
251 local id
=$
(ceph osd create
$osd_uuid)
253 ceph osd crush add osd.
$id $weight root
=default
host=localhost ||
return 1
255 $timeout $TIMEOUT rados
--pool $TEST_POOL put BAR
$dir/BAR ||
return 1
256 $timeout $TIMEOUT rados
--pool $TEST_POOL get BAR
$dir/BAR.copy ||
return 1
257 $diff $dir/BAR
$dir/BAR.copy ||
return 1
260 function test_activate
() {
263 local osd_uuid
=$
($uuidgen)
266 if [ `uname` = FreeBSD
]; then
267 # for unknown reasons FreeBSD timeout does not return here
268 # So we run without timeout
271 timeoutcmd
="${timeout} $TIMEOUT"
274 ${CEPH_DISK} $CEPH_DISK_ARGS \
275 prepare
--osd-uuid $osd_uuid $to_prepare ||
return 1
277 $timeoutcmd ${CEPH_DISK} $CEPH_DISK_ARGS \
280 $to_activate ||
return 1
282 test_pool_read_write
$osd_uuid ||
return 1
285 function test_activate_dir
() {
292 local osd_data
=$dir/dir
294 test_activate
$osd_data $osd_data ||
return 1
297 function test_activate_dir_bluestore
() {
301 local osd_data
=$dir/dir
303 local to_prepare
=$osd_data
304 local to_activate
=$osd_data
305 local osd_uuid
=$
($uuidgen)
307 CEPH_ARGS
=" --bluestore-block-size=10737418240 $CEPH_ARGS" \
308 ${CEPH_DISK} $CEPH_DISK_ARGS \
309 prepare
--bluestore --block-file --osd-uuid $osd_uuid $to_prepare ||
return 1
311 CEPH_ARGS
=" --osd-objectstore=bluestore --bluestore-fsck-on-mount=true --enable_experimental_unrecoverable_data_corrupting_features=* --bluestore-block-db-size=67108864 --bluestore-block-wal-size=134217728 --bluestore-block-size=10737418240 $CEPH_ARGS" \
312 $timeout $TIMEOUT ${CEPH_DISK} $CEPH_DISK_ARGS \
315 $to_activate ||
return 1
316 test_pool_read_write
$osd_uuid ||
return 1
319 function test_find_cluster_by_uuid
() {
321 test_activate_dir
$dir 2>&1 |
tee $dir/test_find
322 ! grep "No cluster conf found in $dir" $dir/test_find ||
return 1
326 test_activate_dir
$dir "rm $dir/ceph.conf" > $dir/test_find
2>&1
327 cp $dir/test_find
/tmp
328 grep --quiet "No cluster conf found in $dir" $dir/test_find ||
return 1
331 # http://tracker.ceph.com/issues/9653
332 function test_keyring_path
() {
334 test_activate_dir
$dir 2>&1 |
tee $dir/test_keyring
335 grep --quiet "keyring $dir/bootstrap-osd/ceph.keyring" $dir/test_keyring ||
return 1
338 # http://tracker.ceph.com/issues/13522
339 function ceph_osd_fail_once_fixture
() {
341 local command=ceph-osd
342 local fpath
=`readlink -f $(which $command)`
343 [ "$fpath" = `readlink -f $CEPH_BIN/$command` ] ||
[ "$fpath" = `readlink -f $(pwd)/$command` ] ||
return 1
345 cat > $dir/$command <<EOF
347 if echo "\$@" | grep -e --mkfs && ! test -f $dir/used-$command ; then
348 touch $dir/used-$command
349 # sleep longer than the first CEPH_OSD_MKFS_DELAYS value (5) below
352 exec $CEPH_BIN/$command "\$@"
355 chmod +x
$dir/$command
358 function test_ceph_osd_mkfs
() {
360 ceph_osd_fail_once_fixture
$dir ||
return 1
361 CEPH_OSD_MKFS_DELAYS
='5 300 300' use_path
$dir test_activate_dir ||
return 1
362 [ -f $dir/used-ceph-osd
] ||
return 1
365 function test_crush_device_class
() {
371 local osd_data
=$dir/dir
374 local osd_uuid
=$
($uuidgen)
378 ${CEPH_DISK} $CEPH_DISK_ARGS \
379 prepare
--osd-uuid $osd_uuid \
380 --crush-device-class CRUSH_CLASS \
381 $osd_data ||
return 1
382 test -f $osd_data/crush_device_class ||
return 1
383 test $
(cat $osd_data/crush_device_class
) = CRUSH_CLASS ||
return 1
385 ceph osd crush class create CRUSH_CLASS ||
return 1
387 CEPH_ARGS
="--crush-location=root=default $CEPH_ARGS" \
388 ${CEPH_DISK} $CEPH_DISK_ARGS \
392 $osd_data ||
return 1
395 for delay
in 2 4 8 16 32 64 128 256 ; do
396 if ceph osd crush dump |
grep --quiet 'CRUSH_CLASS' ; then
401 ceph osd crush dump
# for debugging purposes
409 CEPH_DISK_ARGS
+=" --statedir=$dir"
410 CEPH_DISK_ARGS
+=" --sysconfdir=$dir"
412 export CEPH_MON
="127.0.0.1:7451" # git grep '\<7451\>' : there must be only one
414 CEPH_ARGS
+=" --fsid=$(uuidgen)"
415 CEPH_ARGS
+=" --auth-supported=none"
416 CEPH_ARGS
+=" --mon-host=$CEPH_MON"
417 CEPH_ARGS
+=" --chdir="
418 CEPH_ARGS
+=" --journal-dio=false"
419 CEPH_ARGS
+=" --erasure-code-dir=$CEPH_LIB"
420 CEPH_ARGS
+=" --plugin-dir=$CEPH_LIB"
421 CEPH_ARGS
+=" --log-file=$dir/\$name.log"
422 CEPH_ARGS
+=" --pid-file=$dir/\$name.pidfile"
423 CEPH_ARGS
+=" --osd-class-dir=$CEPH_LIB"
424 CEPH_ARGS
+=" --run-dir=$dir"
425 CEPH_ARGS
+=" --osd-failsafe-full-ratio=.99"
426 CEPH_ARGS
+=" --osd-journal-size=100"
427 CEPH_ARGS
+=" --debug-osd=20"
428 CEPH_ARGS
+=" --debug-bdev=20"
429 CEPH_ARGS
+=" --debug-bluestore=20"
430 CEPH_ARGS
+=" --osd-max-object-name-len=460"
431 CEPH_ARGS
+=" --osd-max-object-namespace-len=64 "
432 local default_actions
433 default_actions
+="test_path "
434 default_actions
+="test_no_path "
435 default_actions
+="test_find_cluster_by_uuid "
436 default_actions
+="test_prepend_to_path "
437 default_actions
+="test_activate_dir_magic "
438 default_actions
+="test_activate_dir "
439 default_actions
+="test_keyring_path "
440 [ `uname` != FreeBSD
] && \
441 default_actions
+="test_mark_init "
442 default_actions
+="test_zap "
443 [ `uname` != FreeBSD
] && \
444 default_actions
+="test_activate_dir_bluestore "
445 default_actions
+="test_ceph_osd_mkfs "
446 default_actions
+="test_crush_device_class "
447 local actions
=${@:-$default_actions}
448 for action
in $actions ; do
449 setup
$dir ||
return 1
451 $action $dir ||
return 1
453 teardown
$dir ||
return 1
457 main test-ceph-disk
"$@"
460 # compile-command: "cd .. ; test/ceph-disk.sh # test_activate_dir"