From c1e1c8d18e6c6257f870a1193307ae5f73764a59 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 22 Feb 2016 11:38:46 +0700 Subject: [PATCH] tests: test_pidfile.sh lingering processes 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 --- src/global/pidfile.cc | 5 +++- src/test/test_pidfile.sh | 53 ++++++++++++++-------------------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/global/pidfile.cc b/src/global/pidfile.cc index 17fe6800cc0f..383181ee1ede 100644 --- a/src/global/pidfile.cc +++ b/src/global/pidfile.cc @@ -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); diff --git a/src/test/test_pidfile.sh b/src/test/test_pidfile.sh index 2dec1f74a0ff..19a3b139e78b 100755 --- a/src/test/test_pidfile.sh +++ b/src/test/test_pidfile.sh @@ -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 "$@" + -- 2.47.3