diff options
author | Martin Schwenke <martin@meltin.net> | 2012-01-15 14:55:52 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2012-02-06 16:00:24 +1100 |
commit | 9f2ce614a792994ffcf2dc13b693429b6b17afcc (patch) | |
tree | b5ee2557f94e1c59dcd12ad0bed44c3f42f0c5a9 | |
parent | e420c6b8019bc66a26b72fa8db457b5eb0f5a6c6 (diff) | |
download | samba-9f2ce614a792994ffcf2dc13b693429b6b17afcc.tar.gz samba-9f2ce614a792994ffcf2dc13b693429b6b17afcc.tar.xz samba-9f2ce614a792994ffcf2dc13b693429b6b17afcc.zip |
Tests: initial ctdb tool testcases
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 47e9975fa75a7bb2628a751dc19d35e2c5c57ce3)
-rw-r--r-- | ctdb/tests/tool/common.sh | 71 | ||||
-rwxr-xr-x | ctdb/tests/tool/run_tests.sh | 31 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/func.parse_nodestring.001.sh | 16 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/func.parse_nodestring.002.sh | 16 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/func.parse_nodestring.003.sh | 15 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/stubby.nodestatus.001.sh | 30 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/stubby.nodestatus.002.sh | 30 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/stubby.nodestatus.003.sh | 30 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/stubby.nodestatus.004.sh | 28 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/stubby.status.001.sh | 37 | ||||
-rwxr-xr-x | ctdb/tests/tool/testcases/stubby.status.002.sh | 37 |
11 files changed, 341 insertions, 0 deletions
diff --git a/ctdb/tests/tool/common.sh b/ctdb/tests/tool/common.sh new file mode 100644 index 0000000000..75ca6ba207 --- /dev/null +++ b/ctdb/tests/tool/common.sh @@ -0,0 +1,71 @@ +# Hey Emacs, this is a -*- shell-script -*- !!! :-) + +# Print a message and exit. +die () { echo "$@" >&2 ; exit 1 ; } + +test_bin="$(dirname ${TESTS_SUBDIR})/bin" + +define_test () +{ + _f="$0" + _f="${_f#./}" # strip leading ./ + _f="${_f#testcases/}" # strip leading testcases/ + _f="${_f%.sh}" # strip off .sh suffix if any + + case "$_f" in + func.*) + _func="${_f#func.}" + _func="${_func%.*}" # Strip test number + test_prog="${test_bin}/ctdb_tool_libctdb ${_func}" + ;; + stubby.*) + _cmd="${_f#stubby.}" + _cmd="${_cmd%.*}" # Strip test number + test_prog="${test_bin}/ctdb_tool_stubby ${_cmd}" + ;; + *) + die "Unknown pattern for testcase \"$_f\"" + esac + + printf "%-28s - %s\n" "$_f" "$1" +} + +required_result () +{ + required_rc="${1:-0}" + required_output=$(cat) +} + +simple_test () +{ + _out=$($test_prog "$@" 2>&1) + _rc=$? + + # Most of the tests when the tool fails will have a date/time/pid + # prefix. Strip that because it isn't possible to match it. + if [ $required_rc -ne 0 ] ; then + OUT_FILTER='s@^[0-9/]+ [0-9:\.]+ \[[0-9]+\]:@DATE TIME \[PID\]:@' + fi + + if [ -n "$OUT_FILTER" ] ; then + _fout=$(echo "$_out" | sed -r "$OUT_FILTER") + else + _fout="$_out" + fi + + if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then + echo "PASSED" + else + cat -A <<EOF +################################################## +Required output (Exit status: ${required_rc}): +################################################## +$required_output +################################################## +Actual output (Exit status: ${_rc}): +################################################## +$_out +EOF + return 1 + fi +} diff --git a/ctdb/tests/tool/run_tests.sh b/ctdb/tests/tool/run_tests.sh new file mode 100755 index 0000000000..b4ad737d58 --- /dev/null +++ b/ctdb/tests/tool/run_tests.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Run some IP allocation unit tests. + +cd $(dirname "$0") +export TESTS_SUBDIR=$(pwd) + +test_dir=$(dirname "$TESTS_SUBDIR") + +opts="-d" + +for i ; do + case "$i" in + -*) + opts="$opts $i" + shift + ;; + *) + break + esac +done + +tests="" +if [ -z "$*" ] ; then + tests=$(ls testcases/*.[0-9][0-9][0-9].sh 2>/dev/null) +fi + +"$test_dir/scripts/run_tests" $opts "$@" $tests || exit 1 + +echo "All OK" +exit 0 diff --git a/ctdb/tests/tool/testcases/func.parse_nodestring.001.sh b/ctdb/tests/tool/testcases/func.parse_nodestring.001.sh new file mode 100755 index 0000000000..04447cbb6a --- /dev/null +++ b/ctdb/tests/tool/testcases/func.parse_nodestring.001.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, dd_ok, 3 healthy" + +required_result <<EOF +NODES: 0 1 2 +PNN MODE: BROADCAST_ALL (4026531842) +EOF + +simple_test all true <<EOF +0 192.168.20.41 0x0 +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 CURRENT RECMASTER +EOF diff --git a/ctdb/tests/tool/testcases/func.parse_nodestring.002.sh b/ctdb/tests/tool/testcases/func.parse_nodestring.002.sh new file mode 100755 index 0000000000..f5b9777af2 --- /dev/null +++ b/ctdb/tests/tool/testcases/func.parse_nodestring.002.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, dd_ok, 2 ok/1 disconnected" + +required_result <<EOF +NODES: 0 1 2 +PNN MODE: BROADCAST_ALL (4026531842) +EOF + +simple_test all true <<EOF +0 192.168.20.41 0x0 +1 192.168.20.42 0x1 +2 192.168.20.43 0x0 CURRENT RECMASTER +EOF diff --git a/ctdb/tests/tool/testcases/func.parse_nodestring.003.sh b/ctdb/tests/tool/testcases/func.parse_nodestring.003.sh new file mode 100755 index 0000000000..709bfa20e4 --- /dev/null +++ b/ctdb/tests/tool/testcases/func.parse_nodestring.003.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, current disconnected" + +required_result 10 <<EOF +DATE TIME [PID]: Unable to get nodemap from local node +EOF + +simple_test all true <<EOF +0 192.168.20.41 0x0 +1 192.168.20.42 0x0 +2 192.168.20.43 0x1 CURRENT RECMASTER +EOF diff --git a/ctdb/tests/tool/testcases/stubby.nodestatus.001.sh b/ctdb/tests/tool/testcases/stubby.nodestatus.001.sh new file mode 100755 index 0000000000..1d364277af --- /dev/null +++ b/ctdb/tests/tool/testcases/stubby.nodestatus.001.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, 3 nodes, all OK" + +required_result 0 <<EOF +Number of nodes:3 +pnn:0 192.168.20.41 OK +pnn:1 192.168.20.42 OK +pnn:2 192.168.20.43 OK (THIS NODE) +EOF + +simple_test all <<EOF +NODEMAP +0 192.168.20.41 0x0 +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 CURRENT RECMASTER + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/ctdb/tests/tool/testcases/stubby.nodestatus.002.sh b/ctdb/tests/tool/testcases/stubby.nodestatus.002.sh new file mode 100755 index 0000000000..9e311b2d7d --- /dev/null +++ b/ctdb/tests/tool/testcases/stubby.nodestatus.002.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "-n all, 3 nodes, all OK" + +required_result 0 <<EOF +Number of nodes:3 +pnn:0 192.168.20.41 OK +pnn:1 192.168.20.42 OK +pnn:2 192.168.20.43 OK (THIS NODE) +EOF + +simple_test all <<EOF +NODEMAP +0 192.168.20.41 0x0 +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 CURRENT RECMASTER + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/ctdb/tests/tool/testcases/stubby.nodestatus.003.sh b/ctdb/tests/tool/testcases/stubby.nodestatus.003.sh new file mode 100755 index 0000000000..28837d0af8 --- /dev/null +++ b/ctdb/tests/tool/testcases/stubby.nodestatus.003.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, 3 nodes, 1 disconnected" + +required_result 1 <<EOF +Number of nodes:3 +pnn:0 192.168.20.41 OK +pnn:1 192.168.20.42 DISCONNECTED|INACTIVE +pnn:2 192.168.20.43 OK (THIS NODE) +EOF + +simple_test all <<EOF +NODEMAP +0 192.168.20.41 0x0 +1 192.168.20.42 0x1 +2 192.168.20.43 0x0 CURRENT RECMASTER + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/ctdb/tests/tool/testcases/stubby.nodestatus.004.sh b/ctdb/tests/tool/testcases/stubby.nodestatus.004.sh new file mode 100755 index 0000000000..6f5193f643 --- /dev/null +++ b/ctdb/tests/tool/testcases/stubby.nodestatus.004.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "-n all, 3 nodes, 1 disconnected" + +required_result 0 <<EOF +pnn:0 192.168.20.41 OK +pnn:2 192.168.20.43 OK (THIS NODE) +EOF + +simple_test -n all <<EOF +NODEMAP +0 192.168.20.41 0x0 +1 192.168.20.42 0x1 +2 192.168.20.43 0x0 CURRENT RECMASTER + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/ctdb/tests/tool/testcases/stubby.status.001.sh b/ctdb/tests/tool/testcases/stubby.status.001.sh new file mode 100755 index 0000000000..74cdc39c22 --- /dev/null +++ b/ctdb/tests/tool/testcases/stubby.status.001.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, 3 nodes, all ok" + +required_result 0 <<EOF +Number of nodes:3 +pnn:0 192.168.20.41 OK (THIS NODE) +pnn:1 192.168.20.42 OK +pnn:2 192.168.20.43 OK +Generation:654321 +Size:3 +hash:0 lmaster:0 +hash:1 lmaster:1 +hash:2 lmaster:2 +Recovery mode:NORMAL (0) +Recovery master:0 +EOF + +simple_test all <<EOF +NODEMAP +0 192.168.20.41 0x0 CURRENT RECMASTER +1 192.168.20.42 0x0 +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF diff --git a/ctdb/tests/tool/testcases/stubby.status.002.sh b/ctdb/tests/tool/testcases/stubby.status.002.sh new file mode 100755 index 0000000000..3963691d95 --- /dev/null +++ b/ctdb/tests/tool/testcases/stubby.status.002.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +. "${TESTS_SUBDIR}/common.sh" + +define_test "all, 3 nodes, 1 unhealthy" + +required_result 0 <<EOF +Number of nodes:3 +pnn:0 192.168.20.41 UNHEALTHY +pnn:1 192.168.20.42 OK (THIS NODE) +pnn:2 192.168.20.43 OK +Generation:654321 +Size:3 +hash:0 lmaster:0 +hash:1 lmaster:1 +hash:2 lmaster:2 +Recovery mode:NORMAL (0) +Recovery master:1 +EOF + +simple_test all <<EOF +NODEMAP +0 192.168.20.41 0x2 +1 192.168.20.42 0x0 CURRENT RECMASTER +2 192.168.20.43 0x0 + +IFACES +:Name:LinkStatus:References: +:eth2:1:2: +:eth1:1:4: + +VNNMAP +654321 +0 +1 +2 +EOF |