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