]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: test_pidfile.sh lingering processes 7734/head
authorLoic Dachary <ldachary@redhat.com>
Mon, 22 Feb 2016 04:38:46 +0000 (11:38 +0700)
committerLoic Dachary <ldachary@redhat.com>
Thu, 25 Feb 2016 05:24:00 +0000 (12:24 +0700)
For the mon, using ps aux to find the process will only show part of the
command line and the $RUNID may be missing. For the OSD, the $RUNID is
passed using an environment variable and will not show at all.

There is no need to test both ceph-osd and ceph-mon since they both end
up in the same code path, pidfile_write. Add a log line that only shows
when the --pid-file is empty and grep for it in the simplest possible
way.

The TEST_pidfile test failed to kill a process because there was
no pidfile with its pid. This is fixed by backuping the pidfile before
it is modified.

http://tracker.ceph.com/issues/14834 Fixes: #14834

Signed-off-by: Loic Dachary <loic@dachary.org>
src/global/pidfile.cc
src/test/test_pidfile.sh

index 17fe6800cc0f129c613b83b48ecd79b3439cccdc..383181ee1edeeeb385adea40f4588bc4279ad26d 100644 (file)
@@ -37,6 +37,7 @@
 // when the caller is daemonized but it will show if not (-f)
 //
 #define dout_prefix *_dout
+#define dout_subsys ceph_subsys_
 
 struct pidfh {
   int pf_fd;
@@ -204,8 +205,10 @@ void pidfile_remove()
 
 int pidfile_write(const md_config_t *conf)
 {
-  if (conf->pid_file.empty())
+  if (conf->pid_file.empty()) {
+    dout(0) << __func__ << ": ignore empty --pid-file" << dendl;
     return 0;
+  }
 
   assert(pfh == nullptr);
 
index 2dec1f74a0ff47aab4adefe27acd492f457e111f..19a3b139e78bb9364cac813e860997d18bdabebe 100755 (executable)
@@ -25,40 +25,21 @@ function run() {
 function TEST_without_pidfile() {
     local dir=$1
     setup $dir
-    local RUNID=`uuidgen`
-    run_mon $dir a --pid-file= --daemonize=$RUNID || { teardown_unexist_pidfile $dir $RUNID; return 1; }
-    run_osd $dir 0 --pid-file= --daemonize=$RUNID || { teardown_unexist_pidfile $dir $RUNID; 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
+    local data=$dir/osd1
+    local id=1
+    ceph-mon \
+        --id $id \
+        --mkfs \
+        --mon-data=$data \
+        --run-dir=$dir || return 1
+    expect_failure $dir "ignore empty --pid-file" ceph-mon \
+        -f \
+        --log-to-stderr \
+        --pid-file= \
+        --id $id \
+        --mon-data=$data \
+        --run-dir=$dir || return 1
+    teardown $dir
 }
 
 function TEST_pidfile() {
@@ -87,6 +68,7 @@ function TEST_pidfile() {
     # if the pid in the file is different from the pid of the daemon
     # the file is not removed because it is assumed to be owned by
     # another daemon
+    cp $dir/osd.0.pid $dir/osd.0.pid.old  # so that kill_daemon finds the pid
     echo 123 > $dir/osd.0.pid
     kill_daemons $dir TERM osd.0 || return 1
     test -f $dir/osd.0.pid || return 1
@@ -99,4 +81,5 @@ function TEST_pidfile() {
     teardown $dir || return 1
 }
 
-main pidfile
+main pidfile "$@"
+