summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/onnode/scripts/local.sh
blob: 35fd013540f3ed1321aa91877f982b29c0fdd9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Hey Emacs, this is a -*- shell-script -*- !!!  :-)

# Set indirectly by run_tests at top level.
unset CTDB_NODES_SOCKETS

# Default to just "onnode".
: ${ONNODE:=onnode}

# Augment PATH with relevant stubs/ directories.

if [ -d "${TEST_SUBDIR}/stubs" ] ; then
    PATH="${TEST_SUBDIR}/stubs:$PATH"
fi

# Find CTDB nodes file.
if [ -z "$CTDB_NODES_FILE" ] ; then
    if [ -r "${TEST_SUBDIR}/nodes" ] ; then
	CTDB_NODES_FILE="${TEST_SUBDIR}/nodes"
    else
	CTDB_NODES_FILE="${CTDB_BASE:-/etc/ctdb}/nodes"
    fi
fi

export CTDB_NODES_FILE

export ONNODE_TESTS_VAR_DIR="${TEST_SUBDIR}/var"
mkdir -p "$ONNODE_TESTS_VAR_DIR"

if [ -z "$CTDB_BASE" ] ; then
    export CTDB_BASE=$(dirname "$CTDB_NODES_FILE")
fi

define_test ()
{
    _f=$(basename "$0")

    echo "$_f $1 - $2"
}

# Set output for ctdb command.  Option 1st argument is return code.
ctdb_set_output ()
{
    _out="$ONNODE_TESTS_VAR_DIR/ctdb.out"
    cat >"$_out"

    _rc="$ONNODE_TESTS_VAR_DIR/ctdb.rc"
    echo "${1:-0}" >"$_rc"

    trap "rm -f $_out $_rc" 0
}

_extra_header ()
{
    cat <<EOF
CTDB_NODES_FILE="${CTDB_NODES_FILE}"
CTDB_BASE="$CTDB_BASE"
$(which ctdb)

EOF
}

simple_test ()
{
    _sort="cat"
    if [ "$1" = "-s" ] ; then
	shift
	_sort="sort"
    fi

    if $TEST_COMMAND_TRACE ; then
	_onnode=$(which "$1") ; shift
	_out=$(bash -x "$_onnode" "$@" 2>&1)
    else
	_out=$("$@" 2>&1)
    fi
    _rc=$?
    _out=$(echo "$_out" | $_sort )

    # Can't do this inline or it affects return code
    _extra_header="$(_extra_header)"

    # Get the return code back into $?
    (exit $_rc)

    result_check "$_extra_header"
}