Whamcloud - gitweb
b=13734
[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 #
16 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
17
18 SETUP=${SETUP:-""}
19 CLEANUP=${CLEANUP:-""}
20
21 build_test_filter
22
23 assert_env mds_HOST MDS_MKFS_OPTS
24 assert_env ost_HOST OST_MKFS_OPTS OSTCOUNT
25 assert_env LIVE_CLIENT FSNAME
26
27
28 # This can be a regexp, to allow more clients
29 CLIENTS=${CLIENTS:-"`comma_list $LIVE_CLIENT $FAIL_CLIENTS $EXTRA_CLIENTS`"}
30
31 DIR=${DIR:-$MOUNT}
32
33 #####
34 # fail clients round robin
35
36 # list of failable clients
37 FAIL_LIST=($FAIL_CLIENTS)
38 FAIL_NUM=${#FAIL_LIST[*]}
39 FAIL_NEXT=0
40 typeset -i  FAIL_NEXT
41 DOWN_NUM=0   # number of nodes currently down
42
43 # set next client to fail
44 set_fail_client() {
45     FAIL_CLIENT=${FAIL_LIST[$FAIL_NEXT]}
46     FAIL_NEXT=$(( (FAIL_NEXT+1) % FAIL_NUM ))
47     echo "fail $FAIL_CLIENT, next is $FAIL_NEXT"
48 }
49
50 shutdown_client() {
51     client=$1
52     if [ "$FAILURE_MODE" = HARD ]; then
53        $POWER_DOWN $client
54        while ping -w 3 -c 1 $client > /dev/null 2>&1; do 
55            echo "waiting for node $client to fail"
56            sleep 1
57        done  
58     elif [ "$FAILURE_MODE" = SOFT ]; then
59        zconf_umount $client $MOUNT -f
60     fi
61 }
62
63 reboot_node() {
64     NODE=$1
65     if [ "$FAILURE_MODE" = HARD ]; then
66        $POWER_UP $NODE
67     fi
68 }
69
70 fail_clients() {
71     num=$1
72     if [ -z "$num"  ] || [ "$num" -gt $((FAIL_NUM - DOWN_NUM)) ]; then
73         num=$((FAIL_NUM - DOWN_NUM)) 
74     fi
75     
76     if [ -z "$num" ] || [ "$num" -le 0 ]; then
77         return
78     fi
79
80     client_mkdirs
81
82     for i in `seq $num`; do
83        set_fail_client
84        client=$FAIL_CLIENT
85        DOWN_CLIENTS="$DOWN_CLIENTS $client"
86        shutdown_client $client
87     done
88
89     echo "down clients: $DOWN_CLIENTS"
90
91     for client in $DOWN_CLIENTS; do
92         reboot_node $client
93     done
94     DOWN_NUM=`echo $DOWN_CLIENTS | wc -w`
95     client_rmdirs
96 }
97
98 reintegrate_clients() {
99     for client in $DOWN_CLIENTS; do
100         wait_for_host $client
101         echo "Restarting $client"
102         zconf_mount $client $MOUNT || return 1
103     done
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         if echo $DOWN_CLIENTS | grep -q $c; then continue; fi
118         $PDSH $c touch $MOUNT/${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 $MOUNT/${c}_$file
126     done
127 }
128
129 client_mkdirs() {
130     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
131         echo "$c mkdir $MOUNT/$c"
132         $PDSH $c "mkdir $MOUNT/$c"
133         $PDSH $c "ls -l $MOUNT/$c" 
134     done
135 }
136
137 client_rmdirs() {
138     for c in $LIVE_CLIENT $FAIL_CLIENTS;  do
139         echo "rmdir $MOUNT/$c"
140         $PDSH $LIVE_CLIENT "rmdir $MOUNT/$c"
141     done
142 }
143
144 clients_recover_osts() {
145     facet=$1
146 #    do_node $CLIENTS "$LCTL "'--device %OSC_`hostname`_'"${facet}_svc_MNT_client_facet recover"
147 }
148
149 cleanup_and_setup_lustre
150
151 # 9 Different Failure Modes Combinations
152 echo "Starting Test 17 at `date`"
153
154 test_0() {
155     facet_failover $SINGLEMDS
156     echo "Waiting for df pid: $DFPID"
157     wait $DFPID || { echo "df returned $?" && return 1; }
158
159     facet_failover ost1 || return 4
160     echo "Waiting for df pid: $DFPID"
161     wait $DFPID || { echo "df returned $?" && return 2; }
162
163     facet_failover ost2 || return 5
164     echo "Waiting for df pid: $DFPID"
165     wait $DFPID || { echo "df returned $?" && return 3; }
166     return 0
167 }
168 run_test 0 "Fail all nodes, independently"
169
170 ############### First Failure Mode ###############
171 test_1() {
172 echo "Don't do a MDS - MDS Failure Case"
173 echo "This makes no sense"
174 }
175 run_test 1 "MDS/MDS failure"
176 ###################################################
177
178 ############### Second Failure Mode ###############
179 test_2() {
180     echo "Verify Lustre filesystem is up and running"
181     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
182
183     client_df
184
185     shutdown_facet $SINGLEMDS
186     reboot_facet $SINGLEMDS
187
188     # prepare for MDS failover
189     change_active $SINGLEMDS
190     reboot_facet $SINGLEMDS
191
192     client_df &
193     DFPID=$!
194     sleep 5
195
196     shutdown_facet ost1
197
198     echo "Reintegrating OST"
199     reboot_facet ost1
200     wait_for ost1
201     start_ost 1 || return 2
202
203     wait_for $SINGLEMDS
204     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS || return $?
205
206     #Check FS
207     wait $DFPID
208     clients_recover_osts ost1
209     echo "Verify reintegration"
210     client_df || return 1
211
212 }
213 run_test 2 "Second Failure Mode: MDS/OST `date`"
214 ###################################################
215
216
217 ############### Third Failure Mode ###############
218 test_3() {
219     #Create files
220     echo "Verify Lustre filesystem is up and running"
221     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
222     
223     #MDS Portion
224     facet_failover $SINGLEMDS
225     wait $DFPID || echo df failed: $?
226     #Check FS
227
228     echo "Test Lustre stability after MDS failover"
229     client_df
230
231     #CLIENT Portion
232     echo "Failing 2 CLIENTS"
233     fail_clients 2
234     
235     #Check FS
236     echo "Test Lustre stability after CLIENT failure"
237     client_df
238     
239     #Reintegration
240     echo "Reintegrating CLIENTS"
241     reintegrate_clients || return 1
242
243     client_df || return 3
244     sleep 2 # give it a little time for fully recovered before next test
245 }
246 run_test 3  "Thirdb Failure Mode: MDS/CLIENT `date`"
247 ###################################################
248
249 ############### Fourth Failure Mode ###############
250 test_4() {
251     echo "Fourth Failure Mode: OST/MDS `date`"
252
253     #OST Portion
254     shutdown_facet ost1
255  
256     #Check FS
257     echo "Test Lustre stability after OST failure"
258     client_df &
259     DFPIDA=$!
260     sleep 5
261
262     #MDS Portion
263     shutdown_facet $SINGLEMDS
264     reboot_facet $SINGLEMDS
265
266     # prepare for MDS failover
267     change_active $SINGLEMDS
268     reboot_facet $SINGLEMDS
269
270     client_df &
271     DFPIDB=$!
272     sleep 5
273
274     #Reintegration
275     echo "Reintegrating OST"
276     reboot_facet ost1
277     wait_for ost1
278     start_ost 1
279     
280     wait_for $SINGLEMDS
281     start $SINGLEMDS `mdsdevname 1` $MDS_MOUNT_OPTS
282     #Check FS
283     
284     wait $DFPIDA
285     wait $DFPIDB
286     clients_recover_osts ost1
287     echo "Test Lustre stability after MDS failover"
288     client_df || return 1
289 }
290 run_test 4 "Fourth Failure Mode: OST/MDS `date`"
291 ###################################################
292
293 ############### Fifth Failure Mode ###############
294 test_5() {
295     echo "Fifth Failure Mode: OST/OST `date`"
296
297     #Create files
298     echo "Verify Lustre filesystem is up and running"
299     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
300
301     client_df
302     
303     #OST Portion
304     shutdown_facet ost1
305     reboot_facet ost1
306     
307     #Check FS
308     echo "Test Lustre stability after OST failure"
309     client_df &
310     DFPIDA=$!
311     sleep 5
312     
313     #OST Portion
314     shutdown_facet ost2
315     reboot_facet ost2
316
317     #Check FS
318     echo "Test Lustre stability after OST failure"
319     client_df &
320     DFPIDB=$!
321     sleep 5
322
323     #Reintegration
324     echo "Reintegrating OSTs"
325     wait_for ost1
326     start_ost 1
327     wait_for ost2
328     start_ost 2
329     
330     clients_recover_osts ost1
331     clients_recover_osts ost2
332     sleep $TIMEOUT
333
334     wait $DFPIDA
335     wait $DFPIDB
336     client_df || return 2
337 }
338 run_test 5 "Fifth Failure Mode: OST/OST `date`"
339 ###################################################
340
341 ############### Sixth Failure Mode ###############
342 test_6() {
343     echo "Sixth Failure Mode: OST/CLIENT `date`"
344
345     #Create files
346     echo "Verify Lustre filesystem is up and running"
347     [ -z "$(mounted_lustre_filesystems)" ] && error "Lustre is not running"
348
349     client_df
350     client_touch testfile || return 2
351         
352     #OST Portion
353     shutdown_facet ost1
354     reboot_facet ost1
355
356     #Check FS
357     echo "Test Lustre stability after OST failure"
358     client_df &
359     DFPIDA=$!
360     sleep 5
361
362     #CLIENT Portion
363     echo "Failing CLIENTs"
364     fail_clients
365     
366     #Check FS
367     echo "Test Lustre stability after CLIENTs failure"
368     client_df &
369     DFPIDB=$!
370     sleep 5
371     
372     #Reintegration
373     echo "Reintegrating OST/CLIENTs"
374     wait_for ost1
375     start_ost 1
376     reintegrate_clients
377     sleep 5 
378
379     wait $DFPIDA
380     wait $DFPIDB
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 || true