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