Whamcloud - gitweb
b=17310
[fs/lustre-release.git] / lustre / tests / insanity.sh
1 #!/bin/sh
2 # Test multiple failures, AKA Test 17
3
4 set -e
5
6 LUSTRE=${LUSTRE:-`dirname $0`/..}
7 . $LUSTRE/tests/test-framework.sh
8
9 init_test_env $@
10
11 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
12 #              
13 ALWAYS_EXCEPT="10  $INSANITY_EXCEPT"
14
15 if [ "$FAILURE_MODE" = "HARD" ]; then
16     mixed_ost_devs && CONFIG_EXCEPTIONS="0 2 4 5 6 8" && \
17         echo -n "Several ost services on one ost node are used with FAILURE_MODE=$FAILURE_MODE. " && \
18         echo "Except the tests: $CONFIG_EXCEPTIONS" && \
19         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
20 fi
21
22 #
23 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
24
25 SETUP=${SETUP:-""}
26 CLEANUP=${CLEANUP:-""}
27
28 build_test_filter
29
30 SINGLECLIENT=${SINGLECLIENT:-$HOSTNAME}
31 LIVE_CLIENT=${LIVE_CLIENT:-$SINGLECLIENT}
32 FAIL_CLIENTS=${FAIL_CLIENTS:-$RCLIENTS}
33
34 assert_env mds_HOST MDS_MKFS_OPTS
35 assert_env ost_HOST OST_MKFS_OPTS OSTCOUNT
36 assert_env LIVE_CLIENT FSNAME
37
38 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
39 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
40
41 # FAIL_CLIENTS list should not contain the LIVE_CLIENT
42 FAIL_CLIENTS=$(echo " $FAIL_CLIENTS " | sed -re "s/\s+$LIVE_CLIENT\s+/ /g")
43
44 DIR=${DIR:-$MOUNT}
45
46 #####
47 # fail clients round robin
48
49 # list of failable clients
50 FAIL_LIST=($FAIL_CLIENTS)
51 FAIL_NUM=${#FAIL_LIST[*]}
52 FAIL_NEXT=0
53 typeset -i  FAIL_NEXT
54 DOWN_NUM=0   # number of nodes currently down
55
56 # set next client to fail
57 set_fail_client() {
58     FAIL_CLIENT=${FAIL_LIST[$FAIL_NEXT]}
59     FAIL_NEXT=$(( (FAIL_NEXT+1) % FAIL_NUM ))
60     echo "fail $FAIL_CLIENT, next is $FAIL_NEXT"
61 }
62
63 shutdown_client() {
64     client=$1
65     if [ "$FAILURE_MODE" = HARD ]; then
66        $POWER_DOWN $client
67        while ping -w 3 -c 1 $client > /dev/null 2>&1; do 
68            echo "waiting for node $client to fail"
69            sleep 1
70        done  
71     elif [ "$FAILURE_MODE" = SOFT ]; then
72        zconf_umount $client $MOUNT -f
73     fi
74 }
75
76 reboot_node() {
77     NODE=$1
78     if [ "$FAILURE_MODE" = HARD ]; then
79        $POWER_UP $NODE
80     fi
81 }
82
83 fail_clients() {
84     num=$1
85
86     log "Request clients to fail: ${num}. Num of clients to fail: ${FAIL_NUM}, already failed: $DOWN_NUM"
87     if [ -z "$num"  ] || [ "$num" -gt $((FAIL_NUM - DOWN_NUM)) ]; then
88         num=$((FAIL_NUM - DOWN_NUM)) 
89     fi
90     
91     if [ -z "$num" ] || [ "$num" -le 0 ]; then
92         log "No clients failed!"
93         return
94     fi
95
96     client_mkdirs
97
98     for i in `seq $num`; do
99        set_fail_client
100        client=$FAIL_CLIENT
101        DOWN_CLIENTS="$DOWN_CLIENTS $client"
102        shutdown_client $client
103     done
104
105     echo "down clients: $DOWN_CLIENTS"
106
107     for client in $DOWN_CLIENTS; do
108         reboot_node $client
109     done
110     DOWN_NUM=`echo $DOWN_CLIENTS | wc -w`
111     client_rmdirs
112 }
113
114 reintegrate_clients() {
115     for client in $DOWN_CLIENTS; do
116         wait_for_host $client
117         echo "Restarting $client"
118         zconf_mount $client $MOUNT || return 1
119     done
120     DOWN_CLIENTS=""
121     DOWN_NUM=0
122 }
123
124 start_ost() {
125     start ost$1 `ostdevname $1` $OST_MOUNT_OPTS
126 }
127
128 trap exit INT
129
130 client_touch() {
131     file=$1
132     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
133         if echo $DOWN_CLIENTS | grep -q $c; then continue; fi
134         $PDSH $c touch $MOUNT/${c}_$file || return 1
135     done
136 }
137
138 client_rm() {
139     file=$1
140     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
141         $PDSH $c rm $MOUNT/${c}_$file
142     done
143 }
144
145 client_mkdirs() {
146     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
147         echo "$c mkdir $MOUNT/$c"
148         $PDSH $c "mkdir $MOUNT/$c"
149         $PDSH $c "ls -l $MOUNT/$c" 
150     done
151 }
152
153 client_rmdirs() {
154     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
155         echo "rmdir $MOUNT/$c"
156         $PDSH $LIVE_CLIENT "rmdir $MOUNT/$c"
157     done
158 }
159
160 clients_recover_osts() {
161     facet=$1
162 #    do_node $CLIENTS "$LCTL "'--device %OSC_`hostname`_'"${facet}_svc_MNT_client_facet recover"
163 }
164
165 check_and_setup_lustre
166
167 # 9 Different Failure Modes Combinations
168 echo "Starting Test 17 at `date`"
169
170 test_0() {
171     facet_failover $SINGLEMDS
172     echo "Waiting for df pid: $DFPID"
173     wait $DFPID || { echo "df returned $?" && return 1; }
174
175     for i in $(seq $OSTCOUNT) ; do
176         facet_failover ost$i || return 4
177         echo "Waiting for df pid: $DFPID"
178         wait $DFPID || { echo "df returned $?" && return 3; }
179     done
180     return 0
181 }
182 run_test 0 "Fail all nodes, independently"
183
184 ############### First Failure Mode ###############
185 test_1() {
186 echo "Don't do a MDS - MDS Failure Case"
187 echo "This makes no sense"
188 }
189 run_test 1 "MDS/MDS failure"
190 ###################################################
191
192 ############### Second Failure Mode ###############
193 test_2() {
194     echo "Verify Lustre filesystem is up and running"
195     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
196
197     client_df
198
199     shutdown_facet $SINGLEMDS
200     reboot_facet $SINGLEMDS
201
202     # prepare for MDS failover
203     change_active $SINGLEMDS
204     reboot_facet $SINGLEMDS
205
206     client_df &
207     DFPID=$!
208     sleep 5
209
210     shutdown_facet ost1
211
212     echo "Reintegrating OST"
213     reboot_facet ost1
214     wait_for ost1
215     start_ost 1 || return 2
216
217     wait_for $SINGLEMDS
218     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS || return $?
219
220     #Check FS
221     wait $DFPID
222     clients_recover_osts ost1
223     echo "Verify reintegration"
224     client_df || return 1
225
226 }
227 run_test 2 "Second Failure Mode: MDS/OST `date`"
228 ###################################################
229
230
231 ############### Third Failure Mode ###############
232 test_3() {
233     #Create files
234     echo "Verify Lustre filesystem is up and running"
235     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
236     
237     #MDS Portion
238     facet_failover $SINGLEMDS
239     wait $DFPID || echo df failed: $?
240     #Check FS
241
242     echo "Test Lustre stability after MDS failover"
243     client_df
244
245     #CLIENT Portion
246     echo "Failing 2 CLIENTS"
247     fail_clients 2
248     
249     #Check FS
250     echo "Test Lustre stability after CLIENT failure"
251     client_df
252     
253     #Reintegration
254     echo "Reintegrating CLIENTS"
255     reintegrate_clients || return 1
256
257     client_df || return 3
258     sleep 2 # give it a little time for fully recovered before next test
259 }
260 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
261 ###################################################
262
263 ############### Fourth Failure Mode ###############
264 test_4() {
265     echo "Fourth Failure Mode: OST/MDS `date`"
266
267     #OST Portion
268     shutdown_facet ost1
269  
270     #Check FS
271     echo "Test Lustre stability after OST failure"
272     client_df &
273     DFPIDA=$!
274     sleep 5
275
276     #MDS Portion
277     shutdown_facet $SINGLEMDS
278     reboot_facet $SINGLEMDS
279
280     # prepare for MDS failover
281     change_active $SINGLEMDS
282     reboot_facet $SINGLEMDS
283
284     client_df &
285     DFPIDB=$!
286     sleep 5
287
288     #Reintegration
289     echo "Reintegrating OST"
290     reboot_facet ost1
291     wait_for ost1
292     start_ost 1
293     
294     wait_for $SINGLEMDS
295     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS
296     #Check FS
297     
298     wait $DFPIDA
299     wait $DFPIDB
300     clients_recover_osts ost1
301     echo "Test Lustre stability after MDS failover"
302     client_df || return 1
303 }
304 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
305 ###################################################
306
307 ############### Fifth Failure Mode ###############
308 test_5() {
309     [ $OSTCOUNT -lt 2 ] && skip "$OSTCOUNT < 2, not enough OSTs" && return 0
310
311     echo "Fifth Failure Mode: OST/OST `date`"
312
313     #Create files
314     echo "Verify Lustre filesystem is up and running"
315     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
316
317     client_df
318     
319     #OST Portion
320     shutdown_facet ost1
321     reboot_facet ost1
322     
323     #Check FS
324     echo "Test Lustre stability after OST failure"
325     client_df &
326     DFPIDA=$!
327     sleep 5
328     
329     #OST Portion
330     shutdown_facet ost2
331     reboot_facet ost2
332
333     #Check FS
334     echo "Test Lustre stability after OST failure"
335     client_df &
336     DFPIDB=$!
337     sleep 5
338
339     #Reintegration
340     echo "Reintegrating OSTs"
341     wait_for ost1
342     start_ost 1
343     wait_for ost2
344     start_ost 2
345     
346     clients_recover_osts ost1
347     clients_recover_osts ost2
348     sleep $TIMEOUT
349
350     wait $DFPIDA
351     wait $DFPIDB
352     client_df || return 2
353 }
354 run_test 5 "Fifth Failure Mode: OST/OST `date`"
355 ###################################################
356
357 ############### Sixth Failure Mode ###############
358 test_6() {
359     echo "Sixth Failure Mode: OST/CLIENT `date`"
360
361     #Create files
362     echo "Verify Lustre filesystem is up and running"
363     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
364
365     client_df
366     client_touch testfile || return 2
367         
368     #OST Portion
369     shutdown_facet ost1
370     reboot_facet ost1
371
372     #Check FS
373     echo "Test Lustre stability after OST failure"
374     client_df &
375     DFPIDA=$!
376     echo DFPIDA=$DFPIDA
377     sleep 5
378
379     #CLIENT Portion
380     echo "Failing CLIENTs"
381     fail_clients
382     
383     #Check FS
384     echo "Test Lustre stability after CLIENTs failure"
385     client_df &
386     DFPIDB=$!
387     echo DFPIDB=$DFPIDB
388     sleep 5
389     
390     #Reintegration
391     echo "Reintegrating OST/CLIENTs"
392     wait_for ost1
393     start_ost 1
394     reintegrate_clients || return 1
395     sleep 5 
396
397     wait_remote_prog df $((TIMEOUT * 3 + 10)) 
398     wait $DFPIDA
399     wait $DFPIDB
400
401     echo "Verifying mount"
402     [ -z "$(mounted_lustre_filesystems)" ] && return 3
403     client_df
404 }
405 run_test 6 "Sixth Failure Mode: OST/CLIENT `date`"
406 ###################################################
407
408
409 ############### Seventh Failure Mode ###############
410 test_7() {
411     echo "Seventh Failure Mode: CLIENT/MDS `date`"
412
413     #Create files
414     echo "Verify Lustre filesystem is up and running"
415     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
416
417     client_df
418     client_touch testfile  || return 1
419
420     #CLIENT Portion
421     echo "Part 1: Failing CLIENT"
422     fail_clients 2
423     
424     #Check FS
425     echo "Test Lustre stability after CLIENTs failure"
426     client_df
427     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
428     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
429     
430     #Sleep
431     echo "Wait 1 minutes"
432     sleep 60
433
434     #Create files
435     echo "Verify Lustre filesystem is up and running"
436     [ -z "$(mounted_lustre_filesystems)" ] && return 2
437
438     client_df
439     client_rm testfile
440
441     #MDS Portion
442     facet_failover $SINGLEMDS
443
444     #Check FS
445     echo "Test Lustre stability after MDS failover"
446     wait $DFPID || echo "df on down clients fails " || return 1
447     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
448     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
449
450     #Reintegration
451     echo "Reintegrating CLIENTs"
452     reintegrate_clients || return 2
453     client_df
454     
455     #Sleep
456     echo "wait 1 minutes"
457     sleep 60
458 }
459 run_test 7 "Seventh Failure Mode: CLIENT/MDS `date`"
460 ###################################################
461
462
463 ############### Eighth Failure Mode ###############
464 test_8() {
465     echo "Eighth Failure Mode: CLIENT/OST `date`"
466
467     #Create files
468     echo "Verify Lustre filesystem is up and running"
469     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
470
471     client_df
472     client_touch testfile
473         
474     #CLIENT Portion
475     echo "Failing CLIENTs"
476     fail_clients 2
477
478     #Check FS
479     echo "Test Lustre stability after CLIENTs failure"
480     client_df
481     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
482     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
483
484     #Sleep
485     echo "Wait 1 minutes"
486     sleep 60
487
488     #Create files
489     echo "Verify Lustre filesystem is up and running"
490     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
491
492     client_df
493     client_touch testfile
494
495
496     #OST Portion
497     shutdown_facet ost1
498     reboot_facet ost1
499
500     #Check FS
501     echo "Test Lustre stability after OST failure"
502     client_df &
503     DFPID=$!
504     sleep 5
505     #non-failout hangs forever here
506     #$PDSH $LIVE_CLIENT "ls -l $MOUNT"
507     #$PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
508     
509     #Reintegration
510     echo "Reintegrating CLIENTs/OST"
511     reintegrate_clients || return 3
512     wait_for ost1
513     start_ost 1
514     wait $DFPID
515     client_df || return 1
516     client_touch testfile2 || return 2
517
518     #Sleep
519     echo "Wait 1 minutes"
520     sleep 60
521 }
522 run_test 8 "Eighth Failure Mode: CLIENT/OST `date`"
523 ###################################################
524
525
526 ############### Ninth Failure Mode ###############
527 test_9() {
528     echo 
529
530     #Create files
531     echo "Verify Lustre filesystem is up and running"
532     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
533
534     client_df
535     client_touch testfile || return 1
536         
537     #CLIENT Portion
538     echo "Failing CLIENTs"
539     fail_clients 2
540
541     #Check FS
542     echo "Test Lustre stability after CLIENTs failure"
543     client_df
544     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 1
545     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 2
546
547     #Sleep
548     echo "Wait 1 minutes"
549     sleep 60
550
551     #Create files
552     echo "Verify Lustre filesystem is up and running"
553     $PDSH $LIVE_CLIENT df $MOUNT || return 3
554     client_touch testfile || return 4
555
556     #CLIENT Portion
557     echo "Failing CLIENTs"
558     fail_clients 2
559     
560     #Check FS
561     echo "Test Lustre stability after CLIENTs failure"
562     client_df
563     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 5
564     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 6
565
566     #Reintegration
567     echo "Reintegrating  CLIENTs/CLIENTs"
568     reintegrate_clients || return 7
569     client_df
570     
571     #Sleep
572     echo "Wait 1 minutes"
573     sleep 60
574 }
575 run_test 9 "Ninth Failure Mode: CLIENT/CLIENT `date`"
576 ###################################################
577
578 test_10() {
579     #Run availability after all failures
580     DURATION=${DURATION:-$((2 * 60 * 60))} # 6 hours default
581     LOADTEST=${LOADTEST:-metadata-load.py}
582     $PWD/availability.sh $CONFIG $DURATION $CLIENTS || return 1
583 }
584 run_test 10 "Running Availability for 6 hours..."
585
586 equals_msg `basename $0`: test complete, cleaning up
587 check_and_cleanup_lustre
588 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true