Skip to content

Commit

Permalink
test: add unitest test_pidfile.sh
Browse files Browse the repository at this point in the history
Fixes: #13422
Signed-off-by: shun song <song.shun3@zte.com.cn>
  • Loading branch information
root authored and shun-s committed Jan 26, 2016
1 parent f2c0ef4 commit 39983b8
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/test/Makefile.am
Expand Up @@ -89,7 +89,8 @@ check_SCRIPTS += \
test/osd/osd-markdown.sh \
test/mon/mon-handle-forward.sh \
test/libradosstriper/rados-striper.sh \
test/test_objectstore_memstore.sh
test/test_objectstore_memstore.sh \
test/test_pidfile.sh

check_SCRIPTS += test/ceph-disk.sh

Expand Down
115 changes: 115 additions & 0 deletions src/test/test_pidfile.sh
@@ -0,0 +1,115 @@
#!/bin/bash -e

#
# test pidfile here
#

# Includes
source ../qa/workunits/ceph-helpers.sh

function run() {
local dir=$1
shift

export CEPH_MON="127.0.0.1:17108"
export CEPH_ARGS
CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
CEPH_ARGS+="--mon-host=$CEPH_MON "

local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
for func in $funcs ; do
$func $dir || return 1
done
}


function TEST_normal() {
local dir=$1
setup $dir
run_mon $dir a
run_osd $dir 0
teardown $dir
}

function TEST_without_pidfile() {
local dir=$1
setup $dir
local RUNID=`uuidgen`
run_mon $dir a --pid-file= --daemonize=$RUNID || { teardown_unexist_pidfile $dir; return 1; }
run_osd $dir 0 --pid-file= --daemonize=$RUNID || { teardown_unexist_pidfile $dir; return 1; }
teardown_unexist_pidfile $dir $RUNID || return 1
}

function teardown_unexist_pidfile() {
local dir=$1
shift
local RUNID=$1
shift
local delays=('0' '1' '3' '5' '10' '10' '20' '60')
local pids=$(ps aux|awk "/cep[h].*$RUNID.*/ {print \$2}")
for i in $pids ; do
local kill_complete="0"
local count=0
while [ $kill_complete -eq "0" ] ; do
if kill -9 $i 2> /dev/null ; then
kill_complete="0"
count=$((count+1))
sleep ${delays[$count]}
else
kill_complete="1"
fi
done
done
if [ $(stat -f -c '%T' .) == "btrfs" ]; then
__teardown_btrfs $dir
fi
rm -fr $dir
if [ $kill_complete -eq "0" ] ;then
return 1
else
return 0
fi
}


function run_osd_again() {
local dir=$1
shift
local id=$1
shift
ceph-osd \
--cluster=ceph \
--id=$id \
--osd-data=$dir/$id \
--osd-journal=$dir/$id/journal \
--pid-file $dir/osd.0.pid 2>&1 | grep "failed to lock pidfile"
}

function run_mon_again() {

local dir=$1
shift
local id=$1
shift
ceph-mon \
--id $id \
--mon-data=$dir \
--log-file=$dir/mon.$id.log \
--mon-cluster-log-file=$dir/log \
--run-dir=$dir \
--pid-file=$dir/mon.$id.pid 2>&1 | grep "failed to lock pidfile"
}

function TEST_contend_pidfile() {
local dir=$1
setup $dir

run_mon $dir a
run_mon_again $dir a || return 1

run_osd $dir 0
run_osd_again $dir 0 || return 1
teardown $dir || return 1
}

main pidfile

0 comments on commit 39983b8

Please sign in to comment.