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