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