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