diff options
| author | Martin Schwenke <martin@meltin.net> | 2008-11-24 17:47:09 +1100 |
|---|---|---|
| committer | Martin Schwenke <martin@meltin.net> | 2008-11-24 17:47:09 +1100 |
| commit | 5d50f5a91c4ec5bd5dcfee9bb48e2587df077949 (patch) | |
| tree | 6bfc215fef9c9d909a1d4537bdd9cb6dcc56eff9 /ctdb/tests/scripts | |
| parent | 0e9f8c4a6fc35b8889bca04b2de5b45314499dd2 (diff) | |
| download | samba-5d50f5a91c4ec5bd5dcfee9bb48e2587df077949.tar.gz samba-5d50f5a91c4ec5bd5dcfee9bb48e2587df077949.tar.xz samba-5d50f5a91c4ec5bd5dcfee9bb48e2587df077949.zip | |
New test 09_ctdb_ping.sh. Add documentation and command-line
processing to all tests. New script ctdb_test_env sets up environment
for tests, is now sourced by run_tests, and can also take a test on
the command-line, complete with options. Various cleanups and
improvements. Document tests that have been properly implemented in
ctdbd.sh.
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 826e85fe5291067b8d0b9c22918d63024aa6141c)
Diffstat (limited to 'ctdb/tests/scripts')
| -rwxr-xr-x | ctdb/tests/scripts/ctdb_test_env | 27 | ||||
| -rw-r--r-- | ctdb/tests/scripts/ctdb_test_functions.bash | 123 | ||||
| -rwxr-xr-x | ctdb/tests/scripts/run_tests | 31 |
3 files changed, 124 insertions, 57 deletions
diff --git a/ctdb/tests/scripts/ctdb_test_env b/ctdb/tests/scripts/ctdb_test_env new file mode 100755 index 0000000000..4fa3e30f79 --- /dev/null +++ b/ctdb/tests/scripts/ctdb_test_env @@ -0,0 +1,27 @@ +#!/bin/bash + +export CTDB_DIR=$(cd $(dirname $(dirname $(dirname $0))) ; pwd) +var_dir=$CTDB_DIR/tests/var + +export CTDB_NUM_NODES=3 + +###################################################################### + +if [ ! -n "$CTDB_TEST_REAL_CLUSTER" ] ; then + export CTDB_NODES_SOCKETS="" + for i in $(seq 1 $CTDB_NUM_NODES) ; do + CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${var_dir}/sock.${i}" + done +fi + +###################################################################### + +ctdb_bin_dir=$CTDB_DIR/bin +ctdb_tools_dir=$CTDB_DIR/tools +ctdb_test_scripts_dir=$(cd $(dirname $0) ; pwd) + +PATH="${ctdb_test_scripts_dir}:${ctdb_bin_dir}:${ctdb_tools_dir}:${PATH}" + +export TEST_WRAP="${ctdb_test_scripts_dir}/test_wrap" + +"$@" diff --git a/ctdb/tests/scripts/ctdb_test_functions.bash b/ctdb/tests/scripts/ctdb_test_functions.bash index 3713c98e49..bc660dbc23 100644 --- a/ctdb/tests/scripts/ctdb_test_functions.bash +++ b/ctdb/tests/scripts/ctdb_test_functions.bash @@ -10,7 +10,7 @@ fail () #. /root/SOFS/autosofs/scripts/tester.bash -test_begin () +ctdb_test_begin () { local name="$1" @@ -22,7 +22,7 @@ test_begin () echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--" } -test_end () +ctdb_test_end () { local name="$1" ; shift local status="$1" ; shift @@ -50,33 +50,102 @@ test_end () } - -test_exit() { +test_exit () +{ exit $(($testfailures+0)) } -test_run () +ctdb_test_exit () +{ + if ! onnode 0 $TEST_WRAP cluster_is_healthy ; then + echo "Restarting ctdb on all nodes to get back into known state..." + restart_ctdb + fi + + test_exit +} + +ctdb_test_run () { local name="$1" ; shift [ -n "$1" ] || set -- "$name" - test_begin "$name" + ctdb_test_begin "$name" local status=0 "$@" || status=$? - test_end "$name" "$status" "$*" + ctdb_test_end "$name" "$status" "$*" return $status } +ctdb_test_usage() +{ + local status=${1:-2} + + cat <<EOF +Usage: $0 [option] + +Options: + -h, --help show this screen. + -v, --version show test case version. + --category show the test category (ACL, CTDB, Samba ...). + -d, --description show test case description. + --summary show short test case summary. +EOF + + exit $status +} + +ctdb_test_version () +{ + [ -n "$CTDB_DIR" ] || fail "Can not determine version." + + (cd "$CTDB_DIR" && git describe) +} + +ctdb_test_cmd_options() +{ + [ -n "$1" ] || return 0 + + case "$1" in + -h|--help) ctdb_test_usage 0 ;; + -v|--version) ctdb_test_version ;; + --category) echo "CTDB" ;; + -d|--description) test_info ;; + --summary) test_info | head -1 ;; + *) + echo "Error: Unknown parameter = $1" + echo + ctdb_test_usage 2 + ;; + esac + + exit 0 +} + +ctdb_test_init () +{ + scriptname=$(basename "$0") + testfailures=0 + + ctdb_test_cmd_options $@ +} + ######################################## # Sets: $out try_command_on_node () { local nodespec="$1" ; shift + + local verbose=false + if [ "$nodespec" = "-v" ] ; then + verbose=true + nodespec="$1" ; shift + fi local cmd="$*" out=$(onnode -q "$nodespec" "$cmd" 2>&1) || { @@ -85,12 +154,17 @@ try_command_on_node () echo "$out" exit 1 } + + if $verbose ; then + echo "Output of \"$cmd\":" + echo "$out" + fi } sanity_check_output () { local min_lines="$1" - local regexp="$2" # Should be anchored to match whole lines. + local regexp="$2" # Should be anchored as necessary. local output="$3" local ret=0 @@ -109,7 +183,7 @@ sanity_check_output () # Note that this is reversed. if [ $status -eq 0 ] ; then echo "BAD: unexpected lines in output:" - echo "$unexpected" + echo "$unexpected" | cat -A ret=1 else echo "Output lines look OK" @@ -126,7 +200,7 @@ wait_until () { local timeout="$1" ; shift # "$@" is the command... - echo -n "|${timeout}|" + echo -n "<${timeout}|" while [ $timeout -gt 0 ] ; do if "$@" ; then echo '|' @@ -145,7 +219,7 @@ wait_until () sleep_for () { - echo -n "|${1}|" + echo -n "=${1}|" for i in $(seq 1 $1) ; do echo -n '.' sleep 1 @@ -198,18 +272,12 @@ node_has_status () local bits case "$status" in - banned) - bits="?:1:?:?" - ;; - unbanned) - bits="?:0:?:?" - ;; - disabled) - bits="?:?:1:?" - ;; - enabled) - bits="?:?:0:?" - ;; + (disconnected) bits="1:?:?:?" ;; + (connected) bits="0:?:?:?" ;; + (banned) bits="?:1:?:?" ;; + (unbanned) bits="?:0:?:?" ;; + (disabled) bits="?:?:1:?" ;; + (enabled) bits="?:?:0:?" ;; *) echo "node_has_status: unknown status \"$status\"" return 1 @@ -366,12 +434,3 @@ restart_ctdb () echo "ctdb is ready" } -ctdb_test_exit () -{ - if ! onnode 0 $TEST_WRAP cluster_is_healthy ; then - echo "Restarting ctdb on all nodes to get back into known state..." - restart_ctdb - fi - - test_exit -} diff --git a/ctdb/tests/scripts/run_tests b/ctdb/tests/scripts/run_tests index 9827ebed63..9779bf336d 100755 --- a/ctdb/tests/scripts/run_tests +++ b/ctdb/tests/scripts/run_tests @@ -1,28 +1,9 @@ #!/bin/bash -export CTDB_DIR=$(cd $(dirname $(dirname $(dirname $0))) ; pwd) -var_dir=$CTDB_DIR/tests/var - -export CTDB_NUM_NODES=3 - -###################################################################### - -if [ ! -n "$CTDB_TEST_REAL_CLUSTER" ] ; then - export CTDB_NODES_SOCKETS="" - for i in $(seq 1 $CTDB_NUM_NODES) ; do - CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${var_dir}/sock.${i}" - done -fi - -###################################################################### - -ctdb_bin_dir=$CTDB_DIR/bin -ctdb_tools_dir=$CTDB_DIR/tools -ctdb_test_scripts_dir=$(cd $(dirname $0) ; pwd) - -PATH="${ctdb_test_scripts_dir}:${ctdb_bin_dir}:${ctdb_tools_dir}:${PATH}" - -export TEST_WRAP="${ctdb_test_scripts_dir}/test_wrap" +# The ability of ctdb_test_env to take tests on the command-line is +# nice, but here we need to hack around it with that colon to reset +# the arguments that it sees. +. $(dirname $0)/ctdb_test_env : . ctdb_test_functions.bash @@ -53,8 +34,8 @@ done ###################################################################### for f; do - [ -x $f ] || fail "test $f is not executable" - test_run "$f" + [ -x $f ] || fail "test \"$f\" is not executable" + ctdb_test_run "$f" done test_exit |
