Whamcloud - gitweb
LU-4218 tests: fix for facet_host()
[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         [ "$(facet_fstype mds2)" = "zfs" ] &&
177                 skip "LU-2059: no local config for ZFS MDTs" && return
178
179         clients_up
180
181         shutdown_facet mds1
182         reboot_facet mds1
183
184         # prepare for MDS failover
185         change_active mds1
186         reboot_facet mds1
187
188         clients_up &
189         DFPID=$!
190         sleep 5
191
192         shutdown_facet mds2
193
194         echo "Reintegrating MDS2"
195         reboot_facet mds2
196         wait_for_facet mds2
197         start_mdt 2 || return 2
198
199         wait_for_facet mds1
200         start_mdt 1 || return $?
201
202         #Check FS
203         wait $DFPID
204         echo "Verify reintegration"
205         clients_up || return 1
206 }
207 run_test 1 "MDS/MDS failure"
208 ###################################################
209
210 ############### Second Failure Mode ###############
211 test_2() {
212         echo "Verify Lustre filesystem is up and running"
213         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
214
215         [ "$(facet_fstype ost1)" = "zfs" ] &&
216                 skip "LU-2059: no local config for ZFS OSTs" && return
217
218     clients_up
219
220         for i in $(seq $MDSCOUNT) ; do
221                 shutdown_facet mds$i
222                 reboot_facet mds$i
223
224                 # prepare for MDS failover
225                 change_active mds$i
226                 reboot_facet mds$i
227         done
228
229     clients_up &
230     DFPID=$!
231     sleep 5
232
233     shutdown_facet ost1
234
235     echo "Reintegrating OST"
236     reboot_facet ost1
237     wait_for_facet ost1
238     start_ost 1 || return 2
239
240         for i in $(seq $MDSCOUNT) ; do
241                 wait_for_facet mds$i
242                 start_mdt $i || return $?
243         done
244
245     #Check FS
246     wait $DFPID
247     clients_recover_osts ost1
248     echo "Verify reintegration"
249     clients_up || return 1
250
251 }
252 run_test 2 "Second Failure Mode: MDS/OST `date`"
253 ###################################################
254
255 ############### Third Failure Mode ###############
256 test_3() {
257     #Create files
258     echo "Verify Lustre filesystem is up and running"
259     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
260
261     #MDS Portion
262         for i in $(seq $MDSCOUNT) ; do
263                 fail mds$i
264         done
265     #Check FS
266
267     echo "Test Lustre stability after MDS failover"
268     clients_up
269
270     #CLIENT Portion
271     echo "Failing 2 CLIENTS"
272     fail_clients 2
273     
274     #Check FS
275     echo "Test Lustre stability after CLIENT failure"
276     clients_up
277     
278     #Reintegration
279     echo "Reintegrating CLIENTS"
280     reintegrate_clients || return 1
281
282     clients_up || return 3
283     sleep 2 # give it a little time for fully recovered before next test
284 }
285 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
286 ###################################################
287
288 ############### Fourth Failure Mode ###############
289 test_4() {
290         echo "Fourth Failure Mode: OST/MDS `date`"
291
292         [ "$(facet_fstype ost1)" = "zfs" ] &&
293                 skip "LU-2059: no local config for ZFS OSTs" && return
294
295     #OST Portion
296     shutdown_facet ost1
297
298     #Check FS
299     echo "Test Lustre stability after OST failure"
300     clients_up &
301     DFPIDA=$!
302     sleep 5
303
304         for i in $(seq $MDSCOUNT) ; do
305                 shutdown_facet mds$i
306                 reboot_facet mds$i
307
308                 # prepare for MDS failover
309                 change_active mds$i
310                 reboot_facet mds$i
311         done
312
313     clients_up &
314     DFPIDB=$!
315     sleep 5
316
317     #Reintegration
318     echo "Reintegrating OST"
319     reboot_facet ost1
320     wait_for_facet ost1
321     start_ost 1
322
323         for i in $(seq $MDSCOUNT) ; do
324                 wait_for_facet mds$i
325                 start_mdt $i || return $?
326         done
327     #Check FS
328
329     wait $DFPIDA
330     wait $DFPIDB
331     clients_recover_osts ost1
332     echo "Test Lustre stability after MDS failover"
333     clients_up || return 1
334 }
335 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
336 ###################################################
337
338 ############### Fifth Failure Mode ###############
339 test_5() {
340     [ $OSTCOUNT -lt 2 ] && skip_env "$OSTCOUNT < 2, not enough OSTs" && return 0
341
342     echo "Fifth Failure Mode: OST/OST `date`"
343
344     #Create files
345     echo "Verify Lustre filesystem is up and running"
346     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
347
348     clients_up
349     
350     #OST Portion
351     shutdown_facet ost1
352     reboot_facet ost1
353     
354     #Check FS
355     echo "Test Lustre stability after OST failure"
356     clients_up &
357     DFPIDA=$!
358     sleep 5
359     
360     #OST Portion
361     shutdown_facet ost2
362     reboot_facet ost2
363
364     #Check FS
365     echo "Test Lustre stability after OST failure"
366     clients_up &
367     DFPIDB=$!
368     sleep 5
369
370     #Reintegration
371     echo "Reintegrating OSTs"
372     wait_for_facet ost1
373     start_ost 1
374     wait_for_facet ost2
375     start_ost 2
376     
377     clients_recover_osts ost1
378     clients_recover_osts ost2
379     sleep $TIMEOUT
380
381     wait $DFPIDA
382     wait $DFPIDB
383     clients_up || return 2
384 }
385 run_test 5 "Fifth Failure Mode: OST/OST `date`"
386 ###################################################
387
388 ############### Sixth Failure Mode ###############
389 test_6() {
390     echo "Sixth Failure Mode: OST/CLIENT `date`"
391
392     #Create files
393     echo "Verify Lustre filesystem is up and running"
394     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
395
396     clients_up
397     client_touch testfile || return 2
398         
399     #OST Portion
400     shutdown_facet ost1
401     reboot_facet ost1
402
403     #Check FS
404     echo "Test Lustre stability after OST failure"
405     clients_up &
406     DFPIDA=$!
407     echo DFPIDA=$DFPIDA
408     sleep 5
409
410     #CLIENT Portion
411     echo "Failing CLIENTs"
412     fail_clients
413     
414     #Check FS
415     echo "Test Lustre stability after CLIENTs failure"
416     clients_up &
417     DFPIDB=$!
418     echo DFPIDB=$DFPIDB
419     sleep 5
420     
421     #Reintegration
422     echo "Reintegrating OST/CLIENTs"
423     wait_for_facet ost1
424     start_ost 1
425     reintegrate_clients || return 1
426     sleep 5 
427
428     wait_remote_prog "stat -f" $((TIMEOUT * 3 + 20)) 
429     wait $DFPIDA
430     wait $DFPIDB
431
432     echo "Verifying mount"
433     [ -z "$(mounted_lustre_filesystems)" ] && return 3
434     clients_up
435 }
436 run_test 6 "Sixth Failure Mode: OST/CLIENT `date`"
437 ###################################################
438
439
440 ############### Seventh Failure Mode ###############
441 test_7() {
442     echo "Seventh Failure Mode: CLIENT/MDS `date`"
443
444     #Create files
445     echo "Verify Lustre filesystem is up and running"
446     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
447
448     clients_up
449     client_touch testfile  || return 1
450
451     #CLIENT Portion
452     echo "Part 1: Failing CLIENT"
453     fail_clients 2
454     
455     #Check FS
456     echo "Test Lustre stability after CLIENTs failure"
457     clients_up
458     $PDSH $LIVE_CLIENT "ls -l $TESTDIR"
459     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
460     
461     #Sleep
462     echo "Wait 1 minutes"
463     sleep 60
464
465     #Create files
466     echo "Verify Lustre filesystem is up and running"
467     [ -z "$(mounted_lustre_filesystems)" ] && return 2
468
469     clients_up
470     client_rm testfile
471
472     #MDS Portion
473         for i in $(seq $MDSCOUNT) ; do
474                 fail mds$i
475         done
476
477     $PDSH $LIVE_CLIENT "ls -l $TESTDIR"
478     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
479
480     #Reintegration
481     echo "Reintegrating CLIENTs"
482     reintegrate_clients || return 2
483     clients_up
484     
485     #Sleep
486     echo "wait 1 minutes"
487     sleep 60
488 }
489 run_test 7 "Seventh Failure Mode: CLIENT/MDS `date`"
490 ###################################################
491
492
493 ############### Eighth Failure Mode ###############
494 test_8() {
495     echo "Eighth Failure Mode: CLIENT/OST `date`"
496
497     #Create files
498     echo "Verify Lustre filesystem is up and running"
499     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
500
501     clients_up
502     client_touch testfile
503         
504     #CLIENT Portion
505     echo "Failing CLIENTs"
506     fail_clients 2
507
508     #Check FS
509     echo "Test Lustre stability after CLIENTs failure"
510     clients_up
511     $PDSH $LIVE_CLIENT "ls -l $TESTDIR"
512     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
513
514     #Sleep
515     echo "Wait 1 minutes"
516     sleep 60
517
518     #Create files
519     echo "Verify Lustre filesystem is up and running"
520     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
521
522     clients_up
523     client_touch testfile
524
525
526     #OST Portion
527     shutdown_facet ost1
528     reboot_facet ost1
529
530     #Check FS
531     echo "Test Lustre stability after OST failure"
532     clients_up &
533     DFPID=$!
534     sleep 5
535     #non-failout hangs forever here
536     #$PDSH $LIVE_CLIENT "ls -l $TESTDIR"
537     #$PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile"
538     
539     #Reintegration
540     echo "Reintegrating CLIENTs/OST"
541     reintegrate_clients || return 3
542     wait_for_facet ost1
543     start_ost 1
544     wait $DFPID
545     clients_up || return 1
546     client_touch testfile2 || return 2
547
548     #Sleep
549     echo "Wait 1 minutes"
550     sleep 60
551 }
552 run_test 8 "Eighth Failure Mode: CLIENT/OST `date`"
553 ###################################################
554
555
556 ############### Ninth Failure Mode ###############
557 test_9() {
558     echo 
559
560     #Create files
561     echo "Verify Lustre filesystem is up and running"
562     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
563
564     clients_up
565     client_touch testfile || return 1
566         
567     #CLIENT Portion
568     echo "Failing CLIENTs"
569     fail_clients 2
570
571     #Check FS
572     echo "Test Lustre stability after CLIENTs failure"
573     clients_up
574     $PDSH $LIVE_CLIENT "ls -l $TESTDIR" || return 1
575     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile" || return 2
576
577     #Sleep
578     echo "Wait 1 minutes"
579     sleep 60
580
581     #Create files
582     echo "Verify Lustre filesystem is up and running"
583     client_up $LIVE_CLIENT || return 3
584     client_touch testfile || return 4
585
586     #CLIENT Portion
587     echo "Failing CLIENTs"
588     fail_clients 2
589     
590     #Check FS
591     echo "Test Lustre stability after CLIENTs failure"
592     clients_up
593     $PDSH $LIVE_CLIENT "ls -l $TESTDIR" || return 5
594     $PDSH $LIVE_CLIENT "rm -f $TESTDIR/*_testfile" || return 6
595
596     #Reintegration
597     echo "Reintegrating  CLIENTs/CLIENTs"
598     reintegrate_clients || return 7
599     clients_up
600     
601     #Sleep
602     echo "Wait 1 minutes"
603     sleep 60
604 }
605 run_test 9 "Ninth Failure Mode: CLIENT/CLIENT `date`"
606 ###################################################
607
608 ############### Tenth Failure Mode ###############
609 test_10() {
610         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
611
612         [ "$(facet_fstype ost1)" = "zfs" ] &&
613                 skip "LU-2059: no local config for ZFS OSTs" && return
614
615         shutdown_facet mds1
616         reboot_facet mds1
617
618         # prepare for MDS failover
619         change_active mds1
620         reboot_facet mds1
621
622         clients_up &
623         DFPID=$!
624         sleep 5
625
626         shutdown_facet ost1
627
628         echo "Reintegrating OST"
629         reboot_facet ost1
630         wait_for_facet ost1
631         start_ost 1 || return 2
632
633         shutdown_facet mds2
634         reboot_facet mds2
635
636         # prepare for MDS failover
637         change_active mds2
638         reboot_facet mds2
639
640         wait_for_facet mds1
641         start_mdt 1 || return $?
642
643         wait_for_facet mds2
644         start_mdt 2 || return $?
645
646         #Check FS
647         wait $DFPID
648         clients_recover_osts ost1
649         echo "Verify reintegration"
650         clients_up || return 1
651 }
652 run_test 10 "Tenth Failure Mode: MDT0/OST/MDT1 `date`"
653 ###################################################
654
655 ############### Seventh Failure Mode ###############
656 test_11() {
657         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
658         echo "Verify Lustre filesystem is up and running"
659         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
660
661         #MDS Portion
662         fail mds1
663         #Check FS
664
665         echo "Test Lustre stability after MDS failover"
666         clients_up
667
668         #CLIENT Portion
669         echo "Failing 2 CLIENTS"
670         fail_clients 2
671
672         #Check FS
673         echo "Test Lustre stability after CLIENT failure"
674         clients_up
675
676         #Reintegration
677         echo "Reintegrating CLIENTS"
678         reintegrate_clients || return 1
679
680         fail mds2
681
682         clients_up || return 3
683         sleep 2 # give it a little time for fully recovered before next test
684 }
685 run_test 11 "Eleventh Failure Mode: MDS0/CLIENT/MDS1 `date`"
686 ###################################################
687
688 test_12() {
689         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
690         echo "Verify Lustre filesystem is up and running"
691         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
692
693         #MDS Portion
694         fail mds1,mds2
695         clients_up
696
697         #OSS Portion
698         fail ost1,ost2
699         clients_up
700
701         #CLIENT Portion
702         echo "Failing 2 CLIENTS"
703         fail_clients 2
704
705         #Check FS
706         echo "Test Lustre stability after CLIENT failure"
707         clients_up
708
709         #Reintegration
710         echo "Reintegrating CLIENTS"
711         reintegrate_clients || return 1
712
713         clients_up || return 3
714         sleep 2 # give it a little time for fully recovered before next test
715 }
716 run_test 12 "Twelve Failure Mode: MDS0,MDS1/OST0, OST1/CLIENTS `date`"
717 ###################################################
718
719 test_13() {
720         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
721         echo "Verify Lustre filesystem is up and running"
722         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
723
724         #MDS Portion
725         fail mds1,mds2
726         clients_up
727
728         #CLIENT Portion
729         echo "Failing 2 CLIENTS"
730         fail_clients 2
731
732         #Check FS
733         echo "Test Lustre stability after CLIENT failure"
734         clients_up
735
736         #Reintegration
737         echo "Reintegrating CLIENTS"
738         reintegrate_clients || return 1
739
740         clients_up || return 3
741         sleep 2 # give it a little time for fully recovered before next test
742
743         #OSS Portion
744         fail ost1,ost2
745         clients_up || return 4
746 }
747 run_test 13 "Thirteen Failure Mode: MDS0,MDS1/CLIENTS/OST0,OST1 `date`"
748 ###################################################
749
750 test_14() {
751         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
752         echo "Verify Lustre filesystem is up and running"
753         [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
754
755         #OST Portion
756         fail ost1,ost2
757         clients_up
758
759         #CLIENT Portion
760         echo "Failing 2 CLIENTS"
761         fail_clients 2
762
763         #Check FS
764         echo "Test Lustre stability after CLIENT failure"
765         clients_up
766
767         #Reintegration
768         echo "Reintegrating CLIENTS"
769         reintegrate_clients || return 1
770
771         clients_up || return 3
772         sleep 2 # give it a little time for fully recovered before next test
773
774         #OSS Portion
775         fail mds1,mds2
776         clients_up || return 4
777 }
778 run_test 14 "Fourteen Failure Mode: OST0,OST1/CLIENTS/MDS0,MDS1 `date`"
779 ###################################################
780
781 test_15() {
782     #Run availability after all failures
783     DURATION=${DURATION:-$((2 * 60 * 60))} # 6 hours default
784     LOADTEST=${LOADTEST:-metadata-load.py}
785     $PWD/availability.sh $CONFIG $DURATION $CLIENTS || return 1
786 }
787 run_test 15 "Running Availability for 6 hours..."
788
789 complete $SECONDS
790 check_and_cleanup_lustre
791 exit_status