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