diff options
Diffstat (limited to '')
47 files changed, 1103 insertions, 0 deletions
diff --git a/ctdb/tests/UNIT/eventd/README b/ctdb/tests/UNIT/eventd/README new file mode 100644 index 0000000..742b2c5 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/README @@ -0,0 +1 @@ +Unit tests for event daemon diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/ctdb.conf b/ctdb/tests/UNIT/eventd/etc-ctdb/ctdb.conf new file mode 100644 index 0000000..59bc9bb --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/ctdb.conf @@ -0,0 +1,6 @@ +[logging] + location = file: + log level = DEBUG + +[event] + debug script = debug-script.sh diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/debug-script.sh b/ctdb/tests/UNIT/eventd/etc-ctdb/debug-script.sh new file mode 100755 index 0000000..d54de7e --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/debug-script.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +log="${CTDB_BASE}/debug_script.log" + +case "$2" in +"timeout") + echo "args: $*" > "$log" + ;; + +"verbosetimeout") + (ctdb-event status random $2) > "$log" + ;; + +"verbosetimeout2") + exec > "$log" 2>&1 + ctdb-event status random $2 + ;; + +*) + ;; + +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/data/03.notalink.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/data/03.notalink.script new file mode 100644 index 0000000..039e4d0 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/data/03.notalink.script @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/data/README b/ctdb/tests/UNIT/eventd/etc-ctdb/events/data/README new file mode 100644 index 0000000..f38a189 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/data/README @@ -0,0 +1 @@ +initially empty event scripts directory diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/empty/README b/ctdb/tests/UNIT/eventd/etc-ctdb/events/empty/README new file mode 100644 index 0000000..a5614a9 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/empty/README @@ -0,0 +1 @@ +empty event scripts directory diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/01.test.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/01.test.script new file mode 100755 index 0000000..d16f0de --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/01.test.script @@ -0,0 +1,11 @@ +#!/bin/sh + +case "$1" in +"startup") sleep 5; exit 0 ;; +"monitor") sleep 5; exit 0 ;; +"event1") sleep 1; exit 0 ;; +"event2") sleep 1; exit 0 ;; +"event3") exit 3 ;; +"timeout1") sleep 99 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/02.test.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/02.test.script new file mode 100755 index 0000000..5c841aa --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/02.test.script @@ -0,0 +1,9 @@ +#!/bin/sh + +case "$1" in +"monitor") sleep 1; exit 0 ;; +"event1") exit 1 ;; +"event2") sleep 1; exit 0 ;; +"timeout2") sleep 99 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/03.test.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/03.test.script new file mode 100755 index 0000000..b48b68c --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/multi/03.test.script @@ -0,0 +1,9 @@ +#!/bin/sh + +case "$1" in +"monitor") sleep 1; exit 0 ;; +"event1") sleep 1; exit 0 ;; +"event2") exit 2 ;; +"timeout3") sleep 99 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/01.disabled.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/01.disabled.script new file mode 100644 index 0000000..c52d3c2 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/01.disabled.script @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 0 diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script new file mode 100755 index 0000000..f25e724 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/02.enabled.script @@ -0,0 +1,12 @@ +#!/bin/sh + +case "$1" in +"monitor") exit 0 ;; +"failure") exit 1 ;; +"timeout") sleep 99 ;; +"verbose") echo "Running event $1" ; exit 0 ;; +"verbosefailure") echo "args: $*"; exit 1 ;; +"verbosetimeout") echo "Sleeping for 99 seconds"; sleep 99 ;; +"verbosetimeout2") echo "Sleeping for 99 seconds"; sleep 99 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/README.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/README.script new file mode 100644 index 0000000..9086add --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/README.script @@ -0,0 +1 @@ +Random collection of files and event scripts diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/a.script b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/a.script new file mode 100755 index 0000000..2bb8d86 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/events/random/a.script @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 1 diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/data/01.dummy.script b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/data/01.dummy.script new file mode 100755 index 0000000..9c56f5b --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/data/01.dummy.script @@ -0,0 +1,6 @@ +#!/bin/sh + +case "$1" in +"failure") exit 1 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/data/02.disabled.script b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/data/02.disabled.script new file mode 100755 index 0000000..9c56f5b --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/data/02.disabled.script @@ -0,0 +1,6 @@ +#!/bin/sh + +case "$1" in +"failure") exit 1 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/empty/README b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/empty/README new file mode 100644 index 0000000..a5614a9 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/empty/README @@ -0,0 +1 @@ +empty event scripts directory diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/01.disabled.script b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/01.disabled.script new file mode 100644 index 0000000..c52d3c2 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/01.disabled.script @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 0 diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/02.enabled.script b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/02.enabled.script new file mode 100755 index 0000000..f25e724 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/02.enabled.script @@ -0,0 +1,12 @@ +#!/bin/sh + +case "$1" in +"monitor") exit 0 ;; +"failure") exit 1 ;; +"timeout") sleep 99 ;; +"verbose") echo "Running event $1" ; exit 0 ;; +"verbosefailure") echo "args: $*"; exit 1 ;; +"verbosetimeout") echo "Sleeping for 99 seconds"; sleep 99 ;; +"verbosetimeout2") echo "Sleeping for 99 seconds"; sleep 99 ;; +*) exit 0 ;; +esac diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/README.script b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/README.script new file mode 100644 index 0000000..9086add --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/README.script @@ -0,0 +1 @@ +Random collection of files and event scripts diff --git a/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/a.script b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/a.script new file mode 100755 index 0000000..2bb8d86 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/etc-ctdb/share/events/random/a.script @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 1 diff --git a/ctdb/tests/UNIT/eventd/eventd_001.sh b/ctdb/tests/UNIT/eventd/eventd_001.sh new file mode 100755 index 0000000..7d4ee9e --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_001.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "non-existent eventscript directory" + +setup_eventd + +required_error ENOENT <<EOF +Event dir for foobar does not exist +EOF +simple_test status foobar monitor + +required_error ENOENT <<EOF +Event dir for foobar does not exist +EOF +simple_test run 10 foobar monitor + +required_error ENOENT <<EOF +Script 01.test does not exist in foobar +EOF +simple_test script enable foobar 01.test + +required_error ENOENT <<EOF +Command script list finished with result=$(errcode ENOENT) +EOF +simple_test script list foobar diff --git a/ctdb/tests/UNIT/eventd/eventd_002.sh b/ctdb/tests/UNIT/eventd/eventd_002.sh new file mode 100755 index 0000000..f964adf --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_002.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "empty eventscript directory" + +setup_eventd + +required_error EINVAL <<EOF +Event monitor has never run in empty +EOF +simple_test status empty monitor + +ok_null +simple_test run 10 empty monitor + +ok_null +simple_test status empty monitor + +ok_null +simple_test script list empty diff --git a/ctdb/tests/UNIT/eventd/eventd_003.sh b/ctdb/tests/UNIT/eventd/eventd_003.sh new file mode 100755 index 0000000..8625057 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_003.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "eventscript directory with random files" + +setup_eventd + +required_error EINVAL <<EOF +Script README is invalid in random +EOF +simple_test script enable random README + +required_error EINVAL <<EOF +Script a is invalid in random +EOF +simple_test script disable random a + +required_error ENOENT <<EOF +Script 00.foobar does not exist in random +EOF +simple_test script enable random 00.foobar + +required_error EINVAL <<EOF +Event monitor has never run in random +EOF +simple_test status random monitor + +ok_null +simple_test run 10 random monitor + +ok <<EOF +01.disabled DISABLED +02.enabled OK DURATION DATETIME +EOF +simple_test status random monitor + +ok <<EOF + 01.disabled + 02.enabled + + 01.disabled +* 02.enabled +EOF +simple_test script list random diff --git a/ctdb/tests/UNIT/eventd/eventd_004.sh b/ctdb/tests/UNIT/eventd/eventd_004.sh new file mode 100755 index 0000000..fe69d1d --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_004.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "disabled event script" + +setup_eventd + +ok_null +simple_test script disable random 01.disabled + +ok_null +simple_test script disable random 01.disabled + +ok_null +simple_test script enable random 01.disabled + +ok_null +simple_test script disable random 01.disabled + +required_error EINVAL <<EOF +Event monitor has never run in random +EOF +simple_test status random monitor + +ok_null +simple_test run 10 random monitor + +ok <<EOF +01.disabled DISABLED +02.enabled OK DURATION DATETIME +EOF +simple_test status random monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_005.sh b/ctdb/tests/UNIT/eventd/eventd_005.sh new file mode 100755 index 0000000..28f4935 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_005.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "enabled event script" + +setup_eventd + +ok_null +simple_test script enable random 02.enabled + +ok_null +simple_test script enable random 02.enabled + +ok_null +simple_test run 10 random monitor + +ok <<EOF +01.disabled DISABLED +02.enabled OK DURATION DATETIME +EOF +simple_test status random monitor + +ok_null +simple_test script enable random 01.disabled + +ok_null +simple_test run 10 random monitor + +ok <<EOF +01.disabled OK DURATION DATETIME +02.enabled OK DURATION DATETIME +EOF +simple_test status random monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_006.sh b/ctdb/tests/UNIT/eventd/eventd_006.sh new file mode 100755 index 0000000..a7a2d41 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_006.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "failing event script" + +setup_eventd + +required_error ENOEXEC <<EOF +Event failure in random failed +EOF +simple_test run 10 random failure + +required_result 1 <<EOF +01.disabled DISABLED +02.enabled ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status random failure diff --git a/ctdb/tests/UNIT/eventd/eventd_007.sh b/ctdb/tests/UNIT/eventd/eventd_007.sh new file mode 100755 index 0000000..e8ee403 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_007.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "timing out event script" + +setup_eventd + +required_error ETIMEDOUT <<EOF +Event timeout in random timed out +EOF +simple_test run 5 random timeout + +required_error ETIMEDOUT <<EOF +01.disabled DISABLED +02.enabled TIMEDOUT DATETIME + OUTPUT: +EOF +simple_test status random timeout diff --git a/ctdb/tests/UNIT/eventd/eventd_008.sh b/ctdb/tests/UNIT/eventd/eventd_008.sh new file mode 100755 index 0000000..c394f61 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_008.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "capture event script output" + +setup_eventd + +required_result 8 <<EOF +Event verbosefailure in random failed +EOF +simple_test run 10 random verbosefailure with some args + +required_result 1 <<EOF +01.disabled DISABLED +02.enabled ERROR DURATION DATETIME + OUTPUT: args: verbosefailure with some args +EOF +simple_test status random verbosefailure diff --git a/ctdb/tests/UNIT/eventd/eventd_009.sh b/ctdb/tests/UNIT/eventd/eventd_009.sh new file mode 100755 index 0000000..39e5cd6 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_009.sh @@ -0,0 +1,155 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "eventscript directory with links" + +setup_eventd + +ok <<EOF + 01.dummy + 02.disabled + + 03.notalink +EOF +simple_test script list data + +# Should be a no-op +ok_null +simple_test script disable data 03.notalink + +ok_null +simple_test run 10 data failure + +ok_null +simple_test script enable data 01.dummy + +required_result 8 <<EOF +Event failure in data failed +EOF +simple_test run 10 data failure + +ok <<EOF +* 01.dummy + 02.disabled + + 03.notalink +EOF +simple_test script list data + +required_result 1 <<EOF +01.dummy ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status data failure + +ok_null +simple_test run 10 data monitor + +ok <<EOF +01.dummy OK DURATION DATETIME +03.notalink DISABLED +EOF +simple_test status data monitor + +ok_null +simple_test script enable data 03.notalink + +ok <<EOF +* 01.dummy + 02.disabled + +* 03.notalink +EOF +simple_test script list data + +# Local/3rd-party link, not enabled +touch "${CTDB_BASE}/foo" +chmod 644 "${CTDB_BASE}/foo" +abs_base=$(cd "$CTDB_BASE" && echo "$PWD") +ln -s "${abs_base}/foo" "${CTDB_BASE}/events/data/04.locallink.script" + +ok <<EOF +* 01.dummy + 02.disabled + +* 03.notalink + 04.locallink +EOF +simple_test script list data + +ok_null +simple_test script enable data 04.locallink + +required_result 1 "" +unit_test test -x "${CTDB_BASE}/foo" + +ok_null +simple_test script disable data 04.locallink + +ok_null +unit_test test -f "${CTDB_BASE}/foo" + +ok <<EOF +* 01.dummy + 02.disabled + +* 03.notalink +EOF +simple_test script list data + +# Local/3rd-party link, enabled +chmod +x "${CTDB_BASE}/foo" +ln -s "${abs_base}/foo" "${CTDB_BASE}/events/data/04.locallink.script" + +ok <<EOF +* 01.dummy + 02.disabled + +* 03.notalink +* 04.locallink +EOF +simple_test script list data + +ok_null +simple_test script disable data 01.dummy + +ok_null +simple_test script disable data 04.locallink + +ok_null +unit_test test -f "${CTDB_BASE}/foo" + +ok <<EOF + 01.dummy + 02.disabled + +* 03.notalink +EOF +simple_test script list data + +ok_null +simple_test run 10 data failure + +# Local/3rd-party link, dangling +ln -s "${CTDB_BASE}/doesnotexist" "${CTDB_BASE}/events/data/04.locallink.script" + +ok <<EOF + 01.dummy + 02.disabled + +* 03.notalink + 04.locallink +EOF +simple_test script list data + +ok_null +simple_test script disable data 04.locallink + +ok <<EOF + 01.dummy + 02.disabled + +* 03.notalink +EOF +simple_test script list data diff --git a/ctdb/tests/UNIT/eventd/eventd_011.sh b/ctdb/tests/UNIT/eventd/eventd_011.sh new file mode 100755 index 0000000..ce75613 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_011.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "multiple events" + +setup_eventd + +ok_null +simple_test run 10 random monitor + +ok <<EOF +01.disabled DISABLED +02.enabled OK DURATION DATETIME +EOF +simple_test status random monitor + +required_error ENOEXEC <<EOF +Event failure in random failed +EOF +simple_test run 10 random failure + +required_result 1 <<EOF +01.disabled DISABLED +02.enabled ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status random failure + +required_error ENOEXEC <<EOF +Event verbosefailure in random failed +EOF +simple_test run 10 random verbosefailure + +required_result 1 <<EOF +01.disabled DISABLED +02.enabled ERROR DURATION DATETIME + OUTPUT: args: verbosefailure +EOF +simple_test status random verbosefailure diff --git a/ctdb/tests/UNIT/eventd/eventd_012.sh b/ctdb/tests/UNIT/eventd/eventd_012.sh new file mode 100755 index 0000000..5e6857b --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_012.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "cancel new monitor event" + +setup_eventd + +ok_null +simple_test_background run 10 multi startup + +required_error ECANCELED <<EOF +Event monitor in multi got cancelled +EOF +simple_test run 10 multi monitor + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi startup + +required_error EINVAL <<EOF +Event monitor has never run in multi +EOF +simple_test status multi monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_013.sh b/ctdb/tests/UNIT/eventd/eventd_013.sh new file mode 100755 index 0000000..5bbb4dc --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_013.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "cancel running monitor event" + +setup_eventd + +required_error ECANCELED <<EOF +Event monitor in multi got cancelled +EOF +simple_test_background run 10 multi monitor + +ok_null +simple_test run 10 multi startup + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi startup + +required_error EINVAL <<EOF +Event monitor has never run in multi +EOF +simple_test status multi monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_014.sh b/ctdb/tests/UNIT/eventd/eventd_014.sh new file mode 100755 index 0000000..63b34b4 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_014.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "queue events" + +setup_eventd + +ok_null +simple_test_background run 10 multi queue1 + +ok_null +simple_test run 10 multi queue2 + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi queue1 + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi queue2 diff --git a/ctdb/tests/UNIT/eventd/eventd_021.sh b/ctdb/tests/UNIT/eventd/eventd_021.sh new file mode 100755 index 0000000..935373a --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_021.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "debug script" + +setup_eventd + +result_filter () +{ + _pid="[0-9][0-9]*" + sed -e "s| ${_pid}| PID|" +} + +required_error ETIMEDOUT <<EOF +Event timeout in random timed out +EOF +simple_test run 5 random timeout + +# wait for debug hung script +sleep 5 + +ok <<EOF +args: PID timeout +EOF +unit_test cat "${CTDB_BASE}/debug_script.log" diff --git a/ctdb/tests/UNIT/eventd/eventd_022.sh b/ctdb/tests/UNIT/eventd/eventd_022.sh new file mode 100755 index 0000000..3f1c4f6 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_022.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "status output in debug script" + +setup_eventd + +required_error ETIMEDOUT <<EOF +Event verbosetimeout in random timed out +EOF +simple_test run 5 random verbosetimeout + +# wait for debug hung script +sleep 5 + +ok <<EOF +01.disabled DISABLED +02.enabled TIMEDOUT DATETIME + OUTPUT: Sleeping for 99 seconds +EOF +unit_test cat "${CTDB_BASE}/debug_script.log" diff --git a/ctdb/tests/UNIT/eventd/eventd_023.sh b/ctdb/tests/UNIT/eventd/eventd_023.sh new file mode 100755 index 0000000..8914218 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_023.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "redirected status output in debug script" + +setup_eventd + +required_error ETIMEDOUT <<EOF +Event verbosetimeout2 in random timed out +EOF +simple_test run 5 random verbosetimeout2 + +# wait for debug hung script +sleep 5 + +ok <<EOF +01.disabled DISABLED +02.enabled TIMEDOUT DATETIME + OUTPUT: Sleeping for 99 seconds +EOF +unit_test cat "${CTDB_BASE}/debug_script.log" diff --git a/ctdb/tests/UNIT/eventd/eventd_024.sh b/ctdb/tests/UNIT/eventd/eventd_024.sh new file mode 100755 index 0000000..db68d01 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_024.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "process terminated after debug" + +setup_eventd + +result_filter() +{ + _pid="[0-9][0-9]*" + sed -e "s|${_pid}|PID|" +} + +required_error ETIMEDOUT <<EOF +Event timeout in random timed out +EOF +simple_test run 5 random timeout + +# wait for debug hung script +sleep 5 + +ok <<EOF +args: PID timeout +EOF +unit_test cat "${CTDB_BASE}/debug_script.log" + +pid=$(cat "${CTDB_BASE}/debug_script.log" | awk '{print $2}') + +ok_null +unit_test pstree "$pid" diff --git a/ctdb/tests/UNIT/eventd/eventd_031.sh b/ctdb/tests/UNIT/eventd/eventd_031.sh new file mode 100755 index 0000000..07efa80 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_031.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "multiple scripts" + +setup_eventd + +ok_null +simple_test run 30 multi monitor + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_032.sh b/ctdb/tests/UNIT/eventd/eventd_032.sh new file mode 100755 index 0000000..778acdb --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_032.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "failures with multiple scripts" + +setup_eventd + +required_error ENOEXEC <<EOF +Event event1 in multi failed +EOF +simple_test run 10 multi event1 + +required_result 1 <<EOF +01.test OK DURATION DATETIME +02.test ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status multi event1 + +required_error ENOEXEC <<EOF +Event event2 in multi failed +EOF +simple_test run 10 multi event2 + +required_result 2 <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status multi event2 + +required_error ENOEXEC <<EOF +Event event3 in multi failed +EOF +simple_test run 10 multi event3 + +required_result 3 <<EOF +01.test ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status multi event3 diff --git a/ctdb/tests/UNIT/eventd/eventd_033.sh b/ctdb/tests/UNIT/eventd/eventd_033.sh new file mode 100755 index 0000000..ba99b11 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_033.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "timeouts with multiple scripts" + +setup_eventd + +required_error ETIMEDOUT <<EOF +Event timeout1 in multi timed out +EOF +simple_test run 5 multi timeout1 + +required_error ETIMEDOUT <<EOF +01.test TIMEDOUT DATETIME + OUTPUT: +EOF +simple_test status multi timeout1 + +required_error ETIMEDOUT <<EOF +Event timeout2 in multi timed out +EOF +simple_test run 5 multi timeout2 + +required_error ETIMEDOUT <<EOF +01.test OK DURATION DATETIME +02.test TIMEDOUT DATETIME + OUTPUT: +EOF +simple_test status multi timeout2 + +required_error ETIMEDOUT <<EOF +Event timeout3 in multi timed out +EOF +simple_test run 5 multi timeout3 + +required_error ETIMEDOUT <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test TIMEDOUT DATETIME + OUTPUT: +EOF +simple_test status multi timeout3 diff --git a/ctdb/tests/UNIT/eventd/eventd_041.sh b/ctdb/tests/UNIT/eventd/eventd_041.sh new file mode 100755 index 0000000..ca4a99c --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_041.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "multiple components" + +setup_eventd + +ok_null +simple_test_background run 10 multi monitor + +ok_null +simple_test run 10 random monitor + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi monitor + +ok <<EOF +01.disabled DISABLED +02.enabled OK DURATION DATETIME +EOF +simple_test status random monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_042.sh b/ctdb/tests/UNIT/eventd/eventd_042.sh new file mode 100755 index 0000000..862cf6c --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_042.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "multiple components with failure" + +setup_eventd + +ok_null +simple_test_background run 10 multi monitor + +required_error ENOEXEC <<EOF +Event failure in random failed +EOF +simple_test run 10 random failure + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi monitor + +required_result 1 <<EOF +01.disabled DISABLED +02.enabled ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status random failure diff --git a/ctdb/tests/UNIT/eventd/eventd_043.sh b/ctdb/tests/UNIT/eventd/eventd_043.sh new file mode 100755 index 0000000..2304d23 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_043.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "multiple components with timeout" + +setup_eventd + +ok_null +simple_test_background run 10 multi monitor + +required_error ETIMEDOUT <<EOF +Event timeout in random timed out +EOF +simple_test run 10 random timeout + +ok <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test OK DURATION DATETIME +EOF +simple_test status multi monitor + +required_error ETIMEDOUT <<EOF +01.disabled DISABLED +02.enabled TIMEDOUT DATETIME + OUTPUT: +EOF +simple_test status random timeout diff --git a/ctdb/tests/UNIT/eventd/eventd_044.sh b/ctdb/tests/UNIT/eventd/eventd_044.sh new file mode 100755 index 0000000..8c0e931 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_044.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "new component" + +setup_eventd + +ok_null +mkdir "${eventd_scriptdir}/foobar" + +ok_null +cp "${eventd_scriptdir}/random/01.disabled.script" "${eventd_scriptdir}/foobar" + +required_result 22 <<EOF +Event monitor has never run in foobar +EOF +simple_test status foobar monitor + +ok_null +simple_test run 10 foobar monitor + +ok <<EOF +01.disabled DISABLED +EOF +simple_test status foobar monitor + +ok_null +simple_test script enable foobar 01.disabled + +ok_null +simple_test run 10 foobar monitor + +ok <<EOF +01.disabled OK DURATION DATETIME +EOF +simple_test status foobar monitor diff --git a/ctdb/tests/UNIT/eventd/eventd_051.sh b/ctdb/tests/UNIT/eventd/eventd_051.sh new file mode 100755 index 0000000..c00cb2e --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_051.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "logging check" + +setup_eventd + +ok_null +simple_test run 10 random verbose + +ok <<EOF +02.enabled: Running event verbose +EOF +unit_test grep "02.enabled:" "$eventd_logfile" diff --git a/ctdb/tests/UNIT/eventd/eventd_052.sh b/ctdb/tests/UNIT/eventd/eventd_052.sh new file mode 100755 index 0000000..75f9572 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/eventd_052.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "run through failure" + +setup_eventd + +export CTDB_EVENT_RUN_ALL=1 + +required_error ENOEXEC <<EOF +Event event1 in multi failed +EOF +simple_test run 10 multi event1 + +required_result 1 <<EOF +01.test OK DURATION DATETIME +02.test ERROR DURATION DATETIME + OUTPUT: +03.test OK DURATION DATETIME +EOF +simple_test status multi event1 + +required_error ENOEXEC <<EOF +Event event2 in multi failed +EOF +simple_test run 10 multi event2 + +required_result 2 <<EOF +01.test OK DURATION DATETIME +02.test OK DURATION DATETIME +03.test ERROR DURATION DATETIME + OUTPUT: +EOF +simple_test status multi event2 diff --git a/ctdb/tests/UNIT/eventd/scripts/local.sh b/ctdb/tests/UNIT/eventd/scripts/local.sh new file mode 100644 index 0000000..04cce63 --- /dev/null +++ b/ctdb/tests/UNIT/eventd/scripts/local.sh @@ -0,0 +1,122 @@ +# Hey Emacs, this is a -*- shell-script -*- !!! :-) + +. "${TEST_SCRIPTS_DIR}/script_install_paths.sh" + +PATH="$PATH:$CTDB_SCRIPTS_TOOLS_HELPER_DIR" + +if "$CTDB_TEST_VERBOSE" ; then + debug () { echo "$@" ; } +else + debug () { : ; } +fi + +setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc" + +ctdb_config=$(ctdb-path config) +eventd_socket=$(ctdb-path socket eventd) +eventd_pidfile=$(ctdb-path pidfile eventd) +eventd_scriptdir=$(ctdb-path etcdir append events) +eventd_logfile="${CTDB_BASE}/eventd.log" + +define_test () +{ + _f=$(basename "$0" ".sh") + + printf "%-28s - %s\n" "$_f" "$1" +} + +cleanup_eventd () +{ + debug "Cleaning up eventd" + + pid=$(cat "$eventd_pidfile" 2>/dev/null || echo) + if [ -n "$pid" ] ; then + kill $pid || true + fi +} + +setup_eventd () +{ + echo "Setting up eventd" + + $VALGRIND ctdb-eventd 2>&1 | tee "$eventd_logfile" & + # Wait till eventd is running + wait_until 10 test -S "$eventd_socket" || \ + die "ctdb_eventd failed to start" + + test_cleanup cleanup_eventd +} + +simple_test_background () +{ + background_log="${CTDB_BASE}/background.log" + background_status="${CTDB_BASE}/background.status" + background_running=1 + + ( + (unit_test ctdb-event "$@") > "$background_log" 2>&1 + echo $? > "$background_status" + ) & + background_pid=$! +} + +background_wait () +{ + [ -n "$background_running" ] || return + + count=0 + while [ ! -s "$background_status" -a $count -lt 30 ] ; do + count=$(( $count + 1 )) + sleep 1 + done + + if [ ! -s "$background_status" ] ; then + kill -9 "$background_pid" + echo TIMEOUT > "$background_status" + fi +} + +background_output () +{ + [ -n "$background_running" ] || return + + bg_status=$(cat "$background_status") + rm -f "$background_status" + echo "--- Background ---" + if [ "$bg_status" = "TIMEOUT" ] ; then + echo "Background process did not complete" + bg_status=1 + else + cat "$background_log" + rm -f "$background_log" + fi + echo "--- Background ---" + unset background_running + [ $bg_status -eq 0 ] || exit $bg_status +} + +simple_test () +{ + (unit_test ctdb-event "$@") + status=$? + + background_wait + background_output + + [ $status -eq 0 ] || exit $status +} + +result_filter () +{ + _duration="\<[0-9][0-9]*\.[0-9][0-9][0-9]\>" + _day="[FMSTW][aehoru][deintu]" + _month="[ADFJMNOS][aceopu][bcglnprtvy]" + _date="[ 0-9][0-9]" + _time="[0-9][0-9]:[0-9][0-9]:[0-9][0-9]" + _year="[0-9][0-9][0-9][0-9]" + _datetime="${_day} ${_month} ${_date} ${_time} ${_year}" + _pid="[0-9][0-9]*" + sed -e "s#${_duration}#DURATION#" \ + -e "s#${_datetime}#DATETIME#" \ + -e "s#,${_pid}#,PID#" +} |