]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Add reclock event script tests
authorMartin Schwenke <martin@meltin.net>
Wed, 6 Jul 2016 04:06:14 +0000 (14:06 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 21 Jul 2016 00:24:25 +0000 (02:24 +0200)
Tweak eventscript unit test infrastructure to support.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/eventscripts/01.reclock.monitor.001.sh [new file with mode: 0755]
ctdb/tests/eventscripts/01.reclock.monitor.002.sh [new file with mode: 0755]
ctdb/tests/eventscripts/01.reclock.monitor.003.sh [new file with mode: 0755]
ctdb/tests/eventscripts/01.reclock.monitor.004.sh [new file with mode: 0755]
ctdb/tests/eventscripts/01.reclock.monitor.005.sh [new file with mode: 0755]
ctdb/tests/eventscripts/etc/sysconfig/ctdb
ctdb/tests/eventscripts/scripts/local.sh
ctdb/tests/eventscripts/stubs/df

diff --git a/ctdb/tests/eventscripts/01.reclock.monitor.001.sh b/ctdb/tests/eventscripts/01.reclock.monitor.001.sh
new file mode 100755 (executable)
index 0000000..8230528
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "unset, check no-op"
+
+CTDB_RECOVERY_LOCK=""
+
+ok_null
+simple_test
diff --git a/ctdb/tests/eventscripts/01.reclock.monitor.002.sh b/ctdb/tests/eventscripts/01.reclock.monitor.002.sh
new file mode 100755 (executable)
index 0000000..b40213f
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "set to helper, check no-op"
+
+CTDB_RECOVERY_LOCK="!/some/recover/lock/helper foo"
+
+ok_null
+simple_test
diff --git a/ctdb/tests/eventscripts/01.reclock.monitor.003.sh b/ctdb/tests/eventscripts/01.reclock.monitor.003.sh
new file mode 100755 (executable)
index 0000000..2d82a21
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "set, exists"
+
+setup_reclock
+
+ok_null
+simple_test
diff --git a/ctdb/tests/eventscripts/01.reclock.monitor.004.sh b/ctdb/tests/eventscripts/01.reclock.monitor.004.sh
new file mode 100755 (executable)
index 0000000..fd185d1
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "set, doesn't exist, 4 times"
+
+setup_reclock
+rm -f "$CTDB_RECOVERY_LOCK"
+
+ok_null
+simple_test
+simple_test
+simple_test
+
+required_result 1 <<EOF
+ERROR: 4 consecutive failures for 01.reclock, marking node unhealthy
+EOF
+simple_test
diff --git a/ctdb/tests/eventscripts/01.reclock.monitor.005.sh b/ctdb/tests/eventscripts/01.reclock.monitor.005.sh
new file mode 100755 (executable)
index 0000000..e190e14
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "set, doesn't exist, 4 times"
+
+setup_reclock
+rm -f "$CTDB_RECOVERY_LOCK"
+
+ok_null
+for i in $(seq 1 3) ; do
+       simple_test
+done
+
+for i in $(seq 4 199) ; do
+       required_result 1 <<EOF
+ERROR: ${i} consecutive failures for 01.reclock, marking node unhealthy
+EOF
+       simple_test
+done
+
+required_result 1 <<EOF
+Reclock file "${CTDB_RECOVERY_LOCK}" can not be accessed. Shutting down.
+Filesystem             1024-blocks      Used Available Capacity Mounted on
+/dev/sda1                               1000000     100000     900000         10% /
+CTDB says BYE!
+ERROR: 200 consecutive failures for 01.reclock, marking node unhealthy
+EOF
+simple_test
index fe0436d6f550d2bc5d363aee01721ff1537ac2a8..e03d8103827fb3c429530aca85b85d0e42d1ec16 100644 (file)
@@ -1,4 +1,3 @@
-CTDB_RECOVERY_LOCK="/some/place/on/shared/storage"
 CTDB_DEBUGLEVEL=ERR
 
 if [ -n "$FAKE_CTDB_EXTRA_CONFIG" -a -r "$FAKE_CTDB_EXTRA_CONFIG" ] ; then
index 37141c6d14b80a15546f10991f5bc11189ef9ae6..6db6e40d513eac82618fdbcdfb293d91740101a8 100644 (file)
@@ -1129,6 +1129,16 @@ program $_rpc_service${_ver:+ version }${_ver} is not available"
 
 ######################################################################
 
+# Recovery lock fakery
+
+setup_reclock ()
+{
+       CTDB_RECOVERY_LOCK=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
+       export CTDB_RECOVERY_LOCK
+}
+
+######################################################################
+
 # VSFTPD fakery
 
 setup_vsftpd ()
index eb91a4c851dacf8ebb37cc88d54af2613f9ca3cd..64eb3814cfe5277ffffc2ee456b3ed833019c2c3 100755 (executable)
@@ -2,20 +2,19 @@
 
 usage ()
 {
-    echo "usage: df -kP <mount-point>"
+    echo "usage: df [-kP] [<mount-point>]"
     exit 1
 }
 
-if [ "$1" != "-kP" ] ; then
-    usage
+if [ "$1" = "-kP" ] ; then
+    shift
 fi
 
-shift
-if [ -z "$1" ] ; then
-    usage
-fi
+case "$1" in
+     -*) usage ;;
+esac
 
-fs="$1"
+fs="${1:-/}"
 
 # Anything starting with CTDB_DBDIR gets canonicalised to CTDB_DBDIR.
 # This helps with the setting of defaults for the filesystem checks.