ctdb-tests: Conditionally use temporary config file for local daemons
authorMartin Schwenke <martin@meltin.net>
Mon, 29 Aug 2016 06:49:07 +0000 (16:49 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 1 Sep 2016 11:30:10 +0000 (13:30 +0200)
If there's configuration in the environment then daemons_start()
should use a temporary configuration file with that appended.

This means that global overrides don't (harmlessly) build up in the
configuration file during each test and individual tests can override
configuration when calling daemons_start() directly.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12180

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

index 022bbf8880a088db151189e3b0d96514e3ccdae1..fb1e7e1cd5f6b7887253680151dfebcf24a5565e 100644 (file)
@@ -123,9 +123,25 @@ daemons_start ()
        local pidfile="${TEST_VAR_DIR}/ctdbd.${pnn}.pid"
        local conf="${TEST_VAR_DIR}/ctdbd.${pnn}.conf"
 
+       # If there is any CTDB configuration in the environment then
+       # append it to the regular configuration in a temporary
+       # configuration file and use it just this once.
+       local tmp_conf=""
+       local env_conf=$(config_from_environment)
+       if [ -n "$env_conf" ] ; then
+               tmp_conf=$(mktemp --tmpdir="$TEST_VAR_DIR")
+               cat "$conf" >"$tmp_conf"
+               echo "$env_conf" >>"$tmp_conf"
+               conf="$tmp_conf"
+       fi
+
        CTDBD="${VALGRIND} ctdbd --sloppy-start --nopublicipcheck" \
             CTDBD_CONF="$conf" \
             ctdbd_wrapper "$pidfile" start
+
+       if [ -n "$tmp_conf" ] ; then
+               rm -f "$tmp_conf"
+       fi
     done
 }