ctdb-tests: Do not expect real-time priority when running local daemons
[amitay/samba.git] / ctdb / tests / simple / scripts / local_daemons.bash
1 # If we're not running on a real cluster then we need a local copy of
2 # ctdb (and other stuff) in $PATH and we will use local daemons.
3
4 export CTDB_NODES_SOCKETS=""
5 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
6     CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${TEST_VAR_DIR}/sock.${i}"
7 done
8
9 # Use in-tree binaries if running against local daemons.
10 # Otherwise CTDB need to be installed on all nodes.
11 if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
12     PATH="${ctdb_dir}/bin:${PATH}"
13     export CTDB_LOCK_HELPER="${ctdb_dir}/bin/ctdb_lock_helper"
14     export CTDB_EVENT_HELPER="${ctdb_dir}/bin/ctdb_event_helper"
15 fi
16
17 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
18
19 #######################################
20
21 daemons_stop ()
22 {
23     echo "Attempting to politely shutdown daemons..."
24     onnode 1 $CTDB shutdown -n all || true
25
26     echo "Sleeping for a while..."
27     sleep_for 1
28
29     local pat="ctdbd --socket=${TEST_VAR_DIR}/.* --nlist .* --nopublicipcheck"
30     if pgrep -f "$pat" >/dev/null ; then
31         echo "Killing remaining daemons..."
32         pkill -f "$pat"
33
34         if pgrep -f "$pat" >/dev/null ; then
35             echo "Once more with feeling.."
36             pkill -9 -f "$pat"
37         fi
38     fi
39
40     rm -rf "${TEST_VAR_DIR}/test.db"
41 }
42
43 setup_ctdb ()
44 {
45     mkdir -p "${TEST_VAR_DIR}/test.db/persistent"
46
47     local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
48     local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
49     rm -f $CTDB_NODES $public_addresses_all $no_public_addresses
50
51     # If there are (strictly) greater than 2 nodes then we'll randomly
52     # choose a node to have no public addresses.
53     local no_public_ips=-1
54     [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
55     echo "$no_public_ips" >$no_public_addresses
56
57     # When running certain tests we add and remove eventscripts, so we
58     # need to be able to modify the events.d/ directory.  Therefore,
59     # we use a temporary events.d/ directory under $TEST_VAR_DIR.  We
60     # copy the actual test eventscript(s) in there from the original
61     # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
62     local top=$(dirname "$TEST_SCRIPTS_DIR")
63     local events_d="${top}/events.d"
64     mkdir -p "${TEST_VAR_DIR}/events.d"
65     cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
66
67     local i
68     for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
69         if [ "${CTDB_USE_IPV6}x" != "x" ]; then
70             echo ::$i >>"$CTDB_NODES"
71             ip addr add ::$i/128 dev lo
72         else
73             echo 127.0.0.$i >>"$CTDB_NODES"
74             # 2 public addresses on most nodes, just to make things interesting.
75             if [ $(($i - 1)) -ne $no_public_ips ] ; then
76                 echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
77                 echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
78             fi
79         fi
80     done
81 }
82
83 daemons_start_1 ()
84 {
85     local pnn="$1"
86     shift # "$@" gets passed to ctdbd
87
88     local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
89     local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"
90     local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
91
92     local no_public_ips=-1
93     [ -r $no_public_addresses ] && read no_public_ips <$no_public_addresses
94
95     if  [ "$no_public_ips" = $pnn ] ; then
96         echo "Node $no_public_ips will have no public IPs."
97     fi
98
99     local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
100     local ctdb_options="--sloppy-start --reclock=${TEST_VAR_DIR}/rec.lock --nlist $CTDB_NODES --nopublicipcheck --listen=${node_ip} --event-script-dir=${TEST_VAR_DIR}/events.d --logfile=${TEST_VAR_DIR}/daemon.${pnn}.log -d 3 --log-ringbuf-size=10000 --dbdir=${TEST_VAR_DIR}/test.db --dbdir-persistent=${TEST_VAR_DIR}/test.db/persistent --dbdir-state=${TEST_VAR_DIR}/test.db/state --nosetsched"
101
102     if [ $pnn -eq $no_public_ips ] ; then
103         ctdb_options="$ctdb_options --public-addresses=/dev/null"
104     else
105         cp "$public_addresses_all" "$public_addresses_mine"
106         ctdb_options="$ctdb_options --public-addresses=$public_addresses_mine"
107     fi
108
109     # We'll use "pkill -f" to kill the daemons with
110     # "--socket=.* --nlist .* --nopublicipcheck" as context.
111     $VALGRIND ctdbd --socket="${TEST_VAR_DIR}/sock.$pnn" $ctdb_options "$@" ||return 1
112 }
113
114 daemons_start ()
115 {
116     # "$@" gets passed to ctdbd
117
118     echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
119
120     for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
121         daemons_start_1 $i "$@"
122     done
123 }
124
125 maybe_stop_ctdb ()
126 {
127     if $TEST_CLEANUP ; then
128         daemons_stop
129     fi
130 }
131
132 _restart_ctdb_all ()
133 {
134     daemons_stop
135     daemons_start "$@"
136 }