Whamcloud - gitweb
b=12560
[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 MDSDEV
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 mds
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     if [ $OSTCOUNT -gt 1 ]; then
191         facet_failover ost2 || return 5
192         echo "Waiting for df pid: $DFPID"
193         wait $DFPID || { echo "df returned $?" && return 3; }
194     fi
195     return 0
196 }
197 run_test 0 "Fail all nodes, independently"
198
199 ############### First Failure Mode ###############
200 test_1() {
201 echo "Don't do a MDS - MDS Failure Case"
202 echo "This makes no sense"
203 }
204 run_test 1 "MDS/MDS failure"
205 ###################################################
206
207 ############### Second Failure Mode ###############
208 test_2() {
209     echo "Verify Lustre filesystem is up and running"
210     client_df
211
212     shutdown_facet mds
213     reboot_facet mds
214
215     # prepare for MDS failover
216     change_active mds
217     reboot_facet mds
218
219     client_df &
220     DFPID=$!
221     sleep 5
222
223     shutdown_facet ost1
224
225     echo "Reintegrating OST"
226     reboot_facet ost1
227     wait_for ost1
228     start_ost 1 || return 2
229
230     wait_for mds
231     start mds $MDSDEV $MDS_MOUNT_OPTS || return $?
232
233     #Check FS
234     wait $DFPID
235     clients_recover_osts ost1
236     echo "Verify reintegration"
237     client_df || return 1
238
239 }
240 run_test 2 "Second Failure Mode: MDS/OST `date`"
241 ###################################################
242
243
244 ############### Third Failure Mode ###############
245 test_3() {
246     #Create files
247     echo "Verify Lustre filesystem is up and running"
248     
249     #MDS Portion
250     facet_failover mds
251     wait $DFPID || echo df failed: $?
252     #Check FS
253
254     echo "Test Lustre stability after MDS failover"
255     client_df
256
257     #CLIENT Portion
258     echo "Failing 2 CLIENTS"
259     fail_clients 2
260     
261     #Check FS
262     echo "Test Lustre stability after CLIENT failure"
263     client_df
264     
265     #Reintegration
266     echo "Reintegrating CLIENTS"
267     reintegrate_clients || return 1
268
269     client_df || return 3
270 }
271 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
272 ###################################################
273
274 ############### Fourth Failure Mode ###############
275 test_4() {
276     echo "Fourth Failure Mode: OST/MDS `date`"
277
278     #OST Portion
279     shutdown_facet ost1
280  
281     #Check FS
282     echo "Test Lustre stability after OST failure"
283     client_df &
284     DFPIDA=$!
285     sleep 5
286
287     #MDS Portion
288     shutdown_facet mds
289     reboot_facet mds
290
291     # prepare for MDS failover
292     change_active mds
293     reboot_facet mds
294
295     client_df &
296     DFPIDB=$!
297     sleep 5
298
299     #Reintegration
300     echo "Reintegrating OST"
301     reboot_facet ost1
302     wait_for ost1
303     start_ost 1
304     
305     wait_for mds
306     start mds $MDSDEV $MDS_MOUNT_OPTS
307     #Check FS
308     
309     wait $DFPIDA
310     wait $DFPIDB
311     clients_recover_osts ost1
312     echo "Test Lustre stability after MDS failover"
313     client_df || return 1
314 }
315 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
316 ###################################################
317
318 ############### Fifth Failure Mode ###############
319 test_5() {
320     [ $OSTCOUNT -lt 1 ] && skip "$OSTCOUNT < 1, not enough OSTs" && return 0
321
322     echo "Fifth Failure Mode: OST/OST `date`"
323
324     #Create files
325     echo "Verify Lustre filesystem is up and running"
326     client_df
327     
328     #OST Portion
329     shutdown_facet ost1
330     reboot_facet ost1
331     
332     #Check FS
333     echo "Test Lustre stability after OST failure"
334     client_df &
335     DFPIDA=$!
336     sleep 5
337     
338     #OST Portion
339     shutdown_facet ost2
340     reboot_facet ost2
341
342     #Check FS
343     echo "Test Lustre stability after OST failure"
344     client_df &
345     DFPIDB=$!
346     sleep 5
347
348     #Reintegration
349     echo "Reintegrating OSTs"
350     wait_for ost1
351     start_ost 1
352     wait_for ost2
353     start_ost 2
354     
355     clients_recover_osts ost1
356     clients_recover_osts ost2
357     sleep $TIMEOUT
358
359     wait $DFPIDA
360     wait $DFPIDB
361     client_df || return 2
362 }
363 run_test 5 "Fifth Failure Mode: OST/OST `date`"
364 ###################################################
365
366 ############### Sixth Failure Mode ###############
367 test_6() {
368     echo "Sixth Failure Mode: OST/CLIENT `date`"
369
370     #Create files
371     echo "Verify Lustre filesystem is up and running"
372     client_df || return 1
373     client_touch testfile || return 2
374         
375     #OST Portion
376     shutdown_facet ost1
377     reboot_facet ost1
378
379     #Check FS
380     echo "Test Lustre stability after OST failure"
381     client_df &
382     DFPIDA=$!
383     sleep 5
384
385     #CLIENT Portion
386     echo "Failing CLIENTs"
387     fail_clients
388     
389     #Check FS
390     echo "Test Lustre stability after CLIENTs failure"
391     client_df &
392     DFPIDB=$!
393     sleep 5
394     
395     #Reintegration
396     echo "Reintegrating OST/CLIENTs"
397     wait_for ost1
398     start_ost 1
399     reintegrate_clients
400     sleep 5 
401
402     wait $DFPIDA
403     wait $DFPIDB
404     echo "Verifying mount"
405     client_df || return 3
406 }
407 run_test 6 "Sixth Failure Mode: OST/CLIENT `date`"
408 ###################################################
409
410
411 ############### Seventh Failure Mode ###############
412 test_7() {
413     echo "Seventh Failure Mode: CLIENT/MDS `date`"
414
415     #Create files
416     echo "Verify Lustre filesystem is up and running"
417     client_df
418     client_touch testfile  || return 1
419
420     #CLIENT Portion
421     echo "Part 1: Failing CLIENT"
422     fail_clients 2
423     
424     #Check FS
425     echo "Test Lustre stability after CLIENTs failure"
426     client_df
427     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
428     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
429     
430     #Sleep
431     echo "Wait 1 minutes"
432     sleep 60
433
434     #Create files
435     echo "Verify Lustre filesystem is up and running"
436     client_df
437     client_rm testfile
438
439     #MDS Portion
440     facet_failover mds
441
442     #Check FS
443     echo "Test Lustre stability after MDS failover"
444     wait $DFPID || echo "df on down clients fails " || return 1
445     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
446     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
447
448     #Reintegration
449     echo "Reintegrating CLIENTs"
450     reintegrate_clients
451     client_df || return 2
452     
453     #Sleep
454     echo "wait 1 minutes"
455     sleep 60
456 }
457 run_test 7 "Seventh Failure Mode: CLIENT/MDS `date`"
458 ###################################################
459
460
461 ############### Eighth Failure Mode ###############
462 test_8() {
463     echo "Eighth Failure Mode: CLIENT/OST `date`"
464
465     #Create files
466     echo "Verify Lustre filesystem is up and running"
467     client_df
468     client_touch testfile
469         
470     #CLIENT Portion
471     echo "Failing CLIENTs"
472     fail_clients 2
473
474     #Check FS
475     echo "Test Lustre stability after CLIENTs failure"
476     client_df
477     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
478     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
479
480     #Sleep
481     echo "Wait 1 minutes"
482     sleep 60
483
484     #Create files
485     echo "Verify Lustre filesystem is up and running"
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
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     client_df
527     client_touch testfile || return 1
528         
529     #CLIENT Portion
530     echo "Failing CLIENTs"
531     fail_clients 2
532
533     #Check FS
534     echo "Test Lustre stability after CLIENTs failure"
535     client_df
536     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 1
537     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 2
538
539     #Sleep
540     echo "Wait 1 minutes"
541     sleep 60
542
543     #Create files
544     echo "Verify Lustre filesystem is up and running"
545     $PDSH $LIVE_CLIENT df $MOUNT || return 3
546     client_touch testfile || return 4
547
548     #CLIENT Portion
549     echo "Failing CLIENTs"
550     fail_clients 2
551     
552     #Check FS
553     echo "Test Lustre stability after CLIENTs failure"
554     client_df
555     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 5
556     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 6
557
558     #Reintegration
559     echo "Reintegrating  CLIENTs/CLIENTs"
560     reintegrate_clients
561     client_df || return 7
562     
563     #Sleep
564     echo "Wait 1 minutes"
565     sleep 60
566 }
567 run_test 9 "Ninth Failure Mode: CLIENT/CLIENT `date`"
568 ###################################################
569
570 test_10() {
571     #Run availability after all failures
572     DURATION=${DURATION:-$((2 * 60 * 60))} # 6 hours default
573     LOADTEST=${LOADTEST:-metadata-load.py}
574     $PWD/availability.sh $CONFIG $DURATION $CLIENTS || return 1
575 }
576 run_test 10 "Running Availability for 6 hours..."
577
578 equals_msg `basename $0`: test complete, cleaning up
579 $CLEANUP
580 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true