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