]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: shell test helpers to run MONs from sources
authorLoic Dachary <loic@dachary.org>
Wed, 8 Jan 2014 11:41:06 +0000 (12:41 +0100)
committerLoic Dachary <loic@dachary.org>
Sun, 26 Jan 2014 12:40:53 +0000 (13:40 +0100)
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 <loic@dachary.org>
src/test/mon/mon-test-helpers.sh [new file with mode: 0644]

diff --git a/src/test/mon/mon-test-helpers.sh b/src/test/mon/mon-test-helpers.sh
new file mode 100644 (file)
index 0000000..63360c9
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/bash
+#
+# Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+#
+# Author: Loic Dachary <loic@dachary.org>
+#
+# 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
+}