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