mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb-tests: Add tests for event daemon
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
9cbdb40612
commit
ca0894e932
1
ctdb/tests/eventd/README
Normal file
1
ctdb/tests/eventd/README
Normal file
@ -0,0 +1 @@
|
||||
Unit tests for event daemon
|
31
ctdb/tests/eventd/eventd_001.sh
Executable file
31
ctdb/tests/eventd/eventd_001.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "empty eventscript directory"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 0 <<EOF
|
||||
No event scripts found
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never run
|
||||
EOF
|
||||
simple_test status monitor
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
54
ctdb/tests/eventd/eventd_002.sh
Executable file
54
ctdb/tests/eventd/eventd_002.sh
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "eventscript directory with random files"
|
||||
|
||||
setup_eventd
|
||||
|
||||
touch "$eventd_scriptdir/README"
|
||||
|
||||
cat > "$eventd_scriptdir/a.sh" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
exit 1
|
||||
EOF
|
||||
|
||||
required_result 0 <<EOF
|
||||
No event scripts found
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 22 <<EOF
|
||||
Script name README is invalid
|
||||
EOF
|
||||
simple_test script enable README
|
||||
|
||||
required_result 22 <<EOF
|
||||
Script name a.sh is invalid
|
||||
EOF
|
||||
simple_test script disable a.sh
|
||||
|
||||
required_result 2 <<EOF
|
||||
Script 00.test does not exist
|
||||
EOF
|
||||
simple_test script enable 00.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never run
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
54
ctdb/tests/eventd/eventd_003.sh
Executable file
54
ctdb/tests/eventd/eventd_003.sh
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "disabled event script"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test DISABLED
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script disable 01.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script enable 01.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script disable 01.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test DISABLED
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test DISABLED
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
45
ctdb/tests/eventd/eventd_004.sh
Executable file
45
ctdb/tests/eventd/eventd_004.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "enabled event script"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test DISABLED
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script enable 01.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script enable 01.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
36
ctdb/tests/eventd/eventd_005.sh
Executable file
36
ctdb/tests/eventd/eventd_005.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "failing event script"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
exit 1
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 1 <<EOF
|
||||
Failed to run event monitor, result=1
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
37
ctdb/tests/eventd/eventd_006.sh
Executable file
37
ctdb/tests/eventd/eventd_006.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "timing out event script"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
sleep 10
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event monitor timed out
|
||||
EOF
|
||||
simple_test run monitor 5
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
37
ctdb/tests/eventd/eventd_007.sh
Executable file
37
ctdb/tests/eventd/eventd_007.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "capture event script output"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "args: \$*"
|
||||
exit 1
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 1 <<EOF
|
||||
Failed to run event monitor, result=1
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT: args: monitor
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT: args: monitor
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
64
ctdb/tests/eventd/eventd_011.sh
Executable file
64
ctdb/tests/eventd/eventd_011.sh
Executable file
@ -0,0 +1,64 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "multiple events"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "args: \$*"
|
||||
|
||||
case "\$1" in
|
||||
startup)
|
||||
exit 0
|
||||
;;
|
||||
monitor)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run startup 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event startup has never failed
|
||||
EOF
|
||||
simple_test status startup lastfail
|
||||
|
||||
required_result 1 <<EOF
|
||||
Failed to run event monitor, result=1
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT: args: monitor
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT: args: monitor
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
53
ctdb/tests/eventd/eventd_012.sh
Executable file
53
ctdb/tests/eventd/eventd_012.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "cancel new monitor event"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
sleep 5
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test_background run startup 30
|
||||
|
||||
required_result 125 <<EOF
|
||||
Event monitor got cancelled
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event startup has never failed
|
||||
EOF
|
||||
simple_test status startup lastfail
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never run
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
53
ctdb/tests/eventd/eventd_013.sh
Executable file
53
ctdb/tests/eventd/eventd_013.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "cancel running monitor event"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
sleep 5
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 125 <<EOF
|
||||
Event monitor got cancelled
|
||||
EOF
|
||||
simple_test_background run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run startup 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event startup has never failed
|
||||
EOF
|
||||
simple_test status startup lastfail
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never run
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
52
ctdb/tests/eventd/eventd_014.sh
Executable file
52
ctdb/tests/eventd/eventd_014.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "queue events"
|
||||
|
||||
setup_eventd
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
sleep 5
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test_background run startup 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run ipreallocated 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status startup lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event startup has never failed
|
||||
EOF
|
||||
simple_test status startup lastfail
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status ipreallocated lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status ipreallocated lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event ipreallocated has never failed
|
||||
EOF
|
||||
simple_test status ipreallocated lastfail
|
40
ctdb/tests/eventd/eventd_021.sh
Executable file
40
ctdb/tests/eventd/eventd_021.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "debug script"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
sleep 99
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
cat > "$eventd_scriptdir/debug.sh" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "args: \$*" > "$eventd_debug"
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/debug.sh"
|
||||
|
||||
setup_eventd "$eventd_scriptdir/debug.sh"
|
||||
|
||||
result_filter ()
|
||||
{
|
||||
_pid="[0-9][0-9]*"
|
||||
sed -e "s| ${_pid}| PID|"
|
||||
}
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event startup timed out
|
||||
EOF
|
||||
simple_test run startup 5
|
||||
|
||||
# wait for debug hung script
|
||||
sleep 5
|
||||
|
||||
required_result 0 <<EOF
|
||||
args: PID startup
|
||||
EOF
|
||||
unit_test cat "$eventd_debug"
|
41
ctdb/tests/eventd/eventd_022.sh
Executable file
41
ctdb/tests/eventd/eventd_022.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "status output in debug script"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "Sleeping for 99 seconds"
|
||||
sleep 99
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
cat > "$eventd_scriptdir/debug.sh" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
(
|
||||
pstree -p -a \$1
|
||||
ctdb_event "$eventd_socket" status monitor lastrun
|
||||
) > "$eventd_debug"
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/debug.sh"
|
||||
|
||||
setup_eventd "$eventd_scriptdir/debug.sh"
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event monitor timed out
|
||||
EOF
|
||||
simple_test run monitor 5
|
||||
|
||||
# wait for debug hung script
|
||||
sleep 5
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test,PID $eventd_scriptdir/01.test monitor
|
||||
\`-sleep,PID 99
|
||||
01.test TIMEDOUT DATETIME
|
||||
OUTPUT: Sleeping for 99 seconds
|
||||
EOF
|
||||
unit_test cat "$eventd_debug"
|
38
ctdb/tests/eventd/eventd_023.sh
Executable file
38
ctdb/tests/eventd/eventd_023.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "redirected status output in debug script"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "Sleeping for 99 seconds"
|
||||
sleep 99
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
cat > "$eventd_scriptdir/debug.sh" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
exec >"$eventd_debug" 2>&1
|
||||
|
||||
ctdb_event "$eventd_socket" status monitor lastrun
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/debug.sh"
|
||||
|
||||
setup_eventd "$eventd_scriptdir/debug.sh"
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event monitor timed out
|
||||
EOF
|
||||
simple_test run monitor 5
|
||||
|
||||
# wait for debug hung script
|
||||
sleep 5
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test TIMEDOUT DATETIME
|
||||
OUTPUT: Sleeping for 99 seconds
|
||||
EOF
|
||||
unit_test cat "$eventd_debug"
|
47
ctdb/tests/eventd/eventd_024.sh
Executable file
47
ctdb/tests/eventd/eventd_024.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "process terminated after debug"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "Sleeping for 99 seconds"
|
||||
sleep 99
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
cat > "$eventd_scriptdir/debug.sh" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo \$1 > "$eventd_debug"
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/debug.sh"
|
||||
|
||||
setup_eventd "$eventd_scriptdir/debug.sh"
|
||||
|
||||
result_filter()
|
||||
{
|
||||
_pid="[0-9][0-9]*"
|
||||
sed -e "s|${_pid}|PID|"
|
||||
}
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event monitor timed out
|
||||
EOF
|
||||
simple_test run monitor 5
|
||||
|
||||
# wait for debug hung script
|
||||
sleep 5
|
||||
|
||||
required_result 0 <<EOF
|
||||
PID
|
||||
EOF
|
||||
unit_test cat "$eventd_debug"
|
||||
|
||||
pid=$(cat "$eventd_debug")
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
unit_test pstree -p -a "$pid"
|
65
ctdb/tests/eventd/eventd_031.sh
Executable file
65
ctdb/tests/eventd/eventd_031.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "multiple scripts"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
sleep 1
|
||||
EOF
|
||||
|
||||
cp "$eventd_scriptdir/01.test" "$eventd_scriptdir/02.test"
|
||||
cp "$eventd_scriptdir/01.test" "$eventd_scriptdir/03.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test DISABLED
|
||||
02.test DISABLED
|
||||
03.test DISABLED
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script enable 01.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script enable 02.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test script enable 03.test
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test
|
||||
02.test
|
||||
03.test
|
||||
EOF
|
||||
simple_test script list
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test OK DURATION DATETIME
|
||||
03.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test OK DURATION DATETIME
|
||||
03.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never failed
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
124
ctdb/tests/eventd/eventd_032.sh
Executable file
124
ctdb/tests/eventd/eventd_032.sh
Executable file
@ -0,0 +1,124 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "failures with multiple scripts"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
case "\$1" in
|
||||
startup)
|
||||
exit 1
|
||||
;;
|
||||
monitor|ipreallocated)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
cat > "$eventd_scriptdir/02.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
case "\$1" in
|
||||
monitor)
|
||||
exit 2
|
||||
;;
|
||||
startup|ipreallocated)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/02.test"
|
||||
|
||||
cat > "$eventd_scriptdir/03.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
case "\$1" in
|
||||
ipreallocated)
|
||||
exit 3
|
||||
;;
|
||||
startup|monitor)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/03.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 1 <<EOF
|
||||
Failed to run event startup, result=1
|
||||
EOF
|
||||
simple_test run startup 30
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status startup
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event startup has never passed
|
||||
EOF
|
||||
simple_test status startup lastpass
|
||||
|
||||
required_result 1 <<EOF
|
||||
01.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status startup lastfail
|
||||
|
||||
required_result 2 <<EOF
|
||||
Failed to run event monitor, result=2
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 2 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 2 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
||||
|
||||
required_result 3 <<EOF
|
||||
Failed to run event ipreallocated, result=3
|
||||
EOF
|
||||
simple_test run ipreallocated 30
|
||||
|
||||
required_result 3 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test OK DURATION DATETIME
|
||||
03.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status ipreallocated
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event ipreallocated has never passed
|
||||
EOF
|
||||
simple_test status ipreallocated lastpass
|
||||
|
||||
required_result 3 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test OK DURATION DATETIME
|
||||
03.test ERROR DURATION DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status ipreallocated lastfail
|
124
ctdb/tests/eventd/eventd_033.sh
Executable file
124
ctdb/tests/eventd/eventd_033.sh
Executable file
@ -0,0 +1,124 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "timeouts with multiple scripts"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
case "\$1" in
|
||||
startup)
|
||||
sleep 10
|
||||
;;
|
||||
monitor|ipreallocated)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
cat > "$eventd_scriptdir/02.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
case "\$1" in
|
||||
monitor)
|
||||
sleep 10
|
||||
;;
|
||||
startup|ipreallocated)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/02.test"
|
||||
|
||||
cat > "$eventd_scriptdir/03.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
case "\$1" in
|
||||
ipreallocated)
|
||||
sleep 10
|
||||
;;
|
||||
startup|monitor)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/03.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event startup timed out
|
||||
EOF
|
||||
simple_test run startup 5
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status startup lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event startup has never passed
|
||||
EOF
|
||||
simple_test status startup lastpass
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status startup lastfail
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event monitor timed out
|
||||
EOF
|
||||
simple_test run monitor 5
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event monitor has never passed
|
||||
EOF
|
||||
simple_test status monitor lastpass
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status monitor lastfail
|
||||
|
||||
required_result 62 <<EOF
|
||||
Event ipreallocated timed out
|
||||
EOF
|
||||
simple_test run ipreallocated 5
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test OK DURATION DATETIME
|
||||
03.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status ipreallocated lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event ipreallocated has never passed
|
||||
EOF
|
||||
simple_test status ipreallocated lastpass
|
||||
|
||||
required_result 62 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
02.test OK DURATION DATETIME
|
||||
03.test TIMEDOUT DATETIME
|
||||
OUTPUT:
|
||||
EOF
|
||||
simple_test status ipreallocated lastfail
|
48
ctdb/tests/eventd/eventd_041.sh
Executable file
48
ctdb/tests/eventd/eventd_041.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "takeip event"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo \$*
|
||||
if [ \$# -ne 4 ] ; then
|
||||
echo "Wrong number of arguments"
|
||||
exit 2
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 1 <<EOF
|
||||
Insufficient arguments for event takeip
|
||||
EOF
|
||||
simple_test run takeip 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event takeip has never run
|
||||
EOF
|
||||
simple_test status takeip lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run takeip 30 eth0 192.168.1.1 24
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status takeip lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status takeip lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event takeip has never failed
|
||||
EOF
|
||||
simple_test status takeip lastfail
|
48
ctdb/tests/eventd/eventd_042.sh
Executable file
48
ctdb/tests/eventd/eventd_042.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "releaseip event"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo \$*
|
||||
if [ \$# -ne 4 ] ; then
|
||||
echo "Wrong number of arguments"
|
||||
exit 2
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 1 <<EOF
|
||||
Insufficient arguments for event releaseip
|
||||
EOF
|
||||
simple_test run releaseip 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event releaseip has never run
|
||||
EOF
|
||||
simple_test status releaseip lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run releaseip 30 eth0 192.168.1.1 24
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status releaseip lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status releaseip lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event releaseip has never failed
|
||||
EOF
|
||||
simple_test status releaseip lastfail
|
48
ctdb/tests/eventd/eventd_043.sh
Executable file
48
ctdb/tests/eventd/eventd_043.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "updateip event"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo \$*
|
||||
if [ \$# -ne 5 ] ; then
|
||||
echo "Wrong number of arguments"
|
||||
exit 2
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 1 <<EOF
|
||||
Insufficient arguments for event updateip
|
||||
EOF
|
||||
simple_test run updateip 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event updateip has never run
|
||||
EOF
|
||||
simple_test status updateip lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run updateip 30 eth0 eth1 192.168.1.1 24
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status updateip lastrun
|
||||
|
||||
required_result 0 <<EOF
|
||||
01.test OK DURATION DATETIME
|
||||
EOF
|
||||
simple_test status updateip lastpass
|
||||
|
||||
required_result 0 <<EOF
|
||||
Event updateip has never failed
|
||||
EOF
|
||||
simple_test status updateip lastfail
|
23
ctdb/tests/eventd/eventd_051.sh
Executable file
23
ctdb/tests/eventd/eventd_051.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "logging check"
|
||||
|
||||
cat > "$eventd_scriptdir/01.test" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
echo "Running event \$1"
|
||||
EOF
|
||||
chmod +x "$eventd_scriptdir/01.test"
|
||||
|
||||
setup_eventd
|
||||
|
||||
required_result 0 <<EOF
|
||||
EOF
|
||||
simple_test run monitor 30
|
||||
|
||||
required_result 0 <<EOF
|
||||
ctdb-eventd[PID]: 01.test: Running event monitor
|
||||
EOF
|
||||
unit_test tail -n 1 "$eventd_logfile"
|
137
ctdb/tests/eventd/scripts/local.sh
Normal file
137
ctdb/tests/eventd/scripts/local.sh
Normal file
@ -0,0 +1,137 @@
|
||||
# Hey Emacs, this is a -*- shell-script -*- !!! :-)
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
|
||||
|
||||
PATH="$PATH:$CTDB_SCRIPTS_TOOLS_HELPER_DIR"
|
||||
|
||||
# Augment PATH with stubs/ directory.
|
||||
|
||||
if "$TEST_VERBOSE" ; then
|
||||
debug () { echo "$@" ; }
|
||||
else
|
||||
debug () { : ; }
|
||||
fi
|
||||
|
||||
eventd_socket="${TEST_VAR_DIR}/eventd.socket.$$"
|
||||
eventd_pidfile="${TEST_VAR_DIR}/eventd.pid.$$"
|
||||
eventd_logfile="${TEST_VAR_DIR}/eventd.log.$$"
|
||||
eventd_debug=$(mktemp --tmpdir="$TEST_VAR_DIR")
|
||||
eventd_scriptdir=$(mktemp -d --tmpdir="$TEST_VAR_DIR")
|
||||
|
||||
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
|
||||
rm -f "$eventd_pidfile"
|
||||
fi
|
||||
rm -f "$eventd_socket"
|
||||
rm -f "$eventd_logfile"
|
||||
rm -f "$eventd_debug"
|
||||
rm -rf "$eventd_scriptdir"
|
||||
}
|
||||
|
||||
setup_eventd ()
|
||||
{
|
||||
debug "Setting up eventd"
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
extra_args="-D $1"
|
||||
fi
|
||||
|
||||
$VALGRIND ctdb_eventd -s "$eventd_socket" \
|
||||
-p "$eventd_pidfile" \
|
||||
-e "$eventd_scriptdir" \
|
||||
-l "file:" -d "DEBUG" $extra_args 2>&1 | tee "$eventd_logfile" &
|
||||
# Wait till eventd is running
|
||||
while [ ! -S "$eventd_socket" ] ; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
test_cleanup cleanup_eventd
|
||||
}
|
||||
|
||||
simple_test_background ()
|
||||
{
|
||||
background_log=$(mktemp --tmpdir="$TEST_VAR_DIR")
|
||||
background_status=$(mktemp --tmpdir="$TEST_VAR_DIR")
|
||||
background_running=1
|
||||
|
||||
(
|
||||
(unit_test ctdb_event "$eventd_socket" "$@") \
|
||||
> "$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 "$eventd_socket" "$@")
|
||||
status=$?
|
||||
|
||||
background_wait
|
||||
background_output
|
||||
|
||||
[ $status -eq 0 ] || exit $status
|
||||
}
|
||||
|
||||
result_filter ()
|
||||
{
|
||||
_duration="[0-9]*\.[0-9][0-9][0-9]"
|
||||
_day="\(Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun\)"
|
||||
_month="\(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\)"
|
||||
_date="\( [0-9]\|[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#" \
|
||||
-e "s#\[${_pid}\]#[PID]#"
|
||||
}
|
@ -257,7 +257,7 @@ export TEST_SCRIPTS_DIR="${test_dir}/scripts"
|
||||
# If no tests specified then run some defaults
|
||||
if [ -z "$1" ] ; then
|
||||
if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
|
||||
set -- onnode takeover tool eventscripts cunit shellcheck simple
|
||||
set -- onnode takeover tool eventscripts cunit eventd shellcheck simple
|
||||
else
|
||||
set -- simple complex
|
||||
fi
|
||||
|
@ -829,6 +829,7 @@ def build(bld):
|
||||
test_subdirs = [
|
||||
'complex',
|
||||
'cunit',
|
||||
'eventd',
|
||||
'events.d',
|
||||
'eventscripts',
|
||||
'onnode',
|
||||
|
Loading…
Reference in New Issue
Block a user