Whamcloud - gitweb
e77f7fb061eca5dbd80ac3f7746bbac882e52c09
[fs/lustre-release.git] / lustre / tests / recovery-double-scale.sh
1 #!/bin/bash
2
3 # All pairwise combinations of node failures.
4 # Was cmd3-17
5 #
6 # Author: Chris Cooper <ccooper@clusterfs.com>
7 #
8 # Script fails pair of nodes:
9 # --  in parallel by default
10 # --  in series if SERIAL is set
11
12 LUSTRE=${LUSTRE:-`dirname $0`/..}
13 SETUP=${SETUP:-""}
14 CLEANUP=${CLEANUP:-""}
15 . $LUSTRE/tests/test-framework.sh
16
17 init_test_env $@
18
19 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
20 TESTSUITELOG=${TESTSUITELOG:-$TMP/recovery-double-scale}
21 DEBUGLOG=$TESTSUITELOG.debug
22 exec 2>$DEBUGLOG
23 echo "--- env ---" >&2
24 env >&2
25 echo "--- env ---" >&2
26 set -x
27
28 [ -n "$CLIENTS" ] || { skip "$0 Need two or more remote clients" && exit 0; }
29 [ $CLIENTCOUNT -ge 3 ] || \
30     { skip "$0 Need two or more remote clients, have $CLIENTCOUNT" && exit 0; }
31
32 END_RUN_FILE=${END_RUN_FILE:-$SHARED_DIRECTORY}/end_run_file}
33 LOAD_PID_FILE=${LOAD_PID_FILE:-$TMP/client-load.pid}
34
35 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
36 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
37
38 check_timeout || exit 1
39
40 build_test_filter
41
42 check_and_setup_lustre
43 rm -rf $DIR/[df][0-9]*
44
45 # the test node needs to be insulated from a lustre failure as much as possible,
46 # so not even loading the lustre modules is ideal.
47 # -- umount lustre
48 # -- remove hostname from clients list
49 zconf_umount $(hostname) $MOUNT
50 NODES_TO_USE=${NODES_TO_USE:-$CLIENTS}
51 NODES_TO_USE=$(exclude_items_from_list $NODES_TO_USE $(hostname))
52
53 check_progs_installed $NODES_TO_USE ${CLIENT_LOADS[@]}
54
55 MDTS=$(get_facets MDS)
56 OSTS=$(get_facets OST)
57
58 rm -f $END_RUN_FILE
59
60 reboot_recover_node () {
61     # item var contains a pair of clients if nodetype=clients
62     # I would prefer to have a list here
63     local item=$1
64     local nodetype=$2   
65     local timeout=$($LCTL get_param  -n timeout)
66
67     # MDS, OST item contains the facet
68     case $nodetype in
69        MDS|OST )    facet_failover $item
70                 [ "$SERIAL" ] && wait_recovery_complete $item $((timeout * 4)) || true
71                 ;;
72        clients) for c in ${item//,/ }; do
73                       shutdown_client $c
74                       boot_node $c
75                       echo "Reintegrating $c"
76                       zconf_mount $c $MOUNT || return $?
77                  done
78                  start_client_loads $item || return $?
79                  ;;
80        * )      error "reboot_recover_node: nodetype=$nodetype. Must be one of 'MDS', 'OST', or 'clients'."
81                 exit 1;;
82     esac
83 }
84
85 get_item_type () {
86     local type=$1
87     local excluded=${2:-""}
88
89     local list
90     case $type in
91        MDS )    list=$MDTS;;
92        OST )    list=$OSTS;;
93        clients) list=$NODES_TO_USE
94                 ;;
95        * )      error "Invalid type=$type. Must be one of 'MDS', 'OST', or 'clients'."
96                 exit 1;;
97     esac
98
99     [ "$excluded" ] && list=$(exclude_items_from_list $list $excluded)
100     # empty list
101     if [ ! "$(echo $list)" ]; then
102         echo
103         return
104     fi
105
106     item=$(get_random_entry $list)
107     if [ "$type" = clients ] ; then
108         item="$item $(get_random_entry $(exclude_items_from_list $list $item))"
109         item=$(comma_list $item)
110     fi
111     echo $item
112 }
113
114 # failover_pair
115 #
116 # for the two nodetypes specified, chooses a random node(s) from each
117 # class, reboots the nodes sequentially, and then restarts lustre on
118 # the nodes.
119 failover_pair() {
120     local type1=$1
121     local type2=$2
122     local title=$3
123
124     local client_nodes=""
125     local item1=
126     local item2=
127     local client1=
128     local client2=
129
130     log "
131 ==== START === $title "
132
133     item1=$(get_item_type $type1)
134     [ "$item1" ] || \
135         { echo "type1=$type1 item1 is empty" && return 0; }
136     item2=$(get_item_type $type2 $item1)
137     [ "$item2" ] || \
138         { echo "type1=$type1 item1=$item1 type2=$type2 item2=$item2 is empty" && return 0; }
139
140     # Check that our client loads are still running. If any have died,
141     # that means they have died outside of recovery, which is unacceptable.
142     log "==== Checking the clients loads BEFORE failover -- failure NOT OK"
143
144     # FIXME. need print summary on exit
145     if ! check_client_loads $NODES_TO_USE; then
146         exit 4
147     fi
148
149     log "Done checking client loads. Failing type1=$type1 item1=$item1 ... "
150
151     reboot_recover_node $item1 $type1 || return $?
152
153     # Hendrix test17 description: 
154     # Introduce a failure, wait at
155     # least 5 minutes (for recovery),
156     # introduce a 2nd
157     # failure, and wait another 5
158     # minutes
159
160     # reboot_recover_node waits recovery in according to
161     # SERIAL value.
162     # We have a "double failures" if SERIAL is not set,
163     # do not need a sleep between failures for "double failures"
164
165     log "                            Failing type2=$type2 item2=$item2 ... "    
166     reboot_recover_node $item2 $type2 || return $?
167
168     # Client loads are allowed to die while in recovery, so we just
169     # restart them.
170     log "==== Checking the clients loads AFTER  failovers -- ERRORS_OK=$ERRORS_OK"
171     restart_client_loads $NODES_TO_USE $ERRORS_OK || return $? 
172     log "Done checking / re-Starting client loads. PASS"
173     return 0
174 }
175
176 summary_and_cleanup () {
177     local rc=$?
178     trap 0
179
180     # Having not empty END_RUN_FILE means the failed loads only
181     if [ -s $END_RUN_FILE ]; then
182         echo "Found the END_RUN_FILE file: $END_RUN_FILE"
183         cat $END_RUN_FILE
184         local END_RUN_NODE=
185         read END_RUN_NODE < $END_RUN_FILE
186
187         # a client load will end (i.e. fail) if it finds
188         # the end run file.  that does not mean that that client load
189         # actually failed though.  the first node in the END_RUN_NODE is
190         # the one we are really interested in.
191         if [ -n "$END_RUN_NODE" ]; then
192             var=${END_RUN_NODE}_load
193             echo "Client load failed on node $END_RUN_NODE"
194             echo
195             echo "client $END_RUN_NODE load debug output :"
196             local logfile=${TESTSUITELOG}_run_${!var}.sh-${END_RUN_NODE}.debug 
197             do_node ${END_RUN_NODE} "set -x; [ -e $logfile ] && cat $logfile " || true
198         fi
199         rc=1
200     fi
201
202     echo $(date +'%F %H:%M:%S') Terminating clients loads ...
203     echo "$0" >> $END_RUN_FILE
204     local result=PASS
205     [ $rc -eq 0 ] || result=FAIL
206
207     log "
208 Server failover period: $FAILOVER_PERIOD seconds
209 Exited after:           $ELAPSED seconds
210 Status: $result: rc=$rc"
211
212     # make sure the client loads die
213     do_nodes $NODES_TO_USE "set -x; test -f $TMP/client-load.pid && \
214         { kill -s TERM \$(cat $TMP/client-load.pid) || true; }"
215
216     # and free up the pdshes that started them, if any are still around
217     if [ -n "$CLIENT_LOAD_PIDS" ]; then
218         kill $CLIENT_LOAD_PIDS || true
219         sleep 5
220         kill -9 $CLIENT_LOAD_PIDS || true
221     fi
222     [ $rc -eq 0 ] && zconf_mount $(hostname) $MOUNT
223     exit $rc
224 }
225
226 trap summary_and_cleanup EXIT TERM INT
227
228 #
229 # MAIN
230 #
231 log "-----============= $0 starting =============-----"
232
233 START_TS=$(date +%s)
234 CURRENT_TS=$START_TS
235 ELAPSED=0
236
237 # Set SERIAL to serialize the failure through a recovery of the first failure. 
238 SERIAL=${SERIAL:-""}
239 ERRORS_OK="yes"
240
241 [ "$SERIAL" ] && ERRORS_OK="" 
242
243 FAILOVER_PERIOD=${FAILOVER_PERIOD:-$((60*5))} # 5 minutes
244
245 # Start client loads.
246 start_client_loads $NODES_TO_USE
247 echo clients load pids:
248 if ! do_nodes $NODES_TO_USE "set -x; echo \$(hostname): && cat $TMP/client-load.pid"; then
249     if [ -e $DEBUGLOG ]; then
250         exec 2<&-
251         cat $DEBUGLOG
252         exit 3
253     fi
254 fi
255
256 # FIXME: Do we want to have an initial sleep period where the clients 
257 # just run before introducing a failure?
258 sleep $FAILOVER_PERIOD
259
260 #CMD_TEST_NUM=17.1
261 failover_pair MDS OST     "test 1: failover MDS, then OST =========="
262 sleep $FAILOVER_PERIOD
263
264 #CMD_TEST_NUM=17.2
265 failover_pair MDS clients "test 2: failover MDS, then 2 clients ===="
266 sleep $FAILOVER_PERIOD
267
268 #CMD_TEST_NUM=17.3
269 if [ $MDSCOUNT -gt 1 ]; then
270     failover_pair MDS MDS     "test 3: failover MDS, then another MDS =="
271     sleep $FAILOVER_PERIOD
272 else
273     skip "$0 : $MDSCOUNT < 2 MDTs, test 3 skipped"
274 fi 
275
276 #CMD_TEST_NUM=17.4
277 if [ $OSTCOUNT -gt 1 ]; then
278     failover_pair OST OST     "test 4: failover OST, then another OST =="
279     sleep $FAILOVER_PERIOD
280 else
281     skip "$0 : $OSTCOUNT < 2 OSTs, test 4 skipped"
282 fi 
283
284 #CMD_TEST_NUM=17.5
285 failover_pair OST clients "test 5: failover OST, then 2 clients ===="
286 sleep $FAILOVER_PERIOD
287
288 #CMD_TEST_NUM=17.6
289 failover_pair OST MDS     "test 6: failover OST, then MDS =========="
290 sleep $FAILOVER_PERIOD
291
292 #CMD_TEST_NUM=17.7
293 failover_pair clients MDS "test 7: failover 2 clients, then MDS ===="
294 sleep $FAILOVER_PERIOD
295
296 #CMD_TEST_NUM=17.8
297 #failover_pair clients OST "test 8: failover 2 clients, then OST ===="
298 sleep $FAILOVER_PERIOD
299
300 #CMD_TEST_NUM=17.9
301 if [ $CLIENTCOUNT -ge 5 ]; then
302     failover_pair clients clients "test 9: failover 2 clients, then 2 different clients =="
303     sleep $FAILOVER_PERIOD
304 fi
305 log "==== Checking the clients loads AFTER  all failovers -- failure NOT OK"
306 if ! check_client_loads $NODES_TO_USE; then
307     log "Client load failed after failover. Exiting"
308     exit 5
309 fi
310
311 CURRENT_TS=$(date +%s)
312 ELAPSED=$((CURRENT_TS - START_TS))
313
314 log "Completed successfully in $ELAPSED seconds"
315
316 exit 0