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