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=`pgrep -z $(zonename) -f testfoo.$$`
37 if [[ $? -eq 0 && ! -z $pid ]]; then
38 return 0
39 else
40 sleep 1
41 fi
42 count=`expr $count + 1`
43 done
44
45 #If test process not started by service in given time
46 #then fail and return 1
47
48 if [ $count -eq 10 ]; then
49 return 1
50 fi
51 }
52
53 function cleanup {
54 kill -9 $pid
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_004
68 #
69 # DESCRIPTION:
70 # Calling 'svcadm -v disable FMRI' where FMRI is a service instance
71 # that is in the enabled state will result in the service being stopped
72 # and being transitioned into disabled state. A message will be sent to
73 # stdout and the exit status will be 0.
74 # STRATEGY:
75 # - locate for template.xml in $STF_SUITE/tests/svcadm/
76 # - Create a simple test_process that sleeps for may be 10 secs.
77 # - Generate say 'svcadm_disable_004.$$.xml' using template.xml
78 # which contains say service='test_service',
79 # instance='test_instance'
80 # execname='test_process' for both start and stop event.
81 # - Import the xml using svccfg import <.xml>
82 # - Wait until test_service loads test_process.
83 # - Now attempt to disable the service.
84 # - Make sure svcadm -v disable <service> is successful with exit 0.
85 # - Also verify that "$service disabled verbose message is printed"
86 # - Wait for the transition period from enable to disable.
87 # - Also verify that 'test_process' is no more running it is STOPPED.
88 # - Make sure now 'service' state is disabled.
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_disable_004
104 readonly ME=$(whence -p ${0})
105 readonly MYLOC=$(dirname ${ME})
106 readonly registration_template=${STF_SUITE}/tests/svcadm/disable/template.xml
107 readonly registration_file=/var/tmp/svcadm_disable_004.$$.xml
108 readonly test_service="disable_004$$"
109 readonly test_instance="disable_004$$"
110 readonly test_process=disable_004.$$
111 pid=""
112
113 # Make sure we run as root
114 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
115 then
116 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
117 echo "--DIAG: [$assertion]
118 This test must be run from root."
119 print_result $RESULT
120 exit $RESULT
121 fi
122
123 # gltest.kshlib functions to extract and print assertion information
124 # from this source script.
125 extract_assertion_info $ME
126
127 # Initialize test result to pass.
128 typeset -i RESULT=${STF_UNRESOLVED}
129
130 # Set a trap to execute the cleanup function
131 trap cleanup 0 1 2 15
132
133 # Exit code for individual commands.
134 typeset -i tmp_rc=0
135
136 # Execute environmental sanity checks.
137 check_gl_env
138 tmp_rc=$?
139 if [[ $tmp_rc -ne 0 ]]
140 then
141 echo "--DIAG: [$assertion]
142 Invalid smf environment, quitting."
143 print_result $RESULT
144 exit $RESULT
145 fi
146
147 echo "--INFO: [$assertion]
148 Verify if required template is located"
149
150 if [ ! -s $registration_template ]; then
151 echo "--DIAG: [$assertion]
152 $registration_template is not located"
153 print_result $RESULT
154 exit $RESULT
155 fi
156
157 echo "--INFO: [$assertion]
158 Create a test process in /var/tmp/$test_process"
159
160 cat > /var/tmp/$test_process << EOF
161 #!/bin/ksh -p
162 print "#!/bin/ksh -p" > /var/tmp/testfoo.$$
163 print "sleep 1000" >> /var/tmp/testfoo.$$
164 print "exit 0" >> /var/tmp/testfoo.$$
165 chmod 755 /var/tmp/testfoo.$$
166 /var/tmp/testfoo.$$ &
167 exit 0
168 EOF
169
170 echo "--INFO: [$assertion]
171 chmod 755 /var/tmp/$test_process"
172
173 chmod 755 /var/tmp/$test_process
174 if [ $? -ne 0 ]; then
175 echo "--DIAG: [$assertion]
176 chmod 755 /var/tmp/$test_process failed"
177 print_result $RESULT
178 exit $RESULT
179 fi
180
181 echo "--INFO: [$assertion]
182 Generate .xml required for this test using given template.xml"
183
184 manifest_generate $registration_template \
185 TEST_SERVICE=$test_service \
186 TEST_INSTANCE=$test_instance \
187 EXEC_NAME=/var/tmp/$test_process \
188 STOP_NAME=":kill" \
189 SERVICE_APP=$service_app \
190 STATEFILE=$service_state > $registration_file
191
192 echo "--INFO: [$assertion]
193 Verify if registration template is located and size > 0 bytes"
194
195 if [ ! -s $registration_file ]; then
196 echo "--DIAG: [$assertion]
197 $registration_file is not located"
198 print_result $RESULT
199 exit $RESULT
200 fi
201
202 echo "--INFO: [$assertion]
203 Import the service to repository using svccfg import"
204
205 svccfg import $registration_file > $svccfg_errfile 2>&1
206 if [ $? -ne 0 ]; then
207 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
208 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
209 exit $STF_UNRESOLVED
210 fi
211
212 echo "--INFO: [$assertion]
213 Wait until the testfoo.$$ is loaded by $test_service"
214
215 #This function sets variable 'pid'
216
217 wait_process_start 2>/dev/null
218 if [ $? -ne 0 ]; then
219 echo "--DIAG: [$assertion]
220 testfoo.$$ not started by svccfg -v import $registration_file"
221 print_result $RESULT
222 exit $RESULT
223 fi
224
225 echo "--INFO: [$assertion]
226 svcs -Hp <FMRI> and make sure $pid is printed"
227 output=`svcs -p svc:/$test_service:$test_instance | grep -w $pid | \
228 awk '{print $2}' 2>/dev/null`
229 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
230 RESULT=$(update_result $STF_FAIL $RESULT)
231 echo "--DIAG: [$assertion]
232 svcs -Hp $test_service:$test_instance | grep testfoo.$$ fails
233 EXPECTED: output = $pid
234 ACTUAL: output = $output"
235 print_result $RESULT
236 exit $RESULT
237 fi
238
239 echo "--INFO: [${assertion}]
240 disable <$test_service> using svcadm"
241
242 output=`svcadm -v disable svc:/$test_service:$test_instance 2>/dev/null`
243 ret=$?
244 if [[ $ret -ne 0 || \
245 $output != "svc:/$test_service:$test_instance disabled." ]]; then
246 RESULT=$(update_result $STF_FAIL $RESULT)
247 echo "--DIAG: [$assertion]
248 svcadm disable svc:/$test_service:$test_instance fails
249 EXPECTED: output = ret 0; and
250 message = svc:/$test_service:$test_instance disabled.
251 ACTUAL: output ret = $ret message = $output"
252 print_result $RESULT
253 exit $RESULT
254 fi
255
256 echo "--INFO: [${assertion}]
257 Just wait for sometime to STATE gets updated"
258
259 service_wait_state $test_service:$test_instance disabled
260 if [ $? -ne 0 ]; then
261 echo "--DIAG: [$assertion]
262 <$service_test> is not disabled"
263 print_result $RESULT
264 exit $RESULT
265 fi
266
267 echo "--INFO: [${assertion}]
268 Make sure svcs -Hp $test_service doesn't print $pid"
269
270 svcs -Hp svc:/$test_service:$test_instance | grep -w $pid >/dev/null 2>&1
271 if [ $? -eq 0 ]; then
272 RESULT=$(update_result $STF_FAIL $RESULT)
273 echo "--DIAG: [$assertion]
274 svcs -Hp svc:/$test_service:$test_instance | grep $pid should
275 fail; It means svcs -Hp shouldn't print process info as the
276 process is dead"
277 print_result $RESULT
278 exit $RESULT
279 fi
280
281 echo "--INFO: [${assertion}]
282 Make sure process is really dead using ps"
283
284 ps -ef -z $(zonename) | grep -w $pid | grep -v grep >/dev/null 2>&1
285 if [ $? -eq 0 ]; then
286 RESULT=$(update_result $STF_FAIL $RESULT)
287 echo "--DIAG: [$assertion]
288 ps -ef -z $(zonename) | grep $pid should fail"
289 print_result $RESULT
290 exit $RESULT
291 fi
292
293 RESULT=$STF_PASS
294 print_result $RESULT
295 exit $RESULT
296
297