1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # ident "@(#)startup_cleanup_common.ksh 1.3 09/01/23 SMI"
27 #
28
29 #
30 # NAME
31 # lofi_check
32 #
33 # SYNOPSIS
34 # lofi_check
35 #
36 # DESCRIPTION
37 # Make sure the system looks sane and usable from a lofi point
38 # of view. Expected to be called by startup() functions in 'tc' files.
39 #
40 # RETURN VALUES
41 # 0 Everything looks ok
42 # 1 Issue found with lofi
43 #
44 function lofi_check {
45 typeset retval=0
46
47 if [[ ! -x /usr/sbin/lofiadm ]]; then
48 cti_report "/usr/sbin/lofiadm does not exist or is not" \
49 "executable"
50 retval=1
51 fi
52
53 if [[ -d /dev/lofi ]]; then
54 cti_report "Error: /dev/lofi already exists -- there appears" \
55 "to be a preexisting lofi config"
56 cti_report "Delete any existing lofi devices and make sure" \
57 "that the /dev/lofi directory has been deleted as well"
58 retval=1
59 fi
60
61 return $retval
62 }
63
64
65 #
66 # NAME
67 # scratch_dir_check
68 #
69 # SYNOPSIS
70 # scratch_dir_check
71 #
72 # DESCRIPTION
73 # Verify that the SCRATCH_DIR variable has been set and points to
74 # a valid location.
75 #
76 # RETURN VALUES
77 # 0 Verification of SCRATCH_DIR succeeded
78 # 1 Verification of SCRATCH_DIR failed
79 function scratch_dir_check {
80 typeset status=0
81
82 if [[ -n "$SCRATCH_DIR" ]]; then
83 if [[ ! -d "$SCRATCH_DIR" ]]; then
84 cti_report "Error: value of SCRATCH_DIR" \
85 "($SCRATCH_DIR) is not a directory"
86 status=1
87 fi
88 else
89 cti_report "Error: SCRATCH_DIR not set."
90 status=1
91 fi
92
93 if (( $status != 0 )); then
94 cti_report "The SCRATCH_DIR environment variable must point" \
95 "to a valid directory."
96 cti_report "Set it either in" \
97 "\$TET_SUITE_ROOT/lofi/config/test_config or when" \
98 "invoking the test suite"
99 cti_report "e.g. run_test -v SCRATCH_DIR=<value> lofi"
100 fi
101
102 return $status
103 }
104
105
106 #
107 # NAME
108 # global_zone_check
109 #
110 # SYNOPSIS
111 # global_zone_check
112 #
113 # DESCRIPTION
114 # Check to see if we're running in the global zone
115 #
116 # RETURN VALUES
117 # 0 Running in global zone
118 # 1 Running in named zone
119 #
120 function global_zone_check {
121 typeset -r ZONEADM=/usr/sbin/zoneadm
122
123 if [[ -x $ZONEADM ]]; then
124 # zoneadm executable exists. Execute 'zoneadm list' and
125 # see if the global zone is listed. If so, we're running
126 # in the global zone. If not, we're running in a named zone.
127 $ZONEADM list | grep global >/dev/null
128 if (( $? == 0 )); then
129 return 0
130 else
131 return 1
132 fi
133 else
134 # No zoneadm executable on this system, so we must be
135 # running in the equivelent of the global zone.
136 return 0
137 fi
138
139 }
140
141
142 #
143 # NAME
144 # mnt_check
145 #
146 # SYNOPSIS
147 # mnt_check
148 #
149 # DESCRIPTION
150 # Verify that the directory /mnt exists and that there is not
151 # currently a filesystem mounted there.
152 #
153 # RETURN VALUES
154 # 0 /mnt exists and no filesystem mounted
155 # 1 /mnt does not exist, or exists but has a filesystem
156 # mounted.
157 #
158 function mnt_check {
159 # Is /mnt a directory?
160 if [[ ! -d /mnt ]]; then
161 cti_report "Error: Directory /mnt does not exist. This" \
162 "directory must exist for the tests to run."
163 return 1
164 fi
165
166 # Is something currently mounted on /mnt?
167 typeset mnt_fs=`awk ' { if ($2 == "/mnt") { print } } ' /etc/mnttab`
168 if [[ -n "$mnt_fs" ]]; then
169 cti_report "Error: /etc/mnttab indicates a filesystem is" \
170 "currently mounted on /mnt. The filesystem must be" \
171 "unmounted before the tests can continue."
172 return 1;
173 fi
174
175 return 0
176 }
177
178 #
179 # NAME
180 # root_check
181 #
182 # SYNOPSIS
183 # root_check
184 #
185 # DESCRIPTION
186 # Verify if we're being executed with root permissions.
187 #
188 # RETURN VALUES
189 # 0 Executing as root
190 # 1 Not executing as root
191 #
192 function root_check {
193 # Use /usr/xpg4/bin/id rather than /usr/bin/id as the latter does not
194 # support the '-u' flag on s10.
195 typeset uid=`/usr/xpg4/bin/id -u`
196 if (( $uid == 0 )); then
197 # Executing as root
198 return 0
199 else
200 # Not executing as root
201 cti_report "Error: Test suite must be executed with root" \
202 "permissions (uid reported as $uid, not 0)"
203 return 1
204 fi
205 }
206
207
208 #
209 # NAME
210 # typical_startup_checks
211 #
212 # SYNOPSIS
213 # typical_startup_checks
214 #
215 # DESCRIPTION
216 # Run all of the typical startup checks.
217 #
218 # RETURN VALUES
219 # 0 All checks passed
220 # non-0 One or more checks failed
221 #
222 function typical_startup_checks {
223 typeset status=0
224 typeset gzstatus
225
226 scratch_dir_check
227 (( status = $status + $? ))
228 lofi_check
229 (( status = $status + $? ))
230 mnt_check
231 (( status = $status + $? ))
232 root_check
233 (( status = $status + $? ))
234 global_zone_check
235 gzstatus=$?
236 if (( $gzstatus != 0 )); then
237 cti_report "Appear to be running in a named zone. lofi is" \
238 "only supported in the global zone."
239 fi
240 (( status = $status + $gzstatus ))
241
242 return $status
243 }