1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # ident "@(#)share_reboot.ksh 1.4 09/08/16 SMI"
28 #
29
30 #
31 # reboot test cases
32 #
33
34 tet_startup="startup"
35 tet_cleanup="cleanup"
36
37 iclist="ic1"
38 ic1="reboot001"
39
40 #__stc_assertion_start
41 #
42 #ID: reboot001
43 #
44 #DESCRIPTION:
45 #
46 # Check if shares and groups can survive system reboot.
47 #
48 #STRATEGY:
49 #
50 # Setup:
51 # - Create share groups and shares.
52 # Test:
53 # - Save needed information and reboot system, and
54 # make sure the groups and share are still there.
55 # Cleanup:
56 # - Make sure to recover ufs test file systems.
57 #
58 # STRATEGY_NOTES:
59 # - To complete this reboot test and obtain its final
60 # result, you must run 'reboot' scenario again after
61 # system comes back, ie. run the same command for
62 # two times:
63 # run_test -F <path-to-config-file> share reboot
64 #
65 #KEYWORDS:
66 #
67 # share after reboot
68 #
69 #TESTABILITY: explicit
70 #
71 #AUTHOR: sean.wilcox@sun.com
72 #
73 #REVIEWERS: TBD
74 #
75 #TEST_AUTOMATION_LEVEL: automated
76 #
77 #CODING_STATUS: COMPLETE
78 #
79 #__stc_assertion_end
80 function reboot001 {
81 tet_result PASS
82 tc_id="reboot001"
83 tc_desc="Create several shares and groups and confirm they survive a reboot"
84 cmd_list=""
85 unset GROUPS
86 print_test_case $tc_id - $tc_desc
87 if [[ ! -f $SHR_TMPDIR/sharemgr_reboot ]]; then
88 #
89 # Setup
90 #
91 create ${TG[0]}
92 add_share POS ${TG[0]} "" ${MP[0]}
93
94 create ${TG[1]}
95 add_share POS ${TG[1]} "" ${MP[1]}
96 disable "" ${TG[1]}
97 #
98 # XXXX - Add the temporary share and confirm that it is
99 # removed upon reboot. This can be done once the updates
100 # to the add_share for temporary shares is worked out.
101 #
102 # add_share POS ${TG[1]} "-t" ${MP[2]}
103 #
104 # Need to store off information for next round of
105 # tests when the reboot comes back up.
106 #
107 set | grep "ShTst" > $SHR_TMPDIR/sharemgr_reboot.env
108 set | grep "EXP_STATE_" >> $SHR_TMPDIR/sharemgr_reboot.env
109 set | grep "SHARES_" >> $SHR_TMPDIR/sharemgr_reboot.env
110 echo "real_groups=\"$real_groups\"" >> \
111 $SHR_TMPDIR/sharemgr_reboot.env
112 echo "${TG[0]}:${MP[0]}" > $SHR_TMPDIR/sharemgr_reboot
113 echo "${TG[1]}:${MP[1]}" >> $SHR_TMPDIR/sharemgr_reboot
114 #
115 # Make sure ufs file systems are setup to persist across
116 # a reboot.
117 #
118 addufstovfstab
119 (( $? != 0 )) && return
120 tet_infoline "Rebooting...."
121 reboot
122 else
123 # need to remount the ufs manually after reboot
124 typeset -i need_remnt=0
125 # check if it is UFS as expected, as it will become zfs if
126 # it was unmounted on zfs boot system
127 df -F ufs ${MP[0]} > $SHR_TMPDIR/mp.df.$$ 2>&1
128 if (( $? != 0 )); then
129 need_remnt=1
130 else
131 grep ${MP[0]} $SHR_TMPDIR/mp.df.$$ > \
132 $SHR_TMPDIR/mp.grep.$$
133 if (( $? != 0 )); then
134 need_remnt=1
135 else
136 # check if the device to mount is our expected
137 typeset expdev=$(grep ${MP[0]} /etc/vfstab \
138 | awk '{print $1}')
139 typeset curdev=$(tail -1 $SHR_TMPDIR/mp.grep.$$ \
140 | awk -F\( '{print $2}' \
141 | awk -F\) '{print $1}')
142 [[ $curdev != $expdev ]] && need_remnt=1
143 fi
144 rm -f $SHR_TMPDIR/mp.grep.$$
145 fi
146 rm -f $SHR_TMPDIR/mp.df.$$
147 if (( $need_remnt != 0 )); then
148 typeset ERRMSG="The required test ufs ${MP[0]} "
149 ERRMSG="${ERRMSG}and/or ${MP[2]} cannot be remounted\n"
150 ERRMSG="${ERRMSG}after reboot, which may cause other "
151 ERRMSG="${ERRMSG}tests to fail, so it should be safer\n"
152 ERRMSG="${ERRMSG}to unconfigure it and do cleanup "
153 ERRMSG="${ERRMSG}manually if needed."
154 # try to remount it based on the entry logged in vfstab,
155 # if it failed, we need to refresh the zfs pool for
156 # making its volumes can be used and mounted as before.
157 mount ${MP[2]} > $SHR_TMPDIR/mp.mnt.$$ 2>&1
158 if (( $? == 0 )); then
159 mount -O ${MP[0]} > $SHR_TMPDIR/mp.mnt.$$ 2>&1
160 if (( $? != 0 )); then
161 cti_reportfile $SHR_TMPDIR/mp.mnt.$$ \
162 "WARNING: failed to remount ufs ${MP[0]}"
163 tet_infoline "$ERRMSG"
164 fi
165 else
166 typeset zfspool="share_pool"
167 [[ -n $ZFSPOOL ]] && zfspool=$ZFSPOOL
168 zpool export $zfspool > \
169 $SHR_TMPDIR/zp.ref.$$ 2>&1
170 typeset -i do_remnt=$?
171 zpool import -d $TESTDIR $zfspool >> \
172 $SHR_TMPDIR/zp.ref.$$ 2>&1
173 do_remnt=$((do_remnt + $?))
174
175 if (( $do_remnt == 0 )); then
176 mount ${MP[2]} > $SHR_TMPDIR/mp.mnt.$$ 2>&1
177 if (( $? != 0 )); then
178 cti_reportfile $SHR_TMPDIR/mp.mnt.$$ \
179 "WARNING: failed to remount ufs ${MP[2]}"
180 tet_infoline "$ERRMSG"
181 fi
182 mount -O ${MP[0]} > $SHR_TMPDIR/mp.mnt.$$ 2>&1
183 if (( $? != 0 )); then
184 cti_reportfile $SHR_TMPDIR/mp.mnt.$$ \
185 "WARNING: failed to remount ufs ${MP[0]}"
186 tet_infoline "$ERRMSG"
187 fi
188 else
189 cti_reportfile $SHR_TMPDIR/zp.ref.$$ \
190 "WARNING: failed to refresh zpool $ZFSPOOL"
191 tet_infoline "$ERRMSG"
192 fi
193 rm -f $SHR_TMPDIR/zp.ref.$$
194 fi
195 rm -f $SHR_TMPDIR/mp.mnt.$$
196 fi
197
198 #
199 # Use the sharemgr_reboot bits to confirm all
200 # shares are still shared.
201 #
202 tet_infoline "Verify the groups ${TG[0]} and ${TG[1]} are in the"
203 eval ES_tmp0=\"\$EXP_STATE_${TG[0]}\"
204 eval ES_tmp1=\"\$EXP_STATE_${TG[1]}\"
205 tet_infoline "correct state ${ES_tmp0} and ${ES_tmp1}"
206 verify_groups ${TG[0]} ${TG[1]}
207 tet_infoline "Verify the ${MP[0]} belongs to ${TG[0]}"
208 verify_share ${MP[0]}
209 tet_infoline "Verify the ${MP[1]} belongs to ${TG[1]}"
210 verify_share ${MP[1]}
211
212 #
213 # Cleanup
214 #
215 while read line; do
216 GROUPS="$GROUPS `echo $line | awk -F":" '{print $1}'`"
217 done < $SHR_TMPDIR/sharemgr_reboot
218 rm $SHR_TMPDIR/sharemgr_reboot
219 rm $SHR_TMPDIR/sharemgr_reboot.env
220 mv /etc/vfstab.sharemgr_tests.orig /etc/vfstab
221 (( $? != 0 )) && tet_infoline \
222 "WARNING : Unable to restore the original vfstab"
223 delete_all_test_groups
224 report_cmds $tc_id POS
225 fi
226 }
227
228 function startup
229 {
230 tet_infoline "Checking environment and runability"
231 if [[ ! -f $SHR_TMPDIR/sharemgr_reboot ]]; then
232 tet_infoline "Calling share_startup...."
233 share_startup
234 $CAT << __EOF__ > /etc/rc3.d/S99tetrestart
235 #!/bin/ksh
236
237 TET_ROOT=$TET_ROOT
238 TET_SUITE_ROOT=$TET_SUITE_ROOT
239
240 export TET_ROOT TET_SUITE_ROOT
241
242 ${TET_ROOT}/bin/tcc -e share reboot
243 __EOF__
244 chmod 755 /etc/rc3.d/S99tetrestart
245 else
246 tet_infoline "Calling minimal share_startup...."
247 share_startup True
248 #
249 # Need to reload some environment variables to
250 # use.
251 #
252 . $SHR_TMPDIR/sharemgr_reboot.env
253 rm /etc/rc3.d/S99tetrestart
254 fi
255 }
256
257 function cleanup
258 {
259 tet_infoline "Cleaning up after tests"
260 if [[ -f $SHR_TMPDIR/sharemgr_reboot ]]; then
261 #
262 # Should not get here when the file exists.
263 # Need to do some extra cleanup.
264 #
265 # Reset the GROUPS variable based on sharemgr_reboot
266 #
267 while read line; do
268 GROUPS="$GROUPS `echo $line | awk -F":" '{print $1}'`"
269 done < $SHR_TMPDIR/sharemgr_reboot
270 rm $SHR_TMPDIR/sharemgr_reboot
271 tet_infoline "cleanup : GROUPS = $GROUPS"
272 delete_all_test_groups
273 fi
274 share_cleanup
275 }
276
277 . ${TET_SUITE_ROOT}/sharefs-tests/lib/share_common
278
279 . ${TET_ROOT}/common/lib/ctiutils.ksh
280 . ${TET_ROOT}/lib/ksh/tcm.ksh