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 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 function wait_process_start {
29 count=0
30 while [ $count -lt 10 ]; do
31 echo "--INFO: [$assertion]
32 Verify if testfoo.$$ is loaded and started"
33
34 pid=`ps -ef | grep testfoo.$$ | \
35 grep -v grep | awk '{print $2}' 2>/dev/null`
36 if [[ $? -eq 0 && ! -z $pid ]]; then
37 return 0
38 else
39 sleep 1
40 fi
41 count=`expr $count + 1`
42 done
43
44 #If test process not started by service in given time
45 #then fail and return 1
46
47 if [ $count -eq 10 ]; then
48 return 1
49 fi
50 }
51
52 #This function is to cleanup the leftovers by this test
53 function cleanup {
54 service_cleanup $test_service
55 /usr/bin/rm -f /var/tmp/$test_process
56
57 /usr/bin/rm -f $registration_file
58 /usr/bin/rm -f /var/tmp/testfoo.$$
59 /usr/bin/rm -f /var/tmp/$test_process
60
61 }
62
63 ###############################################################################
64 # start __stf_assertion__
65 #
66 # ASSERTION: svcadm_enable_007
67 #
68 # DESCRIPTION:
69 # Calling 'svcadm -v enable FMRI' over an instance that is
70 # currently in disabled state should transition the state to
71 # online and start any process associated with it and also
72 # should display "fmri displayed" message in output.
73 # STRATEGY:
74 # - locate for template.xml in $STF_SUITE/tests/svcadm/
75 # - Create a simple test_process that sleeps for may be 10 secs.
76 # - Generate say 'svcadm_enable_007.$$.xml' using template.xml
77 # which contains say service='test_service',
78 # instance='test_instance'
79 # execname='test_process' for both start and stop event.
80 # - Import the xml using svccfg import <.xml>
81 # - Wait until test_service loads test_process.
82 # - Now attempt to disable the service.
83 # - Make sure svcadm disable <fmri> is successful with exit 0.
84 # - Wait for the transition period from enable to disable.
85 # - Also verify that 'test_process' is no more running it is STOPPED.
86 # - Make sure now 'fmri' state is disabled.
87 # - Now attempt to enable the FMRI using svcadm -v <fmri> enable
88 # - Verify that state is transited to "online" and process is started.
89 #
90 # COMMANDS: svcadm(1)
91 #
92 # end __stf_assertion__
93 ################################################################################
94
95 # First load up definitions of STF result variables like STF_PASS etc.
96 . ${STF_TOOLS}/include/stf.kshlib
97
98 # Load up definitions of shell functionality common to all smf sub-suites.
99 . ${STF_SUITE}/include/gltest.kshlib
100 . ${STF_SUITE}/include/svc.startd_config.kshlib
101
102 # Define Variables
103 readonly assertion=svcadm_enable_007
104 readonly ME=$(whence -p ${0})
105 readonly MYLOC=$(dirname ${ME})
106 readonly registration_template=${STF_SUITE}/tests/svcadm/enable/template.xml
107 readonly registration_file=/var/tmp/svcadm_enable_007.$$.xml
108 readonly test_service="enable_007$$"
109 readonly test_instance="enable_007$$"
110 readonly test_process=enable_007.$$
111 readonly fmri="svc:/$test_service:$test_instance"
112 pid=""
113
114 # Make sure we run as root
115 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
116 then
117 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
118 echo "--DIAG: [$assertion]
119 This test must be run as root."
120 print_result $RESULT
121 exit $RESULT
122 fi
123
124 # gltest.kshlib functions to extract and print assertion information
125 # from this source script.
126 extract_assertion_info $ME
127
128 # Initialize test result to pass.
129 typeset -i RESULT=${STF_UNRESOLVED}
130
131 # Set a trap to execute the cleanup function
132 trap cleanup 0 1 2 15
133
134 # Exit code for individual commands.
135 typeset -i tmp_rc=0
136
137 # Execute environmental sanity checks.
138 check_gl_env
139 tmp_rc=$?
140 if [[ $tmp_rc -ne 0 ]]
141 then
142 echo "--DIAG: [$assertion]
143 Invalid smf environment, quitting."
144 print_result $RESULT
145 exit $RESULT
146 fi
147
148 echo "--INFO: [$assertion]
149 Verify if required template is located"
150
151 if [ ! -s $registration_template ]; then
152 echo "--DIAG: [$assertion]
153 $registration_template is not located"
154 print_result $RESULT
155 exit $RESULT
156 fi
157
158 echo "--INFO: [$assertion]
159 Create a test process in /var/tmp/$test_process"
160
161 cat > /var/tmp/$test_process << EOF
162 #!/bin/ksh -p
163 print "#!/bin/ksh -p" > /var/tmp/testfoo.$$
164 print "sleep 1000" >> /var/tmp/testfoo.$$
165 print "exit 0" >> /var/tmp/testfoo.$$
166 chmod 755 /var/tmp/testfoo.$$
167 /var/tmp/testfoo.$$ &
168 exit 0
169 EOF
170
171 echo "--INFO: [$assertion]
172 chmod 755 /var/tmp/$test_process"
173
174 chmod 755 /var/tmp/$test_process
175 if [ $? -ne 0 ]; then
176 echo "--DIAG: [$assertion]
177 chmod 755 /var/tmp/$test_process failed"
178 print_result $RESULT
179 exit $RESULT
180 fi
181
182 echo "--INFO: [$assertion]
183 Generate .xml required for this test using given template.xml"
184
185 manifest_generate $registration_template \
186 TEST_SERVICE=$test_service \
187 TEST_INSTANCE=$test_instance \
188 EXEC_NAME=/var/tmp/$test_process \
189 STOP_NAME=":kill" \
190 SERVICE_APP=$service_app \
191 STATEFILE=$service_state > $registration_file
192
193 echo "--INFO: [$assertion]
194 Verify if registration template is located and size > 0 bytes"
195
196 if [ ! -s $registration_file ]; then
197 echo "--DIAG: [$assertion]
198 $registration_file is not located"
199 print_result $RESULT
200 exit $RESULT
201 fi
202
203 echo "--INFO: [$assertion]
204 Import the service to repository using svccfg import"
205
206 svccfg import $registration_file > $svccfg_errfile 2>&1
207 if [ $? -ne 0 ]; then
208 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
209 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
210 print_result $RESULT
211 exit $RESULT
212 fi
213
214 echo "--INFO: [$assertion]
215 Wait until the testfoo.$$ is loaded by $fmri"
216
217 #This function sets variable 'pid'
218
219 wait_process_start 2>/dev/null
220 if [ $? -ne 0 ]; then
221 echo "--DIAG: [$assertion]
222 testfoo.$$ not started by svccfg -v import $registration_file"
223 print_result $RESULT
224 exit $RESULT
225 fi
226
227 echo "--INFO: [$assertion]
228 svcs -p <FMRI> and make sure $pid is printed"
229 output=`svcs -p svc:/$test_service:$test_instance | grep -w $pid | \
230 awk '{print $2}' 2>/dev/null`
231 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
232 echo "--DIAG: [$assertion]
233 svcs -p svc:/$test_service:$test_instance | grep $pid fails
234 EXPECTED: output = $pid
235 ACTUAL: output = $output"
236 print_result $RESULT
237 exit $RESULT
238 fi
239
240 echo "--INFO: [${assertion}]
241 disable <$fmri> using svcadm"
242
243 svcadm disable svc:/$test_service:$test_instance >/dev/null 2>&1
244 ret=$?
245 if [ $ret -ne 0 ]; then
246 echo "--DIAG: [$assertion]
247 svcadm disable svc:/$test_service:$test_instance fails
248 EXPECTED: output = ret 0
249 ACTUAL: output ret = $ret"
250 print_result $RESULT
251 exit $RESULT
252 fi
253
254 echo "--INFO: [${assertion}]
255 Wait until STATE gets updated"
256
257 service_wait_state $test_service:$test_instance disabled
258 if [ $? -ne 0 ]; then
259 echo "--DIAG: [$assertion]
260 <$test_service> is not disabled"
261 print_result $RESULT
262 exit $RESULT
263 fi
264
265 echo "--INFO: [${assertion}]
266 Make sure svcs -p $test_service doesn't print $pid"
267
268 svcs -p svc:/$test_service:$test_instance | grep -w $pid >/dev/null 2>&1
269 if [ $? -eq 0 ]; then
270 echo "--DIAG: [$assertion]
271 svcs -p svc:/$test_service:$test_instance | grep $pid should
272 fail; It means svcs -p shouldn't print process info as the
273 process is dead"
274 print_result $RESULT
275 exit $RESULT
276 fi
277
278 echo "--INFO: [${assertion}]
279 Make sure process is really dead using ps"
280
281 ps -ef | grep -w $pid | grep -v grep >/dev/null 2>&1
282 if [ $? -eq 0 ]; then
283 echo "--DIAG: [$assertion]
284 ps -ef | grep $pid should fail"
285 print_result $RESULT
286 exit $RESULT
287 fi
288
289
290 echo "--INFO: [${assertion}]
291 enable <$fmri> using svcadm -v <$fmri> enable"
292
293 output=`svcadm -v enable svc:/$test_service:$test_instance 2>/dev/null`
294 ret=$?
295 if [[ $ret -ne 0 || "$output" != "$fmri enabled." ]]; then
296 RESULT=$(update_result $STF_FAIL $RESULT)
297 echo "--DIAG: [$assertion]
298 svcadm disable svc:/$test_service:$test_instance fails
299 EXPECTED: exit = ret 0, output=svc:/$test_service:$test_instance enabled
300 ACTUAL: exit ret = $ret, output=$fmri enabled."
301 print_result $RESULT
302 exit $RESULT
303 fi
304
305 echo "--INFO: [${assertion}]
306 Wait until STATE gets updated"
307
308 service_wait_state $test_service:$test_instance online
309 if [ $? -ne 0 ]; then
310 RESULT=$(update_result $STF_FAIL $RESULT)
311 echo "--DIAG: [$assertion]
312 <$test_service> is not online"
313 print_result $RESULT
314 exit $RESULT
315 fi
316
317 echo "--INFO: [$assertion]
318 Wait until the testfoo.$$ is loaded by $fmri"
319
320 #This function sets variable 'pid'
321
322 wait_process_start 2>/dev/null
323 if [ $? -ne 0 ]; then
324 RESULT=$(update_result $STF_FAIL $RESULT)
325 echo "--DIAG: [$assertion]
326 testfoo.$$ not started by svcadm enable $fmri"
327 print_result $RESULT
328 exit $RESULT
329 fi
330
331 echo "--INFO: [$assertion]
332 svcs -p <FMRI> and make sure $pid is printed"
333
334 output=`svcs -p svc:/$test_service:$test_instance | grep $pid | \
335 awk '{print $2}' 2>/dev/null`
336 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
337 RESULT=$(update_result $STF_FAIL $RESULT)
338 echo "--DIAG: [$assertion]
339 svcs -p svc:/$test_service:$test_instance | grep $pid fails
340 EXPECTED: output = $pid
341 ACTUAL: output = $output"
342 print_result $RESULT
343 exit $RESULT
344 fi
345
346 RESULT=$STF_PASS
347 print_result $RESULT
348 exit $RESULT