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