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 #This function is to cleanup the leftovers by this test
29
30 function wait_process_start {
31 count=0
32 while [ $count -lt 10 ]; do
33 echo "--INFO: [$assertion]
34 Verify if testfoo.$$ is loaded and started"
35
36 pid=`ps -ef | grep testfoo.$$ | \
37 grep -v grep | awk '{print $2}' 2>/dev/null`
38 if [[ $? -eq 0 && ! -z $pid ]]; then
39 return 0
40 else
41 sleep 1
42 fi
43 count=`expr $count + 1`
44 done
45
46 #If test process not started by service in given time
47 #then fail and return 1
48
49 if [ $count -eq 10 ]; then
50 return 1
51 fi
52 }
53
54 function cleanup {
55 service_cleanup $test_service
56 /usr/bin/rm -f /var/tmp/$test_process
57
58 /usr/bin/rm -f $registration_file
59 /usr/bin/rm -f /var/tmp/testfoo.$$
60 /usr/bin/rm -f /var/tmp/$test_process
61
62 }
63
64 ###############################################################################
65 # start __stf_assertion__
66 #
67 # ASSERTION: svcadm_disable_003
68 #
69 # DESCRIPTION:
70 # Calling 'svcadm disable FMRI' where FMRI is a service instance that is
71 # in the enabled state will result in the service being stopped and
72 # being transitioned into disabled state. The exit status shall be 0
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_disable_003.$$.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 <service> 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 'service' state is disabled.
87 #
88 # COMMANDS: svcadm(1)
89 #
90 # end __stf_assertion__
91 ################################################################################
92
93 # First load up definitions of STF result variables like STF_PASS etc.
94 . ${STF_TOOLS}/include/stf.kshlib
95
96 # Load up definitions of shell functionality common to all smf sub-suites.
97 . ${STF_SUITE}/include/gltest.kshlib
98 . ${STF_SUITE}/include/svc.startd_config.kshlib
99
100 # Define Variables
101 readonly assertion=svcadm_disable_003
102 readonly ME=$(whence -p ${0})
103 readonly MYLOC=$(dirname ${ME})
104 readonly registration_template=${STF_SUITE}/tests/svcadm/disable/template.xml
105 readonly registration_file=/var/tmp/svcadm_disable_003.$$.xml
106 readonly test_service="disable_003$$"
107 readonly test_instance="disable_003$$"
108 readonly test_process=disable_003.$$
109 pid=""
110
111 # Make sure we run as root
112 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
113 then
114 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
115 echo "--DIAG: [$assertion]
116 This test must be run from root."
117 print_result $RESULT
118 exit $RESULT
119 fi
120
121 # gltest.kshlib functions to extract and print assertion information
122 # from this source script.
123 extract_assertion_info $ME
124
125 # Initialize test result to pass.
126 typeset -i RESULT=${STF_UNRESOLVED}
127
128 # Set a trap to execute the cleanup function
129 trap cleanup 0 1 2 15
130
131 # Exit code for individual commands.
132 typeset -i tmp_rc=0
133
134 # Execute environmental sanity checks.
135 check_gl_env
136 tmp_rc=$?
137 if [[ $tmp_rc -ne 0 ]]
138 then
139 echo "--DIAG: [$assertion]
140 Invalid smf environment, quitting."
141 print_result $RESULT
142 exit $RESULT
143 fi
144
145 echo "--INFO: [$assertion]
146 Verify if required template is located"
147
148 if [ ! -s $registration_template ]; then
149 echo "--DIAG: [$assertion]
150 $registration_template is not located"
151 print_result $RESULT
152 exit $RESULT
153 fi
154
155 echo "--INFO: [$assertion]
156 Create a test process in /var/tmp/$test_process"
157
158 cat > /var/tmp/$test_process << EOF
159 #!/bin/ksh -p
160 print "#!/bin/ksh -p" > /var/tmp/testfoo.$$
161 print "sleep 1000" >> /var/tmp/testfoo.$$
162 print "exit 0" >> /var/tmp/testfoo.$$
163 chmod 755 /var/tmp/testfoo.$$
164 /var/tmp/testfoo.$$ &
165 exit 0
166 EOF
167
168 echo "--INFO: [$assertion]
169 chmod 755 /var/tmp/$test_process"
170
171 chmod 755 /var/tmp/$test_process
172 if [ $? -ne 0 ]; then
173 echo "--DIAG: [$assertion]
174 chmod 755 /var/tmp/$test_process failed"
175 print_result $RESULT
176 exit $RESULT
177 fi
178
179 echo "--INFO: [$assertion]
180 Generate .xml required for this test using given template.xml"
181
182 manifest_generate $registration_template \
183 TEST_SERVICE=$test_service \
184 TEST_INSTANCE=$test_instance \
185 EXEC_NAME=/var/tmp/$test_process \
186 STOP_NAME=":kill" \
187 SERVICE_APP=$service_app \
188 STATEFILE=$service_state > $registration_file
189
190 echo "--INFO: [$assertion]
191 Verify if registration template is located and size > 0 bytes"
192
193 if [ ! -s $registration_file ]; then
194 echo "--DIAG: [$assertion]
195 $registration_file is not located"
196 print_result $RESULT
197 exit $RESULT
198 fi
199
200 echo "--INFO: [$assertion]
201 Import the service to repository using svccfg import"
202
203 svccfg import $registration_file > $svccfg_errfile 2>&1
204 if [ $? -ne 0 ]; then
205 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
206 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
207 exit $STF_UNRESOLVED
208 fi
209
210 echo "--INFO: [$assertion]
211 Wait until the testfoo.$$ is loaded by $test_service"
212
213 #This function sets variable 'pid'
214
215 wait_process_start 2>/dev/null
216 if [ $? -ne 0 ]; then
217 echo "--DIAG: [$assertion]
218 testfoo.$$ not started by svccfg -v import $registration_file"
219 print_result $RESULT
220 exit $RESULT
221 fi
222
223 echo "--INFO: [$assertion]
224 svcs -p <FMRI> and make sure $pid is printed"
225 output=`svcs -p svc:/$test_service:$test_instance | grep -w $pid | \
226 awk '{print $2}' 2>/dev/null`
227 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
228 RESULT=$(update_result $STF_FAIL $RESULT)
229 echo "--DIAG: [$assertion]
230 svcs -p svc:/$test_service:$test_instance | grep $pid fails
231 EXPECTED: output = $pid testfoo.$$
232 ACTUAL: output = $output"
233 print_result $RESULT
234 exit $RESULT
235 fi
236
237 echo "--INFO: [${assertion}]
238 disable <$test_service> using svcadm"
239
240 svcadm disable svc:/$test_service:$test_instance >/dev/null 2>&1
241 ret=$?
242 if [ $ret -ne 0 ]; then
243 RESULT=$(update_result $STF_FAIL $RESULT)
244 echo "--DIAG: [$assertion]
245 svcadm disable svc:/$test_service:$test_instance fails
246 EXPECTED: output = ret 0
247 ACTUAL: output ret = $ret"
248 print_result $RESULT
249 exit $RESULT
250 fi
251
252 echo "--INFO: [${assertion}]
253 Wait until service STATE gets updated"
254
255 service_wait_state $test_service:$test_instance disabled
256 if [ $? -ne 0 ]; then
257 echo "--DIAG: [$assertion]
258 <$service_test> is not disabled"
259 print_result $RESULT
260 exit $RESULT
261 fi
262
263 echo "--INFO: [${assertion}]
264 Make sure svcs -p $test_service doesn't print $pid"
265
266 svcs -p svc:/$test_service:$test_instance | grep -w $pid >/dev/null 2>&1
267 if [ $? -eq 0 ]; then
268 RESULT=$(update_result $STF_FAIL $RESULT)
269 echo "--DIAG: [$assertion]
270 svcs -p svc:/$test_service:$test_instance | grep $pid should
271 fail; It means svcs -p shouldn't print process info as the
272 process is dead"
273 print_result $RESULT
274 exit $RESULT
275 fi
276
277 echo "--INFO: [${assertion}]
278 Make sure process is really dead using ps"
279
280 ps -ef | grep -w $pid | grep -v grep >/dev/null 2>&1
281 if [ $? -eq 0 ]; then
282 RESULT=$(update_result $STF_FAIL $RESULT)
283 echo "--DIAG: [$assertion]
284 ps -ef | grep $pid should fail"
285 print_result $RESULT
286 exit $RESULT
287 fi
288
289 RESULT=$STF_PASS
290 print_result $RESULT
291 exit $RESULT
292
293