Whamcloud - gitweb
land b_eq on HEAD
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2 # requirement:
3 #       add uml1 uml2 uml3 in your /etc/hosts
4
5 # FIXME - there is no reason to use all of these different
6 #   return codes, espcially when most of them are mapped to something
7 #   else anyway.  The combination of test number and return code
8 #   figure out what failed.
9
10 set -e
11
12 SRCDIR=`dirname $0`
13 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
14
15 LUSTRE=${LUSTRE:-`dirname $0`/..}
16 RLUSTRE=${RLUSTRE:-$LUSTRE}
17
18 . $LUSTRE/tests/test-framework.sh
19
20 init_test_env $@
21
22 . ${CONFIG:=$LUSTRE/tests/cfg/local.sh}
23
24 gen_config() {
25         rm -f $XMLCONFIG
26
27         add_mds mds --dev $MDSDEV --size $MDSSIZE
28         add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
29             --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
30         add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
31         add_client client mds --lov lov1 --path $MOUNT
32 }
33
34 gen_second_config() {
35         rm -f $XMLCONFIG
36
37         add_mds mds2 --dev $MDSDEV --size $MDSSIZE
38         add_lov lov2 mds2 --stripe_sz $STRIPE_BYTES\
39             --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
40         add_ost ost2 --lov lov2 --dev $OSTDEV --size $OSTSIZE
41         add_client client mds2 --lov lov2 --path $MOUNT2
42 }
43
44 start_mds() {
45         echo "start mds service on `facet_active_host mds`"
46         start mds --reformat $MDSLCONFARGS  || return 94
47 }
48 stop_mds() {
49         echo "stop mds service on `facet_active_host mds`"
50         stop mds $@  || return 97 
51 }
52
53 start_ost() {
54         echo "start ost service on `facet_active_host ost`"
55         start ost --reformat $OSTLCONFARGS  || return 95
56 }
57
58 stop_ost() {
59         echo "stop ost service on `facet_active_host ost`"
60         stop ost $@  || return 98 
61 }
62
63 mount_client() {
64         local MOUNTPATH=$1
65         echo "mount lustre on ${MOUNTPATH}....."
66         zconf_mount `hostname`  $MOUNTPATH  || return 96
67 }
68
69 umount_client() {
70         local MOUNTPATH=$1
71         echo "umount lustre on ${MOUNTPATH}....."
72         zconf_umount `hostname`  $MOUNTPATH || return 97
73 }
74
75 manual_umount_client(){
76         echo "manual umount lustre on ${MOUNTPATH}...."
77         do_facet  client "umount $MOUNT"
78 }
79
80 setup() {
81         start_ost
82         start_mds
83         mount_client $MOUNT 
84 }
85
86 cleanup() {
87         umount_client $MOUNT || return 200
88         stop_mds  || return 201
89         stop_ost || return 202
90         # catch case where these return just fine, but modules are still not unloaded
91         /sbin/lsmod | grep -q portals 
92         if [ 1 -ne $? ]; then
93                 echo "modules still loaded..."
94                 return 203
95         fi
96 }
97
98 check_mount() {
99         do_facet client "touch $DIR/a" || return 71     
100         do_facet client "rm $DIR/a" || return 72        
101         echo "setup single mount lustre success"
102 }
103
104 check_mount2() {
105         do_facet client "touch $DIR/a" || return 71     
106         do_facet client "rm $DIR/a" || return 72        
107         do_facet client "touch $DIR2/a" || return 73    
108         do_facet client "rm $DIR2/a" || return 74       
109         echo "setup double mount lustre success"
110 }
111
112 build_test_filter
113
114 #create single point mountpoint
115
116 gen_config
117
118
119 test_0() {
120         start_ost
121         start_mds       
122         mount_client $MOUNT  
123         check_mount || return 41
124         cleanup || return $?
125 }
126 run_test 0 "single mount setup"
127
128 test_1() {
129         start_ost
130         echo "start ost second time..."
131         start ost --reformat $OSTLCONFARGS 
132         start_mds       
133         mount_client $MOUNT
134         check_mount || return 42
135         cleanup || return $?
136 }
137 run_test 1 "start up ost twice"
138
139 test_2() {
140         start_ost
141         start_mds       
142         echo "start mds second time.."
143         start mds --reformat $MDSLCONFARGS 
144         
145         mount_client $MOUNT  
146         check_mount || return 43
147         cleanup || return $?
148 }
149 run_test 2 "start up mds twice"
150
151 test_3() {
152         setup
153         mount_client $MOUNT
154
155         check_mount || return 44
156         
157         umount_client $MOUNT    
158         cleanup  || return $?
159 }
160 run_test 3 "mount client twice"
161
162 test_4() {
163         setup
164         touch $DIR/$tfile || return 85
165         stop_ost --force
166         cleanup 
167         eno=$?
168         # ok for ost to fail shutdown
169         if [ 202 -ne $eno ]; then
170                 return $eno;
171         fi
172         return 0
173 }
174 run_test 4 "force cleanup ost, then cleanup"
175
176 test_5() {
177         setup
178         touch $DIR/$tfile || return 1
179         stop_mds --force || return 2
180
181         # cleanup may return an error from the failed 
182         # disconnects; for now I'll consider this successful 
183         # if all the modules have unloaded.
184         umount $MOUNT &
185         UMOUNT_PID=$!
186         sleep 2
187         echo "killing umount"
188         kill -TERM $UMOUNT_PID
189         echo "waiting for umount to finish"
190         wait $UMOUNT_PID 
191
192         # cleanup client modules
193         $LCONF --cleanup --nosetup --node client_facet $XMLCONFIG > /dev/null 
194         
195         # stop_mds is a no-op here, and should not fail
196         stop_mds  || return 4
197         stop_ost || return 5
198
199         lsmod | grep -q portals && return 6
200         return 0
201 }
202 run_test 5 "force cleanup mds, then cleanup"
203
204 test_5b() {
205         start_ost
206         start_mds
207         stop_mds
208
209         [ -d $MOUNT ] || mkdir -p $MOUNT
210         $LCONF --nosetup --node client_facet $XMLCONFIG > /dev/null 
211         llmount $mds_HOST://mds_svc/client_facet $MOUNT  && exit 1
212
213         # cleanup client modules
214         $LCONF --cleanup --nosetup --node client_facet $XMLCONFIG > /dev/null 
215         
216         # stop_mds is a no-op here, and should not fail
217         stop_mds || return 2
218         stop_ost || return 3
219
220         lsmod | grep -q portals && return 3
221         return 0
222
223 }
224 run_test 5b "mds down, cleanup after failed mount (bug 2712)"
225
226 test_5c() {
227         start_ost
228         start_mds
229
230         [ -d $MOUNT ] || mkdir -p $MOUNT
231         $LCONF --nosetup --node client_facet $XMLCONFIG > /dev/null 
232         llmount $mds_HOST://wrong_mds_svc/client_facet $MOUNT  && exit 1
233
234         # cleanup client modules
235         $LCONF --cleanup --nosetup --node client_facet $XMLCONFIG > /dev/null 
236         
237         stop_mds || return 2
238         stop_ost || return 3
239
240         lsmod | grep -q portals && return 3
241         return 0
242
243 }
244 run_test 5c "cleanup after failed mount (bug 2712)"
245
246 test_6() {
247         setup
248         manual_umount_client
249         mount_client ${MOUNT} || return 87
250         touch $DIR/a || return 86
251         cleanup  || return $?
252 }
253 run_test 6 "manual umount, then mount again"
254
255 test_7() {
256         setup
257         manual_umount_client
258         cleanup || return $?
259 }
260 run_test 7 "manual umount, then cleanup"
261
262 test_8() {
263         start_ost
264         start_mds
265
266         mount_client $MOUNT  
267         mount_client $MOUNT2 
268
269         check_mount2 || return 45
270         umount $MOUNT
271         umount_client $MOUNT2  
272         
273         stop_mds
274         stop_ost
275 }
276 run_test 8 "double mount setup"
277
278 test_9() {
279         # backup the old values of PTLDEBUG and SUBSYSTEM
280         OLDPTLDEBUG=$PTLDEBUG
281         OLDSUBSYSTEM=$SUBSYSTEM
282         
283         # generate new configuration file with lmc --ptldebug and --subsystem
284         PTLDEBUG="trace"
285         SUBSYSTEM="mdc"
286         gen_config
287
288         # check the result of lmc --ptldebug/subsystem
289         start_ost
290         start_mds
291         mount_client $MOUNT
292         CHECK_PTLDEBUG="`cat /proc/sys/portals/debug`"
293         if [ $CHECK_PTLDEBUG = "1" ]; then
294            echo "lmc --debug success"
295         else
296            echo "lmc --debug: want 1, have $CHECK_PTLDEBUG"
297            return 1
298         fi
299         CHECK_SUBSYSTEM="`cat /proc/sys/portals/subsystem_debug`"
300         if [ $CHECK_SUBSYSTEM = "2" ]; then
301            echo "lmc --subsystem success"
302         else
303            echo "lmc --subsystem: want 2, have $CHECK_SUBSYSTEM"
304            return 1
305         fi
306         check_mount || return 41
307         cleanup || return $?
308
309         # the new PTLDEBUG/SUBSYSTEM used for lconf --ptldebug/subsystem
310         PTLDEBUG="inode+trace"
311         SUBSYSTEM="mds+ost"
312
313         # check lconf --ptldebug/subsystem overriding lmc --ptldebug/subsystem
314         start_ost
315         start_mds
316         CHECK_PTLDEBUG="`do_facet mds cat /proc/sys/portals/debug`"
317         if [ $CHECK_PTLDEBUG = "3" ]; then
318            echo "lconf --debug success"
319         else
320            echo "lconf --debug: want 3, have $CHECK_PTLDEBUG"
321            return 1
322         fi
323         CHECK_SUBSYSTEM="`do_facet mds cat /proc/sys/portals/subsystem_debug`"
324         if [ $CHECK_SUBSYSTEM = "20" ]; then
325            echo "lconf --subsystem success"
326         else
327            echo "lconf --subsystem: want 20, have $CHECK_SUBSYSTEM"
328            return 1
329         fi
330         mount_client $MOUNT
331         check_mount || return 41
332         cleanup || return $?
333
334         # resume the old configuration
335         PTLDEBUG=$OLDPTLDEBUG
336         SUBSYSTEM=$OLDSUBSYSTEM
337         gen_config
338 }
339
340 run_test 9 "test --ptldebug and --subsystem for lmc and lconf"
341
342 test_10() {
343         OLDXMLCONFIG=$XMLCONFIG
344         XMLCONFIG="broken.xml"
345         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
346         SAMENAME="mds1"
347         do_lmc --add node --node $SAMENAME
348         do_lmc --add net --node $SAMENAME --nid $SAMENAME --nettype tcp
349         do_lmc --add mds --node $SAMENAME --mds $SAMENAME --nid $SAMENAME \
350                --fstype ext3 --dev /dev/mds1 || return $?
351         do_lmc --add lov --lov lov1 --mds $SAMENAME --stripe_sz 65536 \
352                --stripe_cnt 1 --stripe_pattern 0 || return $?
353         echo "Success!"
354         XMLCONFIG=$OLDXMLCONFIG
355 }
356 run_test 10 "use lmc with the same name for node and mds"
357
358 test_11() {
359         OLDXMLCONFIG=$XMLCONFIG
360         XMLCONFIG="conf11.xml"
361
362         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
363         add_mds mds --dev $MDSDEV --size $MDSSIZE
364         add_ost ost --dev $OSTDEV --size $OSTSIZE
365         add_client client mds --path $MOUNT --ost ost_svc || return $?
366         echo "Default lov config success!"
367         
368         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
369         add_mds mds --dev $MDSDEV --size $MDSSIZE
370         add_ost ost --dev $OSTDEV --size $OSTSIZE
371         add_client client mds --path $MOUNT && return $?
372         echo "--add mtpt with neither --lov nor --ost will return error"
373
374         echo ""
375         echo "Success!"
376         XMLCONFIG=$OLDXMLCONFIG
377 }
378 run_test 11 "use default lov configuration (should return error)"
379
380 test_12() {
381         OLDXMLCONFIG=$XMLCONFIG
382         XMLCONFIG="batch.xml"
383         BATCHFILE="batchfile"
384
385         # test double quote
386         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
387         [ -f "$BATCHFILE" ] && rm -f $BATCHFILE
388         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
389         echo "--add mds --node localhost --mds mds1 --mkfsoptions \"-I 128\"" >> $BATCHFILE
390         # --mkfsoptions "-I 128"
391         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
392         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
393                 echo "matched double quote success"
394         else
395                 echo "matched double quote fail"
396                 return 1
397         fi 
398         rm -f $XMLCONFIG
399         rm -f $BATCHFILE
400         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
401         echo "--add mds --node localhost --mds mds1 --mkfsoptions \"-I 128" >> $BATCHFILE
402         # --mkfsoptions "-I 128
403         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
404         echo "unmatched double quote should return error"
405
406         # test single quote
407         rm -f $BATCHFILE
408         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
409         echo "--add mds --node localhost --mds mds1 --mkfsoptions '-I 128'" >> $BATCHFILE
410         # --mkfsoptions '-I 128'
411         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
412         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
413                 echo "matched single quote success"
414         else
415                 echo "matched single quote fail"
416                 return 1
417         fi
418         rm -f $XMLCONFIG
419         rm -f $BATCHFILE
420         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
421         echo "--add mds --node localhost --mds mds1 --mkfsoptions '-I 128" >> $BATCHFILE
422         # --mkfsoptions '-I 128
423         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
424         echo "unmatched single quote should return error"
425
426         # test backslash
427         rm -f $BATCHFILE
428         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
429         echo "--add mds --node localhost --mds mds1 --mkfsoptions \-\I\ \128" >> $BATCHFILE
430         # --mkfsoptions \-\I\ \128
431         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
432         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
433                 echo "backslash followed by a whitespace/letter success"
434         else
435                 echo "backslash followed by a whitespace/letter fail"
436                 return 1
437         fi
438         rm -f $XMLCONFIG
439         rm -f $BATCHFILE
440         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
441         echo "--add mds --node localhost --mds mds1 --mkfsoptions -I\ 128\\" >> $BATCHFILE
442         # --mkfsoptions -I\ 128\
443         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
444         echo "backslash followed by nothing should return error"
445
446         rm -f $BATCHFILE
447         XMLCONFIG=$OLDXMLCONFIG
448 }
449 run_test 12 "lmc --batch, with single/double quote, backslash in batchfile"
450
451 test_13() {
452         OLDXMLCONFIG=$XMLCONFIG
453         XMLCONFIG="conf13-1.xml"
454         SECONDXMLCONFIG="conf13-2.xml"
455
456         # check long uuid will be truncated properly and uniquely
457         echo "To generate XML configuration file(with long ost name): $XMLCONFIG"
458         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
459         do_lmc --add net --node localhost --nid localhost.localdomain --nettype tcp
460         do_lmc --add mds --node localhost --mds mds1_name_longer_than_31characters
461         do_lmc --add mds --node localhost --mds mds2_name_longer_than_31characters
462         if [ ! -f "$XMLCONFIG" ]; then
463                 echo "Error:no file $XMLCONFIG created!"
464                 return 1
465         fi
466         EXPECTEDMDS1UUID="e_longer_than_31characters_UUID"
467         EXPECTEDMDS2UUID="longer_than_31characters_UUID_2"
468         FOUNDMDS1UUID=`awk -F"'" '/<mds uuid=/{print $2}' $XMLCONFIG | sed -n '1p'`
469         FOUNDMDS2UUID=`awk -F"'" '/<mds uuid=/{print $2}' $XMLCONFIG | sed -n '2p'`
470         if [ $EXPECTEDMDS1UUID != $FOUNDMDS1UUID ]; then
471                 echo "Error:expected uuid for mds1: $EXPECTEDMDS1UUID; found: $FOUNDMDS1UUID"
472                 return 1
473         fi
474         if [ $EXPECTEDMDS2UUID != $FOUNDMDS2UUID ]; then
475                 echo "Error:expected uuid for mds2: $EXPECTEDMDS2UUID; found: $FOUNDMDS2UUID"
476                 return 1
477         fi
478         echo "Success:long uuid truncated successfully and being unique."
479
480         # check multiple invocations for lmc generate same XML configuration file
481         rm -f $XMLCONFIG
482         echo "Generate the first XML configuration file"
483         gen_config
484         echo "mv $XMLCONFIG to $SECONDXMLCONFIG"
485         mv $XMLCONFIG $SECONDXMLCONFIG || return $?
486         echo "Generate the second XML configuration file"
487         gen_config
488         if [ `diff $XMLCONFIG $SECONDXMLCONFIG | wc -l` -eq 0 ]; then
489                 echo "Success:multiple invocations for lmc generate same XML file"
490         else
491                 echo "Error: multiple invocations for lmc generate different XML file"
492                 return 1
493         fi
494
495         rm -f $XMLCONFIG
496         rm -f $SECONDXMLCONFIG
497         XMLCONFIG=$OLDXMLCONFIG
498 }
499 run_test 13 "check new_uuid of lmc operating correctly"
500
501 test_14() {
502         rm -f $XMLCONFIG
503
504         # create xml file with --mkfsoptions for ost
505         echo "create xml file with --mkfsoptions for ost"
506         add_mds mds --dev $MDSDEV --size $MDSSIZE
507         add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
508             --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
509         add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE \
510             --mkfsoptions "-Llabel_conf_15"
511         add_client client mds --lov lov1 --path $MOUNT
512
513         FOUNDSTRING=`awk -F"<" '/<mkfsoptions>/{print $2}' $XMLCONFIG`
514         EXPECTEDSTRING="mkfsoptions>-Llabel_conf_15"
515         if [ $EXPECTEDSTRING != $FOUNDSTRING ]; then
516                 echo "Error: expected: $EXPECTEDSTRING; found: $FOUNDSTRING"
517                 return 1
518         fi
519         echo "Success:mkfsoptions for ost written to xml file correctly."
520
521         # mount lustre to test lconf mkfsoptions-parsing
522         echo "mount lustre"
523         start_ost
524         start_mds
525         mount_client $MOUNT || return $?
526         if [ -z "`dumpe2fs -h $OSTDEV | grep label_conf_15`" ]; then
527                 echo "Error: the mkoptions not applied to mke2fs of ost."
528                 return 1
529         fi
530         cleanup
531         echo "lconf mkfsoptions for ost success"
532
533         gen_config
534 }
535 run_test 14 "test mkfsoptions of ost for lmc and lconf"
536
537 equals_msg "Done"