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