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