Whamcloud - gitweb
34ba23159ab780680b2c84da96e390a9fbb34530
[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 $TIMEOUT
187         echo "killing umount"
188         kill -TERM $UMOUNT_PID
189         wait $UMOUNT_PID 
190
191         # cleanup client modules
192         $LCONF --cleanup --nosetup --node client_facet $XMLCONFIG > /dev/null 
193         
194         # stop_mds is a no-op here, and should not fail
195         stop_mds  || return 4
196         stop_ost || return 5
197
198         lsmod | grep -q portals && return 6
199         return 0
200 }
201 run_test 5 "force cleanup mds, then cleanup"
202
203 test_6() {
204         setup
205         manual_umount_client
206         mount_client ${MOUNT} || return 87
207         touch $DIR/a || return 86
208         cleanup  || return $?
209 }
210 run_test 6 "manual umount, then mount again"
211
212 test_7() {
213         setup
214         manual_umount_client
215         cleanup || return $?
216 }
217 run_test 7 "manual umount, then cleanup"
218
219 test_8() {
220         start_ost
221         start_mds
222
223         mount_client $MOUNT  
224         mount_client $MOUNT2 
225
226         check_mount2 || return 45
227         umount $MOUNT
228         umount_client $MOUNT2  
229         
230         stop_mds
231         stop_ost
232 }
233 run_test 8 "double mount setup"
234
235 test_9() {
236         # backup the old values of PTLDEBUG and SUBSYSTEM
237         OLDPTLDEBUG=$PTLDEBUG
238         OLDSUBSYSTEM=$SUBSYSTEM
239         
240         # generate new configuration file with lmc --ptldebug and --subsystem
241         PTLDEBUG="trace"
242         SUBSYSTEM="mdc"
243         gen_config
244
245         # check the result of lmc --ptldebug/subsystem
246         start_ost
247         start_mds
248         mount_client $MOUNT
249         CHECK_PTLDEBUG="`cat /proc/sys/portals/debug`"
250         if [ $CHECK_PTLDEBUG = "1" ]; then
251            echo "lmc --debug success"
252         else
253            echo "lmc --debug: want 1, have $CHECK_PTLDEBUG"
254            return 1
255         fi
256         CHECK_SUBSYSTEM="`cat /proc/sys/portals/subsystem_debug`"
257         if [ $CHECK_SUBSYSTEM = "2" ]; then
258            echo "lmc --subsystem success"
259         else
260            echo "lmc --subsystem: want 2, have $CHECK_SUBSYSTEM"
261            return 1
262         fi
263         check_mount || return 41
264         cleanup || return $?
265
266         # the new PTLDEBUG/SUBSYSTEM used for lconf --ptldebug/subsystem
267         PTLDEBUG="inode+trace"
268         SUBSYSTEM="mds+ost"
269
270         # check lconf --ptldebug/subsystem overriding lmc --ptldebug/subsystem
271         start_ost
272         start_mds
273         CHECK_PTLDEBUG="`do_facet mds cat /proc/sys/portals/debug`"
274         if [ $CHECK_PTLDEBUG = "3" ]; then
275            echo "lconf --debug success"
276         else
277            echo "lconf --debug: want 3, have $CHECK_PTLDEBUG"
278            return 1
279         fi
280         CHECK_SUBSYSTEM="`do_facet mds cat /proc/sys/portals/subsystem_debug`"
281         if [ $CHECK_SUBSYSTEM = "20" ]; then
282            echo "lconf --subsystem success"
283         else
284            echo "lconf --subsystem: want 20, have $CHECK_SUBSYSTEM"
285            return 1
286         fi
287         mount_client $MOUNT
288         check_mount || return 41
289         cleanup || return $?
290
291         # resume the old configuration
292         PTLDEBUG=$OLDPTLDEBUG
293         SUBSYSTEM=$OLDSUBSYSTEM
294         gen_config
295 }
296
297 run_test 9 "test --ptldebug and --subsystem for lmc and lconf"
298
299 test_10() {
300         OLDXMLCONFIG=$XMLCONFIG
301         XMLCONFIG="broken.xml"
302         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
303         SAMENAME="mds1"
304         do_lmc --add node --node $SAMENAME
305         do_lmc --add net --node $SAMENAME --nid $SAMENAME --nettype tcp
306         do_lmc --add mds --node $SAMENAME --mds $SAMENAME --nid $SAMENAME \
307                --fstype ext3 --dev /dev/mds1 || return $?
308         do_lmc --add lov --lov lov1 --mds $SAMENAME --stripe_sz 65536 \
309                --stripe_cnt 1 --stripe_pattern 0 || return $?
310         echo "Success!"
311         XMLCONFIG=$OLDXMLCONFIG
312 }
313 run_test 10 "use lmc with the same name for node and mds"
314
315 test_11() {
316         OLDXMLCONFIG=$XMLCONFIG
317         XMLCONFIG="conf11.xml"
318
319         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
320         add_mds mds --dev $MDSDEV --size $MDSSIZE
321         add_ost ost --dev $OSTDEV --size $OSTSIZE
322         add_client client mds --path $MOUNT --ost ost_svc || return $?
323         echo "Default lov config success!"
324         
325         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
326         add_mds mds --dev $MDSDEV --size $MDSSIZE
327         add_ost ost --dev $OSTDEV --size $OSTSIZE
328         add_client client mds --path $MOUNT && return $?
329         echo "--add mtpt with neither --lov nor --ost will return error"
330
331         echo ""
332         echo "Success!"
333         XMLCONFIG=$OLDXMLCONFIG
334 }
335 run_test 11 "use default lov configuration (should return error)"
336
337 test_12() {
338         OLDXMLCONFIG=$XMLCONFIG
339         XMLCONFIG="batch.xml"
340         BATCHFILE="batchfile"
341
342         # test double quote
343         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
344         [ -f "$BATCHFILE" ] && rm -f $BATCHFILE
345         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
346         echo "--add mds --node localhost --mds mds1 --mkfsoptions \"-I 128\"" >> $BATCHFILE
347         # --mkfsoptions "-I 128"
348         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
349         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
350                 echo "matched double quote success"
351         else
352                 echo "matched double quote fail"
353                 return 1
354         fi 
355         rm -f $XMLCONFIG
356         rm -f $BATCHFILE
357         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
358         echo "--add mds --node localhost --mds mds1 --mkfsoptions \"-I 128" >> $BATCHFILE
359         # --mkfsoptions "-I 128
360         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
361         echo "unmatched double quote should return error"
362
363         # test single quote
364         rm -f $BATCHFILE
365         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
366         echo "--add mds --node localhost --mds mds1 --mkfsoptions '-I 128'" >> $BATCHFILE
367         # --mkfsoptions '-I 128'
368         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
369         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
370                 echo "matched single quote success"
371         else
372                 echo "matched single quote fail"
373                 return 1
374         fi
375         rm -f $XMLCONFIG
376         rm -f $BATCHFILE
377         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
378         echo "--add mds --node localhost --mds mds1 --mkfsoptions '-I 128" >> $BATCHFILE
379         # --mkfsoptions '-I 128
380         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
381         echo "unmatched single quote should return error"
382
383         # test backslash
384         rm -f $BATCHFILE
385         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
386         echo "--add mds --node localhost --mds mds1 --mkfsoptions \-\I\ \128" >> $BATCHFILE
387         # --mkfsoptions \-\I\ \128
388         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
389         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
390                 echo "backslash followed by a whitespace/letter success"
391         else
392                 echo "backslash followed by a whitespace/letter fail"
393                 return 1
394         fi
395         rm -f $XMLCONFIG
396         rm -f $BATCHFILE
397         echo "--add net --node  localhost --nid localhost.localdomain --nettype tcp" > $BATCHFILE
398         echo "--add mds --node localhost --mds mds1 --mkfsoptions -I\ 128\\" >> $BATCHFILE
399         # --mkfsoptions -I\ 128\
400         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
401         echo "backslash followed by nothing should return error"
402
403         rm -f $BATCHFILE
404         XMLCONFIG=$OLDXMLCONFIG
405 }
406 run_test 12 "lmc --batch, with single/double quote, backslash in batchfile"
407
408 test_13() {
409         OLDXMLCONFIG=$XMLCONFIG
410         XMLCONFIG="conf13-1.xml"
411         SECONDXMLCONFIG="conf13-2.xml"
412
413         # check long uuid will be truncated properly and uniquely
414         echo "To generate XML configuration file(with long ost name): $XMLCONFIG"
415         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
416         do_lmc --add net --node localhost --nid localhost.localdomain --nettype tcp
417         do_lmc --add mds --node localhost --mds mds1_name_longer_than_31characters
418         do_lmc --add mds --node localhost --mds mds2_name_longer_than_31characters
419         if [ ! -f "$XMLCONFIG" ]; then
420                 echo "Error:no file $XMLCONFIG created!"
421                 return 1
422         fi
423         EXPECTEDMDS1UUID="e_longer_than_31characters_UUID"
424         EXPECTEDMDS2UUID="longer_than_31characters_UUID_2"
425         FOUNDMDS1UUID=`awk -F"'" '/<mds uuid=/{print $2}' $XMLCONFIG | sed -n '1p'`
426         FOUNDMDS2UUID=`awk -F"'" '/<mds uuid=/{print $2}' $XMLCONFIG | sed -n '2p'`
427         if [ $EXPECTEDMDS1UUID != $FOUNDMDS1UUID ]; then
428                 echo "Error:expected uuid for mds1: $EXPECTEDMDS1UUID; found: $FOUNDMDS1UUID"
429                 return 1
430         fi
431         if [ $EXPECTEDMDS2UUID != $FOUNDMDS2UUID ]; then
432                 echo "Error:expected uuid for mds2: $EXPECTEDMDS2UUID; found: $FOUNDMDS2UUID"
433                 return 1
434         fi
435         echo "Success:long uuid truncated successfully and being unique."
436
437         # check multiple invocations for lmc generate same XML configuration file
438         rm -f $XMLCONFIG
439         echo "Generate the first XML configuration file"
440         gen_config
441         echo "mv $XMLCONFIG to $SECONDXMLCONFIG"
442         mv $XMLCONFIG $SECONDXMLCONFIG || return $?
443         echo "Generate the second XML configuration file"
444         gen_config
445         if [ `diff $XMLCONFIG $SECONDXMLCONFIG | wc -l` -eq 0 ]; then
446                 echo "Success:multiple invocations for lmc generate same XML file"
447         else
448                 echo "Error: multiple invocations for lmc generate different XML file"
449                 return 1
450         fi
451
452         rm -f $XMLCONFIG
453         rm -f $SECONDXMLCONFIG
454         XMLCONFIG=$OLDXMLCONFIG
455 }
456 run_test 13 "check new_uuid of lmc operating correctly"
457
458 test_14() {
459         rm -f $XMLCONFIG
460
461         # create xml file with --mkfsoptions for ost
462         echo "create xml file with --mkfsoptions for ost"
463         add_mds mds --dev $MDSDEV --size $MDSSIZE
464         add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
465             --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
466         add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE \
467             --mkfsoptions "-Llabel_conf_15"
468         add_client client mds --lov lov1 --path $MOUNT
469
470         FOUNDSTRING=`awk -F"<" '/<mkfsoptions>/{print $2}' $XMLCONFIG`
471         EXPECTEDSTRING="mkfsoptions>-Llabel_conf_15"
472         if [ $EXPECTEDSTRING != $FOUNDSTRING ]; then
473                 echo "Error: expected: $EXPECTEDSTRING; found: $FOUNDSTRING"
474                 return 1
475         fi
476         echo "Success:mkfsoptions for ost written to xml file correctly."
477
478         # mount lustre to test lconf mkfsoptions-parsing
479         echo "mount lustre"
480         start_ost
481         start_mds
482         mount_client $MOUNT || return $?
483         if [ -z "`dumpe2fs -h $OSTDEV | grep label_conf_15`" ]; then
484                 echo "Error: the mkoptions not applied to mke2fs of ost."
485                 return 1
486         fi
487         cleanup
488         echo "lconf mkfsoptions for ost success"
489
490         gen_config
491 }
492 run_test 14 "test mkfsoptions of ost for lmc and lconf"
493
494 equals_msg "Done"