Whamcloud - gitweb
b=15967
[fs/lustre-release.git] / lustre / tests / insanity.sh
1 #!/bin/sh
2 # Test multiple failures, AKA Test 17
3
4 set -e
5
6 LUSTRE=${LUSTRE:-`dirname $0`/..}
7 . $LUSTRE/tests/test-framework.sh
8
9 init_test_env $@
10
11 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
12 #              
13 ALWAYS_EXCEPT="10  $INSANITY_EXCEPT"
14
15 if [ "$FAILURE_MODE" = "HARD" ]; then
16     mixed_ost_devs && CONFIG_EXCEPTIONS="0 2 4 5 6 8" && \
17         echo -n "Several ost services on one ost node are used with FAILURE_MODE=$FAILURE_MODE. " && \
18         echo "Except the tests: $CONFIG_EXCEPTIONS" && \
19         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
20 fi
21
22 #
23 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
24
25 SETUP=${SETUP:-""}
26 CLEANUP=${CLEANUP:-""}
27
28 build_test_filter
29
30 SINGLECLIENT=${SINGLECLIENT:-$HOSTNAME}
31 LIVE_CLIENT=${LIVE_CLIENT:-$SINGLECLIENT}
32 FAIL_CLIENTS=${FAIL_CLIENTS:-$RCLIENTS}
33
34 assert_env mds_HOST MDS_MKFS_OPTS
35 assert_env ost_HOST OST_MKFS_OPTS OSTCOUNT
36 assert_env LIVE_CLIENT FSNAME
37
38
39 # This can be a regexp, to allow more clients
40 CLIENTS=${CLIENTS:-"`comma_list $LIVE_CLIENT $FAIL_CLIENTS`"}
41
42 DIR=${DIR:-$MOUNT}
43
44 #####
45 # fail clients round robin
46
47 # list of failable clients
48 FAIL_LIST=($FAIL_CLIENTS)
49 FAIL_NUM=${#FAIL_LIST[*]}
50 FAIL_NEXT=0
51 typeset -i  FAIL_NEXT
52 DOWN_NUM=0   # number of nodes currently down
53
54 # set next client to fail
55 set_fail_client() {
56     FAIL_CLIENT=${FAIL_LIST[$FAIL_NEXT]}
57     FAIL_NEXT=$(( (FAIL_NEXT+1) % FAIL_NUM ))
58     echo "fail $FAIL_CLIENT, next is $FAIL_NEXT"
59 }
60
61 shutdown_client() {
62     client=$1
63     if [ "$FAILURE_MODE" = HARD ]; then
64        $POWER_DOWN $client
65        while ping -w 3 -c 1 $client > /dev/null 2>&1; do 
66            echo "waiting for node $client to fail"
67            sleep 1
68        done  
69     elif [ "$FAILURE_MODE" = SOFT ]; then
70        zconf_umount $client $MOUNT -f
71     fi
72 }
73
74 reboot_node() {
75     NODE=$1
76     if [ "$FAILURE_MODE" = HARD ]; then
77        $POWER_UP $NODE
78     fi
79 }
80
81 fail_clients() {
82     num=$1
83
84     log "Request clients to fail: ${num}. Num of clients to fail: ${FAIL_NUM}, already failed: $DOWN_NUM"
85     if [ -z "$num"  ] || [ "$num" -gt $((FAIL_NUM - DOWN_NUM)) ]; then
86         num=$((FAIL_NUM - DOWN_NUM)) 
87     fi
88     
89     if [ -z "$num" ] || [ "$num" -le 0 ]; then
90         log "No clients failed!"
91         return
92     fi
93
94     client_mkdirs
95
96     for i in `seq $num`; do
97        set_fail_client
98        client=$FAIL_CLIENT
99        DOWN_CLIENTS="$DOWN_CLIENTS $client"
100        shutdown_client $client
101     done
102
103     echo "down clients: $DOWN_CLIENTS"
104
105     for client in $DOWN_CLIENTS; do
106         reboot_node $client
107     done
108     DOWN_NUM=`echo $DOWN_CLIENTS | wc -w`
109     client_rmdirs
110 }
111
112 reintegrate_clients() {
113     for client in $DOWN_CLIENTS; do
114         wait_for_host $client
115         echo "Restarting $client"
116         zconf_mount $client $MOUNT || return 1
117     done
118     DOWN_CLIENTS=""
119     DOWN_NUM=0
120 }
121
122 start_ost() {
123     start ost$1 `ostdevname $1` $OST_MOUNT_OPTS
124 }
125
126 trap exit INT
127
128 client_touch() {
129     file=$1
130     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
131         if echo $DOWN_CLIENTS | grep -q $c; then continue; fi
132         $PDSH $c touch $MOUNT/${c}_$file || return 1
133     done
134 }
135
136 client_rm() {
137     file=$1
138     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
139         $PDSH $c rm $MOUNT/${c}_$file
140     done
141 }
142
143 client_mkdirs() {
144     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
145         echo "$c mkdir $MOUNT/$c"
146         $PDSH $c "mkdir $MOUNT/$c"
147         $PDSH $c "ls -l $MOUNT/$c" 
148     done
149 }
150
151 client_rmdirs() {
152     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
153         echo "rmdir $MOUNT/$c"
154         $PDSH $LIVE_CLIENT "rmdir $MOUNT/$c"
155     done
156 }
157
158 clients_recover_osts() {
159     facet=$1
160 #    do_node $CLIENTS "$LCTL "'--device %OSC_`hostname`_'"${facet}_svc_MNT_client_facet recover"
161 }
162
163 cleanup_and_setup_lustre
164
165 # 9 Different Failure Modes Combinations
166 echo "Starting Test 17 at `date`"
167
168 test_0() {
169     facet_failover $SINGLEMDS
170     echo "Waiting for df pid: $DFPID"
171     wait $DFPID || { echo "df returned $?" && return 1; }
172
173     for i in $(seq $OSTCOUNT) ; do
174         facet_failover ost$i || return 4
175         echo "Waiting for df pid: $DFPID"
176         wait $DFPID || { echo "df returned $?" && return 3; }
177     done
178     return 0
179 }
180 run_test 0 "Fail all nodes, independently"
181
182 ############### First Failure Mode ###############
183 test_1() {
184 echo "Don't do a MDS - MDS Failure Case"
185 echo "This makes no sense"
186 }
187 run_test 1 "MDS/MDS failure"
188 ###################################################
189
190 ############### Second Failure Mode ###############
191 test_2() {
192     echo "Verify Lustre filesystem is up and running"
193     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
194
195     client_df
196
197     shutdown_facet $SINGLEMDS
198     reboot_facet $SINGLEMDS
199
200     # prepare for MDS failover
201     change_active $SINGLEMDS
202     reboot_facet $SINGLEMDS
203
204     client_df &
205     DFPID=$!
206     sleep 5
207
208     shutdown_facet ost1
209
210     echo "Reintegrating OST"
211     reboot_facet ost1
212     wait_for ost1
213     start_ost 1 || return 2
214
215     wait_for $SINGLEMDS
216     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS || return $?
217
218     #Check FS
219     wait $DFPID
220     clients_recover_osts ost1
221     echo "Verify reintegration"
222     client_df || return 1
223
224 }
225 run_test 2 "Second Failure Mode: MDS/OST `date`"
226 ###################################################
227
228
229 ############### Third Failure Mode ###############
230 test_3() {
231     #Create files
232     echo "Verify Lustre filesystem is up and running"
233     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
234     
235     #MDS Portion
236     facet_failover $SINGLEMDS
237     wait $DFPID || echo df failed: $?
238     #Check FS
239
240     echo "Test Lustre stability after MDS failover"
241     client_df
242
243     #CLIENT Portion
244     echo "Failing 2 CLIENTS"
245     fail_clients 2
246     
247     #Check FS
248     echo "Test Lustre stability after CLIENT failure"
249     client_df
250     
251     #Reintegration
252     echo "Reintegrating CLIENTS"
253     reintegrate_clients || return 1
254
255     client_df || return 3
256     sleep 2 # give it a little time for fully recovered before next test
257 }
258 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
259 ###################################################
260
261 ############### Fourth Failure Mode ###############
262 test_4() {
263     echo "Fourth Failure Mode: OST/MDS `date`"
264
265     #OST Portion
266     shutdown_facet ost1
267  
268     #Check FS
269     echo "Test Lustre stability after OST failure"
270     client_df &
271     DFPIDA=$!
272     sleep 5
273
274     #MDS Portion
275     shutdown_facet $SINGLEMDS
276     reboot_facet $SINGLEMDS
277
278     # prepare for MDS failover
279     change_active $SINGLEMDS
280     reboot_facet $SINGLEMDS
281
282     client_df &
283     DFPIDB=$!
284     sleep 5
285
286     #Reintegration
287     echo "Reintegrating OST"
288     reboot_facet ost1
289     wait_for ost1
290     start_ost 1
291     
292     wait_for $SINGLEMDS
293     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS
294     #Check FS
295     
296     wait $DFPIDA
297     wait $DFPIDB
298     clients_recover_osts ost1
299     echo "Test Lustre stability after MDS failover"
300     client_df || return 1
301 }
302 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
303 ###################################################
304
305 ############### Fifth Failure Mode ###############
306 test_5() {
307     [ $OSTCOUNT -lt 2 ] && skip "$OSTCOUNT < 2, not enough OSTs" && return 0
308
309     echo "Fifth Failure Mode: OST/OST `date`"
310
311     #Create files
312     echo "Verify Lustre filesystem is up and running"
313     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
314
315     client_df
316     
317     #OST Portion
318     shutdown_facet ost1
319     reboot_facet ost1
320     
321     #Check FS
322     echo "Test Lustre stability after OST failure"
323     client_df &
324     DFPIDA=$!
325     sleep 5
326     
327     #OST Portion
328     shutdown_facet ost2
329     reboot_facet ost2
330
331     #Check FS
332     echo "Test Lustre stability after OST failure"
333     client_df &
334     DFPIDB=$!
335     sleep 5
336
337     #Reintegration
338     echo "Reintegrating OSTs"
339     wait_for ost1
340     start_ost 1
341     wait_for ost2
342     start_ost 2
343     
344     clients_recover_osts ost1
345     clients_recover_osts ost2
346     sleep $TIMEOUT
347
348     wait $DFPIDA
349     wait $DFPIDB
350     client_df || return 2
351 }
352 run_test 5 "Fifth Failure Mode: OST/OST `date`"
353 ###################################################
354
355 ############### Sixth Failure Mode ###############
356 test_6() {
357     echo "Sixth Failure Mode: OST/CLIENT `date`"
358
359     #Create files
360     echo "Verify Lustre filesystem is up and running"
361     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
362
363     client_df
364     client_touch testfile || return 2
365         
366     #OST Portion
367     shutdown_facet ost1
368     reboot_facet ost1
369
370     #Check FS
371     echo "Test Lustre stability after OST failure"
372     client_df &
373     DFPIDA=$!
374     sleep 5
375
376     #CLIENT Portion
377     echo "Failing CLIENTs"
378     fail_clients
379     
380     #Check FS
381     echo "Test Lustre stability after CLIENTs failure"
382     client_df &
383     DFPIDB=$!
384     sleep 5
385     
386     #Reintegration
387     echo "Reintegrating OST/CLIENTs"
388     wait_for ost1
389     start_ost 1
390     reintegrate_clients
391     sleep 5 
392
393     wait $DFPIDA
394     wait $DFPIDB
395     echo "Verifying mount"
396     [ -z "$(mounted_lustre_filesystems)" ] && return 3
397     client_df
398 }
399 run_test 6 "Sixth Failure Mode: OST/CLIENT `date`"
400 ###################################################
401
402
403 ############### Seventh Failure Mode ###############
404 test_7() {
405     echo "Seventh Failure Mode: CLIENT/MDS `date`"
406
407     #Create files
408     echo "Verify Lustre filesystem is up and running"
409     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
410
411     client_df
412     client_touch testfile  || return 1
413
414     #CLIENT Portion
415     echo "Part 1: Failing CLIENT"
416     fail_clients 2
417     
418     #Check FS
419     echo "Test Lustre stability after CLIENTs failure"
420     client_df
421     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
422     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
423     
424     #Sleep
425     echo "Wait 1 minutes"
426     sleep 60
427
428     #Create files
429     echo "Verify Lustre filesystem is up and running"
430     [ -z "$(mounted_lustre_filesystems)" ] && return 2
431
432     client_df
433     client_rm testfile
434
435     #MDS Portion
436     facet_failover $SINGLEMDS
437
438     #Check FS
439     echo "Test Lustre stability after MDS failover"
440     wait $DFPID || echo "df on down clients fails " || return 1
441     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
442     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
443
444     #Reintegration
445     echo "Reintegrating CLIENTs"
446     reintegrate_clients || return 2
447     client_df
448     
449     #Sleep
450     echo "wait 1 minutes"
451     sleep 60
452 }
453 run_test 7 "Seventh Failure Mode: CLIENT/MDS `date`"
454 ###################################################
455
456
457 ############### Eighth Failure Mode ###############
458 test_8() {
459     echo "Eighth Failure Mode: CLIENT/OST `date`"
460
461     #Create files
462     echo "Verify Lustre filesystem is up and running"
463     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
464
465     client_df
466     client_touch testfile
467         
468     #CLIENT Portion
469     echo "Failing CLIENTs"
470     fail_clients 2
471
472     #Check FS
473     echo "Test Lustre stability after CLIENTs failure"
474     client_df
475     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
476     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
477
478     #Sleep
479     echo "Wait 1 minutes"
480     sleep 60
481
482     #Create files
483     echo "Verify Lustre filesystem is up and running"
484     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
485
486     client_df
487     client_touch testfile
488
489
490     #OST Portion
491     shutdown_facet ost1
492     reboot_facet ost1
493
494     #Check FS
495     echo "Test Lustre stability after OST failure"
496     client_df &
497     DFPID=$!
498     sleep 5
499     #non-failout hangs forever here
500     #$PDSH $LIVE_CLIENT "ls -l $MOUNT"
501     #$PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
502     
503     #Reintegration
504     echo "Reintegrating CLIENTs/OST"
505     reintegrate_clients || return 3
506     wait_for ost1
507     start_ost 1
508     wait $DFPID
509     client_df || return 1
510     client_touch testfile2 || return 2
511
512     #Sleep
513     echo "Wait 1 minutes"
514     sleep 60
515 }
516 run_test 8 "Eighth Failure Mode: CLIENT/OST `date`"
517 ###################################################
518
519
520 ############### Ninth Failure Mode ###############
521 test_9() {
522     echo 
523
524     #Create files
525     echo "Verify Lustre filesystem is up and running"
526     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
527
528     client_df
529     client_touch testfile || return 1
530         
531     #CLIENT Portion
532     echo "Failing CLIENTs"
533     fail_clients 2
534
535     #Check FS
536     echo "Test Lustre stability after CLIENTs failure"
537     client_df
538     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 1
539     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 2
540
541     #Sleep
542     echo "Wait 1 minutes"
543     sleep 60
544
545     #Create files
546     echo "Verify Lustre filesystem is up and running"
547     $PDSH $LIVE_CLIENT df $MOUNT || return 3
548     client_touch testfile || return 4
549
550     #CLIENT Portion
551     echo "Failing CLIENTs"
552     fail_clients 2
553     
554     #Check FS
555     echo "Test Lustre stability after CLIENTs failure"
556     client_df
557     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 5
558     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 6
559
560     #Reintegration
561     echo "Reintegrating  CLIENTs/CLIENTs"
562     reintegrate_clients || return 7
563     client_df
564     
565     #Sleep
566     echo "Wait 1 minutes"
567     sleep 60
568 }
569 run_test 9 "Ninth Failure Mode: CLIENT/CLIENT `date`"
570 ###################################################
571
572 test_10() {
573     #Run availability after all failures
574     DURATION=${DURATION:-$((2 * 60 * 60))} # 6 hours default
575     LOADTEST=${LOADTEST:-metadata-load.py}
576     $PWD/availability.sh $CONFIG $DURATION $CLIENTS || return 1
577 }
578 run_test 10 "Running Availability for 6 hours..."
579
580 equals_msg `basename $0`: test complete, cleaning up
581 check_and_cleanup_lustre
582 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true