]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add unitest test_pidfile.sh 7075/head
authorroot <root@clove83.zte.com.cn>
Thu, 14 Jan 2016 12:20:39 +0000 (20:20 +0800)
committershun-s <song.shun3@zte.com.cn>
Wed, 27 Jan 2016 06:38:54 +0000 (14:38 +0800)
Fixes: #13422
Signed-off-by: shun song <song.shun3@zte.com.cn>
src/test/Makefile.am
src/test/test_pidfile.sh [new file with mode: 0755]

index a9d3dbdf5c126fdc8308b45708396949317caac4..02c6cae5ca838b30dee64757fbb5ec6f3dbb6777 100644 (file)
@@ -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
 
diff --git a/src/test/test_pidfile.sh b/src/test/test_pidfile.sh
new file mode 100755 (executable)
index 0000000..2a5cb27
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/bash 
+
+#
+# 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_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=${4:-0 0 1 1 1 2 3 5 5 5 10 10 20 60 60 60 120}
+    local pids=$(ps aux|awk "/cep[h].*$RUNID.*/ {print \$2}")
+    local status=0
+    for i in $pids ; do
+        local kill_complete=false
+        for try in $delays ; do  
+            if kill $i 2> /dev/null ; then
+                kill_complete=false
+                sleep $try
+            else
+                kill_complete=true
+                break
+            fi
+       done
+       if ! $kill_complete ; then
+            status=1
+       fi   
+    done
+    if [ $(stat -f -c '%T' .) == "btrfs" ]; then
+         __teardown_btrfs $dir
+    fi
+    rm -fr $dir
+    return $status
+}
+
+function TEST_contend_pidfile() {
+    local dir=$1
+    setup $dir 
+    run_mon $dir a 
+    run_mon $dir a 2>&1 | grep "failed to lock pidfile" || return 1
+
+    run_osd $dir 0 
+    run_osd $dir 0 2>&1 | grep "failed to lock pidfile" || return 1
+    teardown $dir || return 1
+}
+
+main pidfile