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
29 function wait_process_start {
30 count=0
31 while [ $count -lt 10 ]; do
32 echo "--INFO: [$assertion]
33 Verify if testfoo.$$ is loaded and started"
34
35 pid=`ps -ef | grep testfoo.$$ | \
36 grep -v grep | awk '{print $2}' 2>/dev/null`
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 #This function is to cleanup the leftovers by this test
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_enable_008
68 #
69 # DESCRIPTION:
70 # Calling 'svcadm enable FMRI' over a service which
71 # is currently online with running processes, should
72 # succeed, without disturbing the service's state and running
73 # process(es).
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_enable_008.$$.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 disable <fmri> is successful with exit 0.
85 # - Wait for the transition period from enable to disable.
86 # - Also verify that 'test_process' is no more running it is STOPPED.
87 # - Make sure now 'fmri' state is disabled.
88 # - Now attempt to enable the FMRI
89 # - Verify that state is transited to "online" and process is started.
90 #
91 # COMMANDS: svcadm(1)
92 #
93 # end __stf_assertion__
94 ################################################################################
95
96 # First load up definitions of STF result variables like STF_PASS etc.
97 . ${STF_TOOLS}/include/stf.kshlib
98
99 # Load up definitions of shell functionality common to all smf sub-suites.
100 . ${STF_SUITE}/include/gltest.kshlib
101 . ${STF_SUITE}/include/svc.startd_config.kshlib
102
103 # Define Variables
104 readonly assertion=svcadm_enable_008
105 readonly ME=$(whence -p ${0})
106 readonly MYLOC=$(dirname ${ME})
107 readonly registration_template=${STF_SUITE}/tests/svcadm/enable/template.xml
108 readonly registration_file=/var/tmp/svcadm_enable_008.$$.xml
109 readonly test_service="enable_008$$"
110 readonly test_instance="enable_008$$"
111 readonly test_process=enable_008.$$
112 readonly fmri="svc:/$test_service:$test_instance"
113 pid=""
114
115 # Make sure we run as root
116 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
117 then
118 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
119 echo "--DIAG: [$assertion]
120 This test must be run as root."
121 print_result $RESULT
122 exit $RESULT
123 fi
124
125 # gltest.kshlib functions to extract and print assertion information
126 # from this source script.
127 extract_assertion_info $ME
128
129 # Initialize test result to pass.
130 typeset -i RESULT=${STF_UNRESOLVED}
131
132 # Set a trap to execute the cleanup function
133 trap cleanup 0 1 2 15
134
135 # Exit code for individual commands.
136 typeset -i tmp_rc=0
137
138 # Execute environmental sanity checks.
139 check_gl_env
140 tmp_rc=$?
141 if [[ $tmp_rc -ne 0 ]]
142 then
143 echo "--DIAG: [$assertion]
144 Invalid smf environment, quitting."
145 print_result $RESULT
146 exit $RESULT
147 fi
148
149 echo "--INFO: [$assertion]
150 Verify if required template is located"
151
152 if [ ! -s $registration_template ]; then
153 echo "--DIAG: [$assertion]
154 $registration_template is not located"
155 print_result $RESULT
156 exit $RESULT
157 fi
158
159 echo "--INFO: [$assertion]
160 Create a test process in /var/tmp/$test_process"
161
162 cat > /var/tmp/$test_process << EOF
163 #!/bin/ksh -p
164 print "#!/bin/ksh -p" > /var/tmp/testfoo.$$
165 print "sleep 1000" >> /var/tmp/testfoo.$$
166 print "exit 0" >> /var/tmp/testfoo.$$
167 chmod 755 /var/tmp/testfoo.$$
168 /var/tmp/testfoo.$$ &
169 exit 0
170 EOF
171
172 echo "--INFO: [$assertion]
173 chmod 755 /var/tmp/$test_process"
174
175 chmod 755 /var/tmp/$test_process
176 if [ $? -ne 0 ]; then
177 echo "--DIAG: [$assertion]
178 chmod 755 /var/tmp/$test_process failed"
179 print_result $RESULT
180 exit $RESULT
181 fi
182
183 echo "--INFO: [$assertion]
184 Generate .xml required for this test using given template.xml"
185
186 manifest_generate $registration_template \
187 TEST_SERVICE=$test_service \
188 TEST_INSTANCE=$test_instance \
189 EXEC_NAME=/var/tmp/$test_process \
190 STOP_NAME=":kill" \
191 SERVICE_APP=$service_app \
192 STATEFILE=$service_state > $registration_file
193
194 echo "--INFO: [$assertion]
195 Verify if registration template is located and size > 0 bytes"
196
197 if [ ! -s $registration_file ]; then
198 echo "--DIAG: [$assertion]
199 $registration_file is not located"
200 print_result $RESULT
201 exit $RESULT
202 fi
203
204 echo "--INFO: [$assertion]
205 Import the service to repository using svccfg import"
206
207 svccfg import $registration_file > $svccfg_errfile 2>&1
208 if [ $? -ne 0 ]; then
209 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
210 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
211 print_result $RESULT
212 exit $RESULT
213 fi
214
215 echo "--INFO: [$assertion]
216 Wait until the testfoo.$$ is loaded by $fmri"
217
218 #This function sets variable 'pid'
219
220 wait_process_start 2>/dev/null
221 if [ $? -ne 0 ]; then
222 echo "--DIAG: [$assertion]
223 testfoo.$$ not started by svccfg -v import $registration_file"
224 print_result $RESULT
225 exit $RESULT
226 fi
227
228 echo "--INFO: [$assertion]
229 svcs -p <FMRI> and make sure $pid is printed"
230 output=`svcs -p svc:/$test_service:$test_instance | grep -w $pid | \
231 awk '{print $2}' 2>/dev/null`
232 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
233 echo "--DIAG: [$assertion]
234 svcs -p svc:/$test_service:$test_instance | grep $pid fails
235 EXPECTED: output = $pid
236 ACTUAL: output = $output"
237 print_result $RESULT
238 exit $RESULT
239 fi
240
241 echo "--INFO: [${assertion}]
242 enable <$fmri> using svcadm"
243
244 svcadm enable svc:/$test_service:$test_instance >/dev/null 2>&1
245 ret=$?
246 if [ $ret -ne 0 ]; then
247 RESULT=$(update_result $STF_FAIL $RESULT)
248 echo "--DIAG: [$assertion]
249 svcadm enable svc:/$test_service:$test_instance fails
250 EXPECTED: output = ret 0
251 ACTUAL: output ret = $ret"
252 print_result $RESULT
253 exit $RESULT
254 fi
255
256 echo "--INFO: [${assertion}]
257 Verify state remains unchanged from online"
258
259 state=`svcprop -p restarter/state svc:/$test_service:$test_instance 2>/dev/null`
260 if [[ $? -ne 0 || "$state" != "online" ]]; then
261 RESULT=$(update_result $STF_FAIL $RESULT)
262 echo "--DIAG: [$assertion]
263 svcs -Ho STATE $test_service
264 EXPECTED: ret =0; state=online
265 ACTUAL: ret = $ret; state= online"
266 print_result $RESULT
267 exit $RESULT
268 fi
269
270 echo "--INFO: [$assertion]
271 svcs -p <FMRI> and make sure $pid is printed"
272
273 output=`svcs -p svc:/$test_service:$test_instance | grep -w $pid | \
274 awk '{print $2}' 2>/dev/null`
275 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
276 RESULT=$(update_result $STF_FAIL $RESULT)
277 echo "--DIAG: [$assertion]
278 svcs -p svc:/$test_service:$test_instance | grep $pid fails
279 EXPECTED: output = $pid
280 ACTUAL: output = $output"
281 print_result $RESULT
282 exit $RESULT
283 fi
284
285 RESULT=$STF_PASS
286 print_result $RESULT
287 exit $RESULT