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/$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     facet_failover $SINGLEMDS
152     echo "Waiting for df pid: $DFPID"
153     wait $DFPID || { echo "df returned $?" && return 1; }
154
155     for i in $(seq $OSTCOUNT) ; do
156         facet_failover ost$i || return 4
157         echo "Waiting for df pid: $DFPID"
158         wait $DFPID || { echo "df returned $?" && return 3; }
159     done
160     return 0
161 }
162 run_test 0 "Fail all nodes, independently"
163
164 ############### First Failure Mode ###############
165 test_1() {
166 echo "Don't do a MDS - MDS Failure Case"
167 echo "This makes no sense"
168 }
169 run_test 1 "MDS/MDS failure"
170 ###################################################
171
172 ############### Second Failure Mode ###############
173 test_2() {
174     echo "Verify Lustre filesystem is up and running"
175     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
176
177     client_df
178
179     shutdown_facet $SINGLEMDS
180     reboot_facet $SINGLEMDS
181
182     # prepare for MDS failover
183     change_active $SINGLEMDS
184     reboot_facet $SINGLEMDS
185
186     client_df &
187     DFPID=$!
188     sleep 5
189
190     shutdown_facet ost1
191
192     echo "Reintegrating OST"
193     reboot_facet ost1
194     wait_for ost1
195     start_ost 1 || return 2
196
197     wait_for $SINGLEMDS
198     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS || return $?
199
200     #Check FS
201     wait $DFPID
202     clients_recover_osts ost1
203     echo "Verify reintegration"
204     client_df || return 1
205
206 }
207 run_test 2 "Second Failure Mode: MDS/OST `date`"
208 ###################################################
209
210
211 ############### Third Failure Mode ###############
212 test_3() {
213     #Create files
214     echo "Verify Lustre filesystem is up and running"
215     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
216     
217     #MDS Portion
218     facet_failover $SINGLEMDS
219     wait $DFPID || echo df failed: $?
220     #Check FS
221
222     echo "Test Lustre stability after MDS failover"
223     client_df
224
225     #CLIENT Portion
226     echo "Failing 2 CLIENTS"
227     fail_clients 2
228     
229     #Check FS
230     echo "Test Lustre stability after CLIENT failure"
231     client_df
232     
233     #Reintegration
234     echo "Reintegrating CLIENTS"
235     reintegrate_clients || return 1
236
237     client_df || return 3
238     sleep 2 # give it a little time for fully recovered before next test
239 }
240 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
241 ###################################################
242
243 ############### Fourth Failure Mode ###############
244 test_4() {
245     echo "Fourth Failure Mode: OST/MDS `date`"
246
247     #OST Portion
248     shutdown_facet ost1
249  
250     #Check FS
251     echo "Test Lustre stability after OST failure"
252     client_df &
253     DFPIDA=$!
254     sleep 5
255
256     #MDS Portion
257     shutdown_facet $SINGLEMDS
258     reboot_facet $SINGLEMDS
259
260     # prepare for MDS failover
261     change_active $SINGLEMDS
262     reboot_facet $SINGLEMDS
263
264     client_df &
265     DFPIDB=$!
266     sleep 5
267
268     #Reintegration
269     echo "Reintegrating OST"
270     reboot_facet ost1
271     wait_for ost1
272     start_ost 1
273     
274     wait_for $SINGLEMDS
275     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS
276     #Check FS
277     
278     wait $DFPIDA
279     wait $DFPIDB
280     clients_recover_osts ost1
281     echo "Test Lustre stability after MDS failover"
282     client_df || return 1
283 }
284 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
285 ###################################################
286
287 ############### Fifth Failure Mode ###############
288 test_5() {
289     [ $OSTCOUNT -lt 2 ] && skip "$OSTCOUNT < 2, not enough OSTs" && return 0
290
291     echo "Fifth Failure Mode: OST/OST `date`"
292
293     #Create files
294     echo "Verify Lustre filesystem is up and running"
295     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
296
297     client_df
298     
299     #OST Portion
300     shutdown_facet ost1
301     reboot_facet ost1
302     
303     #Check FS
304     echo "Test Lustre stability after OST failure"
305     client_df &
306     DFPIDA=$!
307     sleep 5
308     
309     #OST Portion
310     shutdown_facet ost2
311     reboot_facet ost2
312
313     #Check FS
314     echo "Test Lustre stability after OST failure"
315     client_df &
316     DFPIDB=$!
317     sleep 5
318
319     #Reintegration
320     echo "Reintegrating OSTs"
321     wait_for ost1
322     start_ost 1
323     wait_for ost2
324     start_ost 2
325     
326     clients_recover_osts ost1
327     clients_recover_osts ost2
328     sleep $TIMEOUT
329
330     wait $DFPIDA
331     wait $DFPIDB
332     client_df || return 2
333 }
334 run_test 5 "Fifth Failure Mode: OST/OST `date`"
335 ###################################################
336
337 ############### Sixth Failure Mode ###############
338 test_6() {
339     echo "Sixth Failure Mode: OST/CLIENT `date`"
340
341     #Create files
342     echo "Verify Lustre filesystem is up and running"
343     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
344
345     client_df
346     client_touch testfile || return 2
347         
348     #OST Portion
349     shutdown_facet ost1
350     reboot_facet ost1
351
352     #Check FS
353     echo "Test Lustre stability after OST failure"
354     client_df &
355     DFPIDA=$!
356     echo DFPIDA=$DFPIDA
357     sleep 5
358
359     #CLIENT Portion
360     echo "Failing CLIENTs"
361     fail_clients
362     
363     #Check FS
364     echo "Test Lustre stability after CLIENTs failure"
365     client_df &
366     DFPIDB=$!
367     echo DFPIDB=$DFPIDB
368     sleep 5
369     
370     #Reintegration
371     echo "Reintegrating OST/CLIENTs"
372     wait_for ost1
373     start_ost 1
374     reintegrate_clients || return 1
375     sleep 5 
376
377     wait_remote_prog df $((TIMEOUT * 3 + 10)) 
378     wait $DFPIDA
379     wait $DFPIDB
380
381     echo "Verifying mount"
382     [ -z "$(mounted_lustre_filesystems)" ] && return 3
383     client_df
384 }
385 run_test 6 "Sixth Failure Mode: OST/CLIENT `date`"
386 ###################################################
387
388
389 ############### Seventh Failure Mode ###############
390 test_7() {
391     echo "Seventh Failure Mode: CLIENT/MDS `date`"
392
393     #Create files
394     echo "Verify Lustre filesystem is up and running"
395     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
396
397     client_df
398     client_touch testfile  || return 1
399
400     #CLIENT Portion
401     echo "Part 1: Failing CLIENT"
402     fail_clients 2
403     
404     #Check FS
405     echo "Test Lustre stability after CLIENTs failure"
406     client_df
407     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
408     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
409     
410     #Sleep
411     echo "Wait 1 minutes"
412     sleep 60
413
414     #Create files
415     echo "Verify Lustre filesystem is up and running"
416     [ -z "$(mounted_lustre_filesystems)" ] && return 2
417
418     client_df
419     client_rm testfile
420
421     #MDS Portion
422     facet_failover $SINGLEMDS
423
424     #Check FS
425     echo "Test Lustre stability after MDS failover"
426     wait $DFPID || echo "df on down clients fails " || return 1
427     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
428     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
429
430     #Reintegration
431     echo "Reintegrating CLIENTs"
432     reintegrate_clients || return 2
433     client_df
434     
435     #Sleep
436     echo "wait 1 minutes"
437     sleep 60
438 }
439 run_test 7 "Seventh Failure Mode: CLIENT/MDS `date`"
440 ###################################################
441
442
443 ############### Eighth Failure Mode ###############
444 test_8() {
445     echo "Eighth Failure Mode: CLIENT/OST `date`"
446
447     #Create files
448     echo "Verify Lustre filesystem is up and running"
449     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
450
451     client_df
452     client_touch testfile
453         
454     #CLIENT Portion
455     echo "Failing CLIENTs"
456     fail_clients 2
457
458     #Check FS
459     echo "Test Lustre stability after CLIENTs failure"
460     client_df
461     $PDSH $LIVE_CLIENT "ls -l $MOUNT"
462     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
463
464     #Sleep
465     echo "Wait 1 minutes"
466     sleep 60
467
468     #Create files
469     echo "Verify Lustre filesystem is up and running"
470     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
471
472     client_df
473     client_touch testfile
474
475
476     #OST Portion
477     shutdown_facet ost1
478     reboot_facet ost1
479
480     #Check FS
481     echo "Test Lustre stability after OST failure"
482     client_df &
483     DFPID=$!
484     sleep 5
485     #non-failout hangs forever here
486     #$PDSH $LIVE_CLIENT "ls -l $MOUNT"
487     #$PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile"
488     
489     #Reintegration
490     echo "Reintegrating CLIENTs/OST"
491     reintegrate_clients || return 3
492     wait_for ost1
493     start_ost 1
494     wait $DFPID
495     client_df || return 1
496     client_touch testfile2 || return 2
497
498     #Sleep
499     echo "Wait 1 minutes"
500     sleep 60
501 }
502 run_test 8 "Eighth Failure Mode: CLIENT/OST `date`"
503 ###################################################
504
505
506 ############### Ninth Failure Mode ###############
507 test_9() {
508     echo 
509
510     #Create files
511     echo "Verify Lustre filesystem is up and running"
512     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
513
514     client_df
515     client_touch testfile || return 1
516         
517     #CLIENT Portion
518     echo "Failing CLIENTs"
519     fail_clients 2
520
521     #Check FS
522     echo "Test Lustre stability after CLIENTs failure"
523     client_df
524     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 1
525     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 2
526
527     #Sleep
528     echo "Wait 1 minutes"
529     sleep 60
530
531     #Create files
532     echo "Verify Lustre filesystem is up and running"
533     $PDSH $LIVE_CLIENT df $MOUNT || return 3
534     client_touch testfile || return 4
535
536     #CLIENT Portion
537     echo "Failing CLIENTs"
538     fail_clients 2
539     
540     #Check FS
541     echo "Test Lustre stability after CLIENTs failure"
542     client_df
543     $PDSH $LIVE_CLIENT "ls -l $MOUNT" || return 5
544     $PDSH $LIVE_CLIENT "rm -f $MOUNT/*_testfile" || return 6
545
546     #Reintegration
547     echo "Reintegrating  CLIENTs/CLIENTs"
548     reintegrate_clients || return 7
549     client_df
550     
551     #Sleep
552     echo "Wait 1 minutes"
553     sleep 60
554 }
555 run_test 9 "Ninth Failure Mode: CLIENT/CLIENT `date`"
556 ###################################################
557
558 test_10() {
559     #Run availability after all failures
560     DURATION=${DURATION:-$((2 * 60 * 60))} # 6 hours default
561     LOADTEST=${LOADTEST:-metadata-load.py}
562     $PWD/availability.sh $CONFIG $DURATION $CLIENTS || return 1
563 }
564 run_test 10 "Running Availability for 6 hours..."
565
566 equals_msg `basename $0`: test complete, cleaning up
567 check_and_cleanup_lustre
568 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true