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 # start __stf_assertion__
30 #
31 # ASSERTION: svcadm_refresh_001
32 #
33 # DESCRIPTION:
34 # Calling 'svcadm refresh FMRI' over FMRI currently in enabled state
35 # should not stop (or) start the service(s)/process(es) associated
36 # with those services.
37 # STRATEGY:
38 # - locate for template.xml in $STF_SUITE/tests/svcadm/
39 # - Create a simple start method
40 # - Generate say 'svcadm_refresh_001.$$.xml' using template.xml
41 # - Import the xml using svccfg import <.xml>
42 # - Wait until test_service loads start_process.
43 # - Call svcadm refresh <FMRI>.
44 # - Make sure above step exits 0.
45 #
46 # COMMANDS: svcadm(1)
47 #
48 # end __stf_assertion__
49 ################################################################################
50
51 # First load up definitions of STF result variables like STF_PASS etc.
52 . ${STF_TOOLS}/include/stf.kshlib
53
54 # Load up definitions of shell functionality common to all smf sub-suites.
55 . ${STF_SUITE}/include/gltest.kshlib
56 . ${STF_SUITE}/include/svc.startd_config.kshlib
57
58 # Load up the common utility functions for tests in this directory
59 . ${STF_SUITE}/${STF_EXEC}/functions.kshlib
60
61 # Define the cleanup function for this test
62 function cleanup {
63 pkill -z $(zonename) -f $start_process
64 pkill -z $(zonename) -f $refresh_test_process
65 cleanup_leftovers $refesh_test_service $registration_file \
66 $start_process $start_file /var/tmp/$rfrsh.$$
67 print_result $RESULT
68 }
69
70 # Define Variables
71 readonly assertion=svcadm_refresh_001
72 readonly ME=$(whence -p ${0})
73 readonly MYLOC=$(dirname ${ME})
74 readonly registration_template=${STF_SUITE}/tests/svcadm/refresh/template.xml
75 readonly registration_file=/var/tmp/svcadm_refresh_001.$$.xml
76 readonly refresh_test_service="refresh_001$$"
77 readonly refresh_test_instance="refresh_001$$"
78 readonly start_process=/var/tmp/refresh_001.$$.start
79 readonly start_file=/var/tmp/svcadm_refresh_001.startfile.$$
80 readonly refresh_test_process_name="rfrsh_001"
81 readonly refresh_test_process=/var/tmp/${refresh_test_process_name}.$$
82 readonly refresh_test_fmri="svc:/$refresh_test_service:$refresh_test_instance"
83 typeset -i pid=0
84
85 # Make sure we run as root
86 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
87 then
88 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
89 echo "--DIAG: [$assertion]
90 This test must be run from root."
91 exit $RESULT
92 fi
93
94 # Extract and print the assertion from this source script.
95 extract_assertion_info $ME
96
97 # Initialize test result to pass.
98 typeset -i RESULT=${STF_UNRESOLVED}
99
100 # Set a trap to execute the cleanup function
101 trap cleanup 0 1 2 15
102
103 # Exit code for individual commands.
104 typeset -i tmp_rc=0
105
106 # Execute environmental sanity checks.
107 check_gl_env
108 tmp_rc=$?
109 if [[ $tmp_rc -ne 0 ]]
110 then
111 echo "--DIAG: [$assertion]
112 Invalid smf environment, quitting."
113 exit $RESULT
114 fi
115
116 set -x
117 # Kill any running instances of start_process and refresh_test_process_name
118 pkill -z $(zonename) -f $start_process
119 pkill -z $(zonename) -f $refresh_test_process_name
120
121 echo "--INFO: [$assertion]
122 Verify that registration template $registration_template exists"
123
124 if [ ! -s $registration_template ]; then
125 echo "--DIAG: [$assertion]
126 $registration_template not found"
127 exit $RESULT
128 fi
129
130 echo "--INFO: [$assertion]
131 Create test start method: $start_process"
132
133 cat > $start_process <<-EOF
134 #!/bin/ksh -p
135 /bin/cp /dev/null $start_file >/dev/null 2>&1
136 cat > $refresh_test_process <<-EOT
137 #!/bin/ksh -p
138 while :; do echo "1" > /dev/null; done
139 exit 0
140 EOT
141 chmod +x $refresh_test_process
142 $refresh_test_process &
143 exit 0
144 EOF
145
146 echo "--INFO: [$assertion]
147 chmod 755 $start_process"
148
149 chmod 755 $start_process
150 if [ $? -ne 0 ]; then
151 echo "--DIAG: [$assertion]
152 chmod 755 $start_process failed"
153 exit $RESULT
154 fi
155
156 echo "--INFO: [$assertion]
157 Generate .xml required for this test"
158
159 manifest_generate $registration_template \
160 TEST_SERVICE=$refresh_test_service \
161 TEST_INSTANCE=$refresh_test_instance \
162 START_NAME=$start_process \
163 STOP_NAME=":kill" \
164 SERVICE_APP=$service_app \
165 STATEFILE=$service_state > $registration_file
166
167 echo "--INFO: [$assertion]
168 Verify the registration template was created and size > 0 bytes"
169
170 if [ ! -s $registration_file ]; then
171 echo "--DIAG: [$assertion]
172 $registration_file does not exist or has size = 0 bytes"
173 exit $RESULT
174 fi
175
176 echo "--INFO: [$assertion]
177 Import the service to repository using svccfg import"
178
179 svccfg import $registration_file > $svccfg_errfile 2>&1
180 if [ $? -ne 0 ]; then
181 echo "--DIAG: [$assertion]
182 Unable to import the service $refresh_test_service
183 error messages from svccfg: \"$(cat $svccfg_errfile)\""
184 exit $RESULT
185 fi
186
187 echo "--INFO: [$assertion]
188 Imported FMRI is: $refresh_test_fmri"
189
190 # Import should automatically enable the service
191 echo "--INFO: [$assertion]
192 Wait until $start_process is triggered"
193
194 wait_process_start 2>/dev/null
195 if [ $? -ne 0 ]; then
196 echo "--DIAG: [$assertion]
197 $start_process was not triggered upon import"
198 exit $RESULT
199 fi
200
201 pid=`pgrep -f ${refresh_test_process_name}`
202 if [[ $? -ne 0 || -z $pid ]]; then
203 echo "--DIAG: [$assertion]
204 Could not determine pid of $start_process"
205 exit $RESULT
206 fi
207
208 echo "--INFO: [$assertion]
209 svcs -p <FMRI> and make sure pid $pid is printed"
210 output="`svcs -p $refresh_test_fmri | grep -w $pid | \
211 awk '{ print $2 }' 2>/dev/null`"
212 if [[ $? -ne 0 ]] || [[ "$output" != "$pid" ]]; then
213 echo "--DIAG: [$assertion]
214 svcs -p $refresh_test_fmri | grep $pid | awk '{ print \$2 }' failed
215 EXPECTED: output = $pid
216 OBSERVED: output = $output"
217 exit $RESULT
218 fi
219
220 #
221 # VERIFY ASSERTION
222 #
223 echo "--INFO: [${assertion}]
224 refresh <$refresh_test_fmri> using svcadm"
225
226 svcadm refresh $refresh_test_fmri >/dev/null 2>&1
227 ret=$?
228 if [ $ret -ne 0 ]; then
229 RESULT=$(update_result $STF_FAIL $RESULT)
230 echo "--DIAG: [$assertion]
231 svcadm refresh $refresh_test_fmri fails
232 EXPECTED: ret = 0
233 OBSERVED: ret = $ret"
234 exit $RESULT
235 fi
236
237 echo "--INFO: [${assertion}]
238 Make sure process is still running with pid $pid"
239
240 svcs -p $refresh_test_fmri | grep -w $pid >/dev/null 2>&1
241 if [ $? -ne 0 ]; then
242 RESULT=$(update_result $STF_FAIL $RESULT)
243 echo "--DIAG: [$assertion]
244 EXPECTED: process with pid $pid exists on system
245 OBSERVED: no process with pid $pid is running"
246 exit $RESULT
247 fi
248
249 # Disable the test instance
250 echo "--INFO: [$assertion]
251 Disable $test_fmri"
252 svcadm disable $refresh_test_fmri >/dev/null 2>&1
253 ret=$?
254 if [ $ret -ne 0 ]; then
255 echo "--DIAG: [$assertion]
256 svcadm disable $refresh_test_fmri failed
257 EXPECTED: ret = 0
258 OBSERVED: ret = $ret"
259 fi
260
261 # Cleanup will be called upon exit
262
263 RESULT=$STF_PASS
264 print_result $RESULT
265 exit $RESULT
266
267 #
268 ### END
269 #