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