From: Loic Dachary Date: Wed, 8 Jan 2014 11:41:06 +0000 (+0100) Subject: mon: shell test helpers to run MONs from sources X-Git-Tag: v0.78~272^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d9a689d69ac8f1803fc0e057a274e3bc1d7fe044;p=ceph.git mon: shell test helpers to run MONs from sources The intent is to make it more convenient to reproduce a specific mon behavior and observe the result by grepping the logs. It can be handy for bug diagnostic. The test could be included as a unit test to be run on make check. The setup function will prepare a directory and kill leftover from a previous run. The teardown function cleans up on success. The run function is expected to be provided by the calling script and can make use of the run_mon function to mkfs + run a monitor. Signed-off-by: Loic Dachary --- diff --git a/src/test/mon/mon-test-helpers.sh b/src/test/mon/mon-test-helpers.sh new file mode 100644 index 000000000000..63360c92807d --- /dev/null +++ b/src/test/mon/mon-test-helpers.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Copyright (C) 2013 Cloudwatt +# +# Author: Loic Dachary +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library Public License for more details. +# +function setup() { + local dir=$1 + teardown $dir + mkdir $dir +} + +function teardown() { + local dir=$1 + kill_daemons $dir + rm -fr $dir +} + +function run_mon() { + local dir=$1 + shift + local id=$1 + shift + dir+=/$id + + ./ceph-mon \ + --id $id \ + --mkfs \ + --mon-data=$dir --run-dir=$dir \ + "$@" + + ./ceph-mon \ + --id $id \ + --debug-mon 20 \ + --debug-ms 20 \ + --chdir= \ + --mon-data=$dir \ + --log-file=$dir/log \ + --mon-cluster-log-file=$dir/log \ + --run-dir=$dir \ + --pid-file=$dir/pidfile \ + "$@" +} + +function kill_daemons() { + local dir=$1 + for pidfile in $(find $dir | grep pidfile) ; do + for try in 0 1 1 1 2 3 ; do + kill $(cat $pidfile 2> /dev/null) 2> /dev/null || break + sleep $try + done + done +} + +function main() { + local dir=$1 + + PS4='${FUNCNAME[0]}: $LINENO: ' + export CEPH_CONF=/dev/null + unset CEPH_ARGS + + setup $dir || return 1 + set -x + run $dir || return 1 + set +x + teardown $dir || return 1 +}