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