winbind: Fix a memleak
[vlendec/samba-autobuild/.git] / ctdb / tests / scripts / integration_local_daemons.bash
1 # Hey Emacs, this is a -*- shell-script -*- !!!  :-)
2
3 hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
4 export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
5
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"
11 fi
12
13 ctdb_local_daemons="${helper} ${CTDB_TEST_TMP_DIR}"
14
15 #######################################
16
17 setup_ctdb ()
18 {
19         local no_event_scripts=false
20
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
25
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
34         fi
35
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/"*'
41         fi
42
43         if $CTDB_TEST_PRINT_LOGS_ON_ERROR ; then
44                 ctdb_test_exit_hook_add _print_logs_on_test_failure
45         fi
46 }
47
48 ctdb_nodes_start ()
49 {
50         local nodespec="${1:-all}"
51
52         $ctdb_local_daemons start "$nodespec"
53 }
54
55 ctdb_nodes_stop ()
56 {
57         local nodespec="${1:-all}"
58
59         if $ctdb_local_daemons stop "$nodespec" ; then
60                 return 0
61         fi
62
63         # Failed, dump logs?
64         if $CTDB_TEST_PRINT_LOGS_ON_ERROR ; then
65                 _print_logs
66         fi
67
68         # Next level up can log the error...
69         return 1
70 }
71
72 onnode ()
73 {
74         $ctdb_local_daemons onnode "$@"
75 }
76
77
78
79 _print_logs ()
80 {
81         echo "*** LOG START --------------------"
82         $ctdb_local_daemons print-log all | tail -n 500
83         echo "*** LOG END   --------------------"
84 }
85
86 _print_logs_on_test_failure ()
87 {
88         # This is called from ctdb_test_exit() where $status is available
89         # shellcheck disable=SC2154
90         if [ "$status" -eq 0 ] ; then
91                 return
92         fi
93
94         _print_logs
95 }