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