Whamcloud - gitweb
LU-11281 ptlrpc: race in AT early reply
[fs/lustre-release.git] / lustre / tests / insanity.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
4 #
5 # Test multiple failures, AKA Test 17
6
7 set -e
8
9 LUSTRE=${LUSTRE:-`dirname $0`/..}
10 . $LUSTRE/tests/test-framework.sh
11
12 init_test_env $@
13
14 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
15 init_logging
16 #              
17 ALWAYS_EXCEPT="15  $INSANITY_EXCEPT"
18
19 if [ "$FAILURE_MODE" = "HARD" ]; then
20         skip_env "$TESTSUITE: is not functional with FAILURE_MODE = HARD, " \
21                 "please use recovery-double-scale, bz20407"
22 fi
23
24 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
25
26 SETUP=${SETUP:-""}
27 CLEANUP=${CLEANUP:-""}
28
29 build_test_filter
30
31 SINGLECLIENT=${SINGLECLIENT:-$HOSTNAME}
32 LIVE_CLIENT=${LIVE_CLIENT:-$SINGLECLIENT}
33 FAIL_CLIENTS=${FAIL_CLIENTS:-$RCLIENTS}
34
35 assert_env mds_HOST MDSCOUNT
36 assert_env ost_HOST OSTCOUNT
37 assert_env LIVE_CLIENT FSNAME
38
39 require_dsh_mds || exit 0
40 require_dsh_ost || exit 0
41
42 # FAIL_CLIENTS list should not contain the LIVE_CLIENT
43 FAIL_CLIENTS=$(echo " $FAIL_CLIENTS " | sed -re "s/\s+$LIVE_CLIENT\s+/ /g")
44
45 DIR=${DIR:-$MOUNT}
46 TESTDIR=$DIR/d0.$TESTSUITE
47
48 #####
49 # fail clients round robin
50
51 # list of failable clients
52 FAIL_LIST=($FAIL_CLIENTS)
53 FAIL_NUM=${#FAIL_LIST[*]}
54 FAIL_NEXT=0
55 typeset -i  FAIL_NEXT
56 DOWN_NUM=0   # number of nodes currently down
57
58 # set next client to fail
59 set_fail_client() {
60     FAIL_CLIENT=${FAIL_LIST[$FAIL_NEXT]}
61     FAIL_NEXT=$(( (FAIL_NEXT+1) % FAIL_NUM ))
62     echo "fail $FAIL_CLIENT, next is $FAIL_NEXT"
63 }
64
65 fail_clients() {
66         num=$1
67
68         log "Request fail clients: $num, to fail: $FAIL_NUM, failed: $DOWN_NUM"
69         if [ -z "$num"  ] || [ "$num" -gt $((FAIL_NUM - DOWN_NUM)) ]; then
70                 num=$((FAIL_NUM - DOWN_NUM))
71         fi
72     
73     if [ -z "$num" ] || [ "$num" -le 0 ]; then
74         log "No clients failed!"
75         return
76     fi
77
78     client_mkdirs
79
80     for i in `seq $num`; do
81        set_fail_client
82        client=$FAIL_CLIENT
83        DOWN_CLIENTS="$DOWN_CLIENTS $client"
84        shutdown_client $client
85     done
86
87     echo "down clients: $DOWN_CLIENTS"
88
89         for client in $DOWN_CLIENTS; do
90                 boot_node $client
91         done
92         DOWN_NUM=`echo $DOWN_CLIENTS | wc -w`
93         client_rmdirs
94 }
95
96 reintegrate_clients() {
97         for client in $DOWN_CLIENTS; do
98                 wait_for_host $client
99                 echo "Restarting $client"
100                 zconf_mount $client $MOUNT || return 1
101         done
102
103         DOWN_CLIENTS=""
104         DOWN_NUM=0
105 }
106
107 start_ost() {
108         start ost$1 `ostdevname $1` $OST_MOUNT_OPTS
109 }
110
111 start_mdt() {
112         start mds$1 $(mdsdevname $1) $MDS_MOUNT_OPTS
113 }
114
115 trap exit INT
116
117 client_touch() {
118         file=$1
119         for c in $LIVE_CLIENT $FAIL_CLIENTS; do
120                 echo $DOWN_CLIENTS | grep -q $c && continue
121                 $PDSH $c touch $TESTDIR/${c}_$file || return 1
122         done
123 }
124
125 client_rm() {
126         file=$1
127         for c in $LIVE_CLIENT $FAIL_CLIENTS; do
128                 $PDSH $c rm $TESTDIR/${c}_$file
129         done
130 }
131
132 client_mkdirs() {
133         for c in $LIVE_CLIENT $FAIL_CLIENTS; do
134                 echo "$c mkdir $TESTDIR/$c"
135                 $PDSH $c "mkdir $TESTDIR/$c && ls -l $TESTDIR/$c"
136         done
137 }
138
139 client_rmdirs() {
140         for c in $LIVE_CLIENT $FAIL_CLIENTS; do
141                 echo "rmdir $TESTDIR/$c"
142                 $PDSH $LIVE_CLIENT "rmdir $TESTDIR/$c"
143         done
144 }
145
146 clients_recover_osts() {
147     facet=$1
148 #    do_node $CLIENTS "$LCTL "'--device %OSC_`hostname`_'"${facet}_svc_MNT_client_facet recover"
149 }
150
151 check_and_setup_lustre
152
153 rm -rf $TESTDIR
154 mkdir -p $TESTDIR
155
156 # 9 Different Failure Modes Combinations
157 echo "Starting Test 17 at `date`"
158
159 test_0() {
160         for i in $(seq $MDSCOUNT) ; do
161                 fail mds$i
162         done
163
164     for i in $(seq $OSTCOUNT) ; do
165         fail ost$i
166     done
167     return 0
168 }
169 run_test 0 "Fail all nodes, independently"
170
171 ############### First Failure Mode ###############
172 test_1() {
173         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
174
175         clients_up
176
177         shutdown_facet mds1
178         reboot_facet mds1
179
180         # prepare for MDS failover
181         change_active mds1
182         reboot_facet mds1
183
184         clients_up &
185         DFPID=$!
186         sleep 5
187
188         shutdown_facet mds2
189
190         echo "Reintegrating MDS2"
191         reboot_facet mds2
192         wait_for_facet mds2
193         start_mdt 2 || return 2
194
195         wait_for_facet mds1
196         start_mdt 1 || return $?
197
198         #Check FS
199         wait $DFPID
200         echo "Verify reintegration"
201         clients_up || return 1
202 }
203 run_test 1 "MDS/MDS failure"
204 ###################################################
205
206 ############### Second Failure Mode ###############
207 test_2() {
208         echo "Verify Lustre filesystem is up and running"
209         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
210
211         clients_up
212
213         for i in $(seq $MDSCOUNT) ; do
214                 shutdown_facet mds$i
215                 reboot_facet mds$i
216
217                 # prepare for MDS failover
218                 change_active mds$i
219                 reboot_facet mds$i
220         done
221
222     clients_up &
223     DFPID=$!
224     sleep 5
225
226     shutdown_facet ost1
227
228     echo "Reintegrating OST"
229     reboot_facet ost1
230     wait_for_facet ost1
231     start_ost 1 || return 2
232
233         for i in $(seq $MDSCOUNT) ; do
234                 wait_for_facet mds$i
235                 start_mdt $i || return $?
236         done
237
238     #Check FS
239     wait $DFPID
240     clients_recover_osts ost1
241     echo "Verify reintegration"
242     clients_up || return 1
243
244 }
245 run_test 2 "Second Failure Mode: MDS/OST `date`"
246 ###################################################
247
248 ############### Third Failure Mode ###############
249 test_3() {
250     #Create files
251     echo "Verify Lustre filesystem is up and running"
252     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
253
254     #MDS Portion
255         for i in $(seq $MDSCOUNT) ; do
256                 fail mds$i
257         done
258     #Check FS
259
260     echo "Test Lustre stability after MDS failover"
261     clients_up
262
263     #CLIENT Portion
264     echo "Failing 2 CLIENTS"
265     fail_clients 2
266     
267     #Check FS
268     echo "Test Lustre stability after CLIENT failure"
269     clients_up
270     
271     #Reintegration
272     echo "Reintegrating CLIENTS"
273     reintegrate_clients || return 1
274
275     clients_up || return 3
276     sleep 2 # give it a little time for fully recovered before next test
277 }
278 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
279 ###################################################
280
281 ############### Fourth Failure Mode ###############
282 test_4() {
283         echo "Fourth Failure Mode: OST/MDS `date`"
284
285     #OST Portion
286     shutdown_facet ost1
287
288     #Check FS
289     echo "Test Lustre stability after OST failure"
290     clients_up &
291     DFPIDA=$!
292     sleep 5
293
294         for i in $(seq $MDSCOUNT) ; do
295                 shutdown_facet mds$i
296                 reboot_facet mds$i
297
298                 # prepare for MDS failover
299                 change_active mds$i
300                 reboot_facet mds$i
301         done
302
303     clients_up &
304     DFPIDB=$!
305     sleep 5
306
307     #Reintegration
308     echo "Reintegrating OST"
309     reboot_facet ost1
310     wait_for_facet ost1
311     start_ost 1
312
313         for i in $(seq $MDSCOUNT) ; do
314                 wait_for_facet mds$i
315                 start_mdt $i || return $?
316         done
317     #Check FS
318
319     wait $DFPIDA
320     wait $DFPIDB
321     clients_recover_osts ost1
322     echo "Test Lustre stability after MDS failover"
323     clients_up || return 1
324 }
325 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
326 ###################################################
327
328 ############### Fifth Failure Mode ###############
329 test_5() {
330         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
331
332         echo "Fifth Failure Mode: OST/OST `date`"
333
334         #Create files
335         echo "Verify Lustre filesystem is up and running"
336         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
337
338         clients_up
339         #OST Portion
340         shutdown_facet ost1
341         reboot_facet ost1
342
343     #Check FS
344     echo "Test Lustre stability after OST failure"
345     clients_up &
346     DFPIDA=$!
347     sleep 5
348
349     #OST Portion
350     shutdown_facet ost2
351     reboot_facet ost2
352
353     #Check FS
354     echo "Test Lustre stability after OST failure"
355     clients_up &
356     DFPIDB=$!
357     sleep 5
358
359     #Reintegration
360     echo "Reintegrating OSTs"
361     wait_for_facet ost1
362     start_ost 1
363     wait_for_facet ost2
364     start_ost 2
365
366     clients_recover_osts ost1
367     clients_recover_osts ost2
368     sleep $TIMEOUT
369
370     wait $DFPIDA
371     wait $DFPIDB
372     clients_up || return 2
373 }
374 run_test 5 "Fifth Failure Mode: OST/OST `date`"
375 ###################################################
376
377 ############### Sixth Failure Mode ###############
378 test_6() {
379     echo "Sixth Failure Mode: OST/CLIENT `date`"
380
381     #Create files
382     echo "Verify Lustre filesystem is up and running"
383     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
384
385     clients_up
386     client_touch testfile || return 2
387         
388     #OST Portion
389     shutdown_facet ost1
390     reboot_facet ost1
391
392     #Check FS
393     echo "Test Lustre stability after OST failure"
394     clients_up &
395     DFPIDA=$!
396     echo DFPIDA=$DFPIDA
397     sleep 5
398
399     #CLIENT Portion
400     echo "Failing CLIENTs"
401     fail_clients
402     
403     #Check FS
404     echo "Test Lustre stability after CLIENTs failure"
405     clients_up &
406     DFPIDB=$!
407     echo DFPIDB=$DFPIDB
408     sleep 5
409     
410     #Reintegration
411     echo "Reintegrating OST/CLIENTs"
412     wait_for_facet ost1
413     start_ost 1
414     reintegrate_clients || return 1
415     sleep 5 
416
417     wait_remote_prog "stat -f" $((TIMEOUT * 3 + 20)) 
418     wait $DFPIDA
419     wait $DFPIDB
420
421     echo "Verifying mount"
422     [ -z "$(mounted_lustre_filesystems)" ] && return 3
423     clients_up
424 }
425 run_test 6 "Sixth Failure Mode: OST/CLIENT `date`"
426 ###################################################
427
428
429 ############### Seventh Failure Mode ###############
430 test_7() {
431     echo "Seventh Failure Mode: CLIENT/MDS `date`"
432
433     #Create files
434     echo "Verify Lustre filesystem is up and running"
435     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
436
437     clients_up
438     client_touch testfile  || return 1
439
440     #CLIENT Portion
441     echo "Part 1: Failing CLIENT"
442     fail_clients 2
443     
444     #Check FS
445     echo "Test Lustre stability after CLIENTs failure"
446     clients_up
447     $PDSH $LIVE_CLIENT "ls -l $TESTDIR"
448     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
449     
450     #Sleep
451     echo "Wait 1 minutes"
452     sleep 60
453
454     #Create files
455     echo "Verify Lustre filesystem is up and running"
456     [ -z "$(mounted_lustre_filesystems)" ] && return 2
457
458     clients_up
459     client_rm testfile
460
461     #MDS Portion
462         for i in $(seq $MDSCOUNT) ; do
463                 fail mds$i
464         done
465
466     $PDSH $LIVE_CLIENT "ls -l $TESTDIR"
467     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
468
469     #Reintegration
470     echo "Reintegrating CLIENTs"
471     reintegrate_clients || return 2
472     clients_up
473     
474     #Sleep
475     echo "wait 1 minutes"
476     sleep 60
477 }
478 run_test 7 "Seventh Failure Mode: CLIENT/MDS `date`"
479 ###################################################
480
481
482 ############### Eighth Failure Mode ###############
483 test_8() {
484     echo "Eighth Failure Mode: CLIENT/OST `date`"
485
486     #Create files
487     echo "Verify Lustre filesystem is up and running"
488     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
489
490     clients_up
491     client_touch testfile
492         
493     #CLIENT Portion
494     echo "Failing CLIENTs"
495     fail_clients 2
496
497     #Check FS
498     echo "Test Lustre stability after CLIENTs failure"
499     clients_up
500     $PDSH $LIVE_CLIENT "ls -l $TESTDIR"
501     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
502
503     #Sleep
504     echo "Wait 1 minutes"
505     sleep 60
506
507     #Create files
508     echo "Verify Lustre filesystem is up and running"
509     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
510
511     clients_up
512     client_touch testfile
513
514
515     #OST Portion
516     shutdown_facet ost1
517     reboot_facet ost1
518
519     #Check FS
520     echo "Test Lustre stability after OST failure"
521     clients_up &
522     DFPID=$!
523     sleep 5
524     #non-failout hangs forever here
525     #$PDSH $LIVE_CLIENT "ls -l $TESTDIR"
526     #$PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
527     
528     #Reintegration
529     echo "Reintegrating CLIENTs/OST"
530     reintegrate_clients || return 3
531     wait_for_facet ost1
532     start_ost 1
533     wait $DFPID
534     clients_up || return 1
535     client_touch testfile2 || return 2
536
537     #Sleep
538     echo "Wait 1 minutes"
539     sleep 60
540 }
541 run_test 8 "Eighth Failure Mode: CLIENT/OST `date`"
542 ###################################################
543
544
545 ############### Ninth Failure Mode ###############
546 test_9() {
547     echo 
548
549     #Create files
550     echo "Verify Lustre filesystem is up and running"
551     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
552
553     clients_up
554     client_touch testfile || return 1
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     clients_up
563     $PDSH $LIVE_CLIENT "ls -l $TESTDIR" || return 1
564     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile" || return 2
565
566     #Sleep
567     echo "Wait 1 minutes"
568     sleep 60
569
570     #Create files
571     echo "Verify Lustre filesystem is up and running"
572     client_up $LIVE_CLIENT || return 3
573     client_touch testfile || return 4
574
575     #CLIENT Portion
576     echo "Failing CLIENTs"
577     fail_clients 2
578     
579     #Check FS
580     echo "Test Lustre stability after CLIENTs failure"
581     clients_up
582     $PDSH $LIVE_CLIENT "ls -l $TESTDIR" || return 5
583     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile" || return 6
584
585     #Reintegration
586     echo "Reintegrating  CLIENTs/CLIENTs"
587     reintegrate_clients || return 7
588     clients_up
589     
590     #Sleep
591     echo "Wait 1 minutes"
592     sleep 60
593 }
594 run_test 9 "Ninth Failure Mode: CLIENT/CLIENT `date`"
595 ###################################################
596
597 ############### Tenth Failure Mode ###############
598 test_10() {
599         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
600
601         shutdown_facet mds1
602         reboot_facet mds1
603
604         # prepare for MDS failover
605         change_active mds1
606         reboot_facet mds1
607
608         clients_up &
609         DFPID=$!
610         sleep 5
611
612         shutdown_facet ost1
613
614         echo "Reintegrating OST"
615         reboot_facet ost1
616         wait_for_facet ost1
617         start_ost 1 || return 2
618
619         shutdown_facet mds2
620         reboot_facet mds2
621
622         # prepare for MDS failover
623         change_active mds2
624         reboot_facet mds2
625
626         wait_for_facet mds1
627         start_mdt 1 || return $?
628
629         wait_for_facet mds2
630         start_mdt 2 || return $?
631
632         #Check FS
633         wait $DFPID
634         clients_recover_osts ost1
635         echo "Verify reintegration"
636         clients_up || return 1
637 }
638 run_test 10 "Tenth Failure Mode: MDT0/OST/MDT1 `date`"
639 ###################################################
640
641 ############### Seventh Failure Mode ###############
642 test_11() {
643         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
644         echo "Verify Lustre filesystem is up and running"
645         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
646
647         #MDS Portion
648         fail mds1
649         #Check FS
650
651         echo "Test Lustre stability after MDS failover"
652         clients_up
653
654         #CLIENT Portion
655         echo "Failing 2 CLIENTS"
656         fail_clients 2
657
658         #Check FS
659         echo "Test Lustre stability after CLIENT failure"
660         clients_up
661
662         #Reintegration
663         echo "Reintegrating CLIENTS"
664         reintegrate_clients || return 1
665
666         fail mds2
667
668         clients_up || return 3
669         sleep 2 # give it a little time for fully recovered before next test
670 }
671 run_test 11 "Eleventh Failure Mode: MDS0/CLIENT/MDS1 `date`"
672 ###################################################
673
674 test_12() {
675         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
676         echo "Verify Lustre filesystem is up and running"
677         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
678
679         #MDS Portion
680         fail mds1,mds2
681         clients_up
682
683         #OSS Portion
684         fail ost1,ost2
685         clients_up
686
687         #CLIENT Portion
688         echo "Failing 2 CLIENTS"
689         fail_clients 2
690
691         #Check FS
692         echo "Test Lustre stability after CLIENT failure"
693         clients_up
694
695         #Reintegration
696         echo "Reintegrating CLIENTS"
697         reintegrate_clients || return 1
698
699         clients_up || return 3
700         sleep 2 # give it a little time for fully recovered before next test
701 }
702 run_test 12 "Twelve Failure Mode: MDS0,MDS1/OST0, OST1/CLIENTS `date`"
703 ###################################################
704
705 test_13() {
706         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
707         echo "Verify Lustre filesystem is up and running"
708         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
709
710         #MDS Portion
711         fail mds1,mds2
712         clients_up
713
714         #CLIENT Portion
715         echo "Failing 2 CLIENTS"
716         fail_clients 2
717
718         #Check FS
719         echo "Test Lustre stability after CLIENT failure"
720         clients_up
721
722         #Reintegration
723         echo "Reintegrating CLIENTS"
724         reintegrate_clients || return 1
725
726         clients_up || return 3
727         sleep 2 # give it a little time for fully recovered before next test
728
729         #OSS Portion
730         fail ost1,ost2
731         clients_up || return 4
732 }
733 run_test 13 "Thirteen Failure Mode: MDS0,MDS1/CLIENTS/OST0,OST1 `date`"
734 ###################################################
735
736 test_14() {
737         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
738         echo "Verify Lustre filesystem is up and running"
739         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
740
741         #OST Portion
742         fail ost1,ost2
743         clients_up
744
745         #CLIENT Portion
746         echo "Failing 2 CLIENTS"
747         fail_clients 2
748
749         #Check FS
750         echo "Test Lustre stability after CLIENT failure"
751         clients_up
752
753         #Reintegration
754         echo "Reintegrating CLIENTS"
755         reintegrate_clients || return 1
756
757         clients_up || return 3
758         sleep 2 # give it a little time for fully recovered before next test
759
760         #OSS Portion
761         fail mds1,mds2
762         clients_up || return 4
763 }
764 run_test 14 "Fourteen Failure Mode: OST0,OST1/CLIENTS/MDS0,MDS1 `date`"
765 ###################################################
766
767 test_15() {
768     #Run availability after all failures
769     DURATION=${DURATION:-$((2 * 60 * 60))} # 6 hours default
770     LOADTEST=${LOADTEST:-metadata-load.py}
771     $PWD/availability.sh $CONFIG $DURATION $CLIENTS || return 1
772 }
773 run_test 15 "Running Availability for 6 hours..."
774
775 complete $SECONDS
776 check_and_cleanup_lustre
777 exit_status