~ubuntu-branches/ubuntu/vivid/ctdb/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/onnode/common.sh

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2011-11-06 15:18:59 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20111106151859-41lblk8ml4es7ra3
Tags: 1.11+git20111102-1
* New upstream release
  - removed 92-apache-service-enable.diff: integrated 
  - removed 99-fix-broken-readdir-test.diff: integrated
* d/rules, d/control, d/compat:
  - converted to dh (% target and dh_auto_*)
  - moved to compat level 9 (buildeps upgraded)
  - dh9 enabled hardening build flags
  - added hardening=+bindnow
  - dh9 enabled multiarch
    + Don't use /use/lib64 on ppc64 (Closes: #644907)
    + libctdb-dev is Multi-Arch: same
    + removed 10_no-lib64.diff: not needed with multiarch
* ctdb.init:
  - removed gettext support
  - synced with upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Hey Emacs, this is a -*- shell-script -*- !!!  :-)
 
2
 
 
3
# Set indirectly by run_tests at top level.
 
4
unset CTDB_NODES_SOCKETS
 
5
 
 
6
# Default to just "onnode".
 
7
: ${ONNODE:=onnode}
 
8
 
 
9
# Augment PATH with relevant stubs/ directories.
 
10
 
 
11
if [ -d "${ONNODE_TESTS_DIR}/stubs" ] ; then
 
12
    PATH="${ONNODE_TESTS_DIR}/stubs:$PATH"
 
13
fi
 
14
 
 
15
export ONNODE_TESTCASE_DIR=$(dirname "$0")
 
16
if [ $(basename "$ONNODE_TESTCASE_DIR") = "onnode" ] ; then
 
17
    # Just a test script, no testcase subdirectory.
 
18
    ONNODE_TESTCASE_DIR="$ONNODE_TESTS_DIR"
 
19
else
 
20
    if [ -d "${ONNODE_TESTCASE_DIR}/stubs" ] ; then
 
21
        PATH="${ONNODE_TESTCASE_DIR}/stubs:$PATH"
 
22
    fi
 
23
fi
 
24
 
 
25
# Find CTDB nodes file.
 
26
if [ -z "$CTDB_NODES_FILE" ] ; then
 
27
    if [ -r "${ONNODE_TESTCASE_DIR}/nodes" ] ; then
 
28
        CTDB_NODES_FILE="${ONNODE_TESTCASE_DIR}/nodes"
 
29
    elif [ -r "${ONNODE_TESTS_DIR}/nodes" ] ; then
 
30
        CTDB_NODES_FILE="${ONNODE_TESTS_DIR}/nodes"
 
31
    else
 
32
        CTDB_NODES_FILE="${CTDB_BASE:-/etc/ctdb}/nodes"
 
33
    fi
 
34
fi
 
35
 
 
36
export CTDB_NODES_FILE
 
37
 
 
38
export ONNODE_TESTS_VAR_DIR="${ONNODE_TESTS_DIR}/var"
 
39
mkdir -p "$ONNODE_TESTS_VAR_DIR"
 
40
 
 
41
if [ -z "$CTDB_BASE" ] ; then
 
42
    export CTDB_BASE=$(dirname "$CTDB_NODES_FILE")
 
43
fi
 
44
 
 
45
define_test ()
 
46
{
 
47
    _f="$0"
 
48
    _f="${_f#./}"  # strip leading ./
 
49
    _f="${_f%%/*}" # if subdir, strip off file
 
50
    _f="${_f%.sh}" # strip off .sh suffix if any
 
51
 
 
52
    echo "$_f $1 - $2"
 
53
}
 
54
 
 
55
# Set output for ctdb command.  Option 1st argument is return code.
 
56
ctdb_set_output ()
 
57
{
 
58
    _out="$ONNODE_TESTS_VAR_DIR/ctdb.out"
 
59
    cat >"$_out"
 
60
 
 
61
    _rc="$ONNODE_TESTS_VAR_DIR/ctdb.rc"
 
62
    echo "${1:-0}" >"$_rc"
 
63
 
 
64
    trap "rm -f $_out $_rc" 0
 
65
}
 
66
 
 
67
required_result ()
 
68
{
 
69
    required_rc="${1:-0}"
 
70
    required_output=$(cat)
 
71
}
 
72
 
 
73
simple_test ()
 
74
{
 
75
    _sort="cat"
 
76
    if [ "$1" = "-s" ] ; then
 
77
        shift
 
78
        _sort="sort"
 
79
    fi
 
80
    _out=$("$@" 2>&1)
 
81
    _rc=$?
 
82
    _out=$(echo "$_out" | $_sort )
 
83
 
 
84
    if [ "$_out" = "$required_output" -a $_rc = $required_rc ] ; then
 
85
        echo "PASSED"
 
86
    else
 
87
        cat <<EOF
 
88
CTDB_NODES_FILE="${CTDB_NODES_FILE}"
 
89
CTDB_BASE="$CTDB_BASE"
 
90
$(which ctdb)
 
91
 
 
92
##################################################
 
93
Required output (Exit status: ${required_rc}):
 
94
##################################################
 
95
$required_output
 
96
##################################################
 
97
Actual output (Exit status: ${_rc}):
 
98
##################################################
 
99
$_out
 
100
EOF
 
101
        return 1
 
102
    fi
 
103
}