ctdb-tests: Dump logs on shutdown failure
[samba.git] / ctdb / tests / scripts / integration_local_daemons.bash
blob643fc5ef8469270bd25dbb237aac95129b6861c7
1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
4 export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
6 if $CTDB_TESTS_ARE_INSTALLED ; then
7 # Find it in $PATH
8 helper="ctdb_local_daemons"
9 else
10 helper="${CTDB_TEST_DIR}/local_daemons.sh"
13 ctdb_local_daemons="${helper} ${CTDB_TEST_TMP_DIR}"
15 #######################################
17 setup_ctdb ()
19 local no_event_scripts=false
21 # All other options are passed through to local_daemons.sh setup
22 case "$1" in
23 --no-event-scripts) no_event_scripts=true ; shift ;;
24 esac
26 $ctdb_local_daemons setup "$@" \
27 -n "$CTDB_TEST_LOCAL_DAEMONS" \
28 ${CTDB_USE_IPV6:+-6} \
29 ${CTDB_TEST_SWRAP_SO_PATH:+-S ${CTDB_TEST_SWRAP_SO_PATH}}
30 # Burying the above in an if-statement condition reduces readability.
31 # shellcheck disable=SC2181
32 if [ $? -ne 0 ] ; then
33 exit 1
36 if $no_event_scripts ; then
37 # Want CTDB_BASE expanded when executed under onnode
38 # shellcheck disable=SC2016
39 $ctdb_local_daemons onnode -q all \
40 'rm "${CTDB_BASE}/events/legacy/"*'
43 if $CTDB_TEST_PRINT_LOGS_ON_ERROR ; then
44 ctdb_test_exit_hook_add _print_logs_on_test_failure
48 ctdb_nodes_start ()
50 local nodespec="${1:-all}"
52 $ctdb_local_daemons start "$nodespec"
55 ctdb_nodes_stop ()
57 local nodespec="${1:-all}"
59 if $ctdb_local_daemons stop "$nodespec" ; then
60 return 0
63 # Failed, dump logs?
64 if $CTDB_TEST_PRINT_LOGS_ON_ERROR ; then
65 _print_logs
68 # Next level up can log the error...
69 return 1
72 onnode ()
74 $ctdb_local_daemons onnode "$@"
79 _print_logs ()
81 echo "*** LOG START --------------------"
82 $ctdb_local_daemons print-log all | tail -n 500
83 echo "*** LOG END --------------------"
86 _print_logs_on_test_failure ()
88 # This is called from ctdb_test_exit() where $status is available
89 # shellcheck disable=SC2154
90 if [ "$status" -eq 0 ] ; then
91 return
94 _print_logs