ctdb-tests: Add new test functions for running commands on nodes
authorMartin Schwenke <martin@meltin.net>
Mon, 12 Aug 2019 11:01:20 +0000 (21:01 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 4 Oct 2019 09:41:28 +0000 (09:41 +0000)
* ctdb_onnode()
* testprog_onnode()
* function_onnode()

These encapsulate familiar patterns found when running
try_command_on_node().  The new function names are more concise and
encourage more readable tests.  Test writers can do less thinking
about the subtleties of running different types of commands on nodes.
For example, these functions ensure that $CTDB and $VALGRIND are used
in the correct contexts.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/scripts/integration.bash

index 52830ff9703043eee946f4dc446d56ff5dd20e94..55b5deb70235996d5c307e8f00f6609122ba0ed7 100644 (file)
@@ -133,6 +133,46 @@ try_command_on_node ()
     fi
 }
 
+_run_onnode ()
+{
+       local thing="$1"
+       shift
+
+       local options nodespec
+
+       while : ; do
+               case "$1" in
+               -*)
+                       options="${options}${options:+ }${1}"
+                       shift
+                       ;;
+               *)
+                       nodespec="$1"
+                       shift
+                       break
+               esac
+       done
+
+       # shellcheck disable=SC2086
+       # $options can be multi-word
+       try_command_on_node $options "$nodespec" "${thing} $*"
+}
+
+ctdb_onnode ()
+{
+       _run_onnode "$CTDB" "$@"
+}
+
+testprog_onnode ()
+{
+       _run_onnode "${CTDB_TEST_WRAPPER} ${VALGRIND}" "$@"
+}
+
+function_onnode ()
+{
+       _run_onnode "${CTDB_TEST_WRAPPER}" "$@"
+}
+
 sanity_check_output ()
 {
     local min_lines="$1"