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_restart_008
32 #
33 # DESCRIPTION:
34 # Calling 'svcadm -v restart <FMRI1> <FMRI2>' where FMRI1 and FMRI2 is a
35 # service instance that is in the online state will result in the
36 # service being stopped and restarted. The exit status will be 0 (zero)
37 # and a verbose message will be printed indicating the transition.
38 #
39 # STRATEGY:
40 # - Generate a manifest which starts and stops a process.
41 # - Enable it using svccfg import <manifest>
42 # - Make sure process is started, verify it whether it touched
43 # a expected file say 'foo.start'.
44 # - remove the file 'foo.start' now.
45 # - Call svcadm restart FMRI1 and FMRI2 and make sure it exits 0.
46 # - Also verify the verbose message printed during transition.
47 # - Now the above step, should touch a file say 'foo.stop when
48 # trigerrring a stop event and touch a file say 'foo.start'
49 # when trigerring a start event.
50 # - Verify foo.start and foo.stop exists.
51 # - That proves restarts, restarts a process.
52 #
53 # COMMANDS: svcadm(1M)
54 #
55 # end __stf_assertion__
56 ################################################################################
57
58 # First load up definitions of STF result variables like STF_PASS etc.
59 . ${STF_TOOLS}/include/stf.kshlib
60
61 # Load up definitions of shell functionality common to all smf sub-suites.
62 . ${STF_SUITE}/include/gltest.kshlib
63 . ${STF_SUITE}/include/svc.startd_config.kshlib
64
65 # Load up common functions for tests in this directory
66 . ${STF_SUITE}/${STF_EXEC}/functions.kshlib
67
68 # Define the test's cleanup function
69 function cleanup {
70 cleanup_leftovers $test_service1 $start_file1 $stop_file1 \
71 $start_process1 $stop_process1 $registration_file1
72 cleanup_leftovers $test_service2 $start_file2 $stop_file2 \
73 $start_process2 $stop_process2 $registration_file2
74 print_result $RESULT
75 }
76
77 # Define Variables
78 readonly assertion=svcadm_restart_008
79 readonly ME=$(whence -p ${0})
80 readonly MYLOC=$(dirname ${ME})
81 readonly registration_template=${STF_SUITE}/tests/svcadm/restart/template.xml
82 readonly registration_file1=/var/tmp/svcadm_restart_008.$$1.xml
83 readonly registration_file2=/var/tmp/svcadm_restart_008.$$2.xml
84 readonly test_service1="smftest_svcadm_1"
85 readonly test_service2="smftest_svcadm_2"
86 readonly test_instance="$assertion"
87 readonly start_process1="/var/tmp/$assertion.$$.start1"
88 readonly start_process2="/var/tmp/$assertion.$$.start2"
89 readonly stop_process1="/var/tmp/$assertion.$$.stop1"
90 readonly stop_process2="/var/tmp/$assertion.$$.stop2"
91 readonly start_file1="/var/tmp/$assertion.$$.startfile1"
92 readonly start_file2="/var/tmp/$assertion.$$.startfile2"
93 readonly stop_file1="/var/tmp/$assertion.$$.stopfile1"
94 readonly stop_file2="/var/tmp/$assertion.$$.stopfile2"
95 readonly fmri1="svc:/$test_service1:$test_instance"
96 readonly fmri2="svc:/$test_service2:$test_instance"
97 readonly expected_output="/var/tmp/$assertion.$$.expected"
98 readonly actual_output="/var/tmp/$assertion.$$.actual"
99
100 # Make sure we run as root
101 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
102 then
103 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
104 echo "--DIAG: [$assertion]
105 This test must be run from root."
106 exit $RESULT
107 fi
108
109 # Extract and print assertion from this source script.
110 extract_assertion_info $ME
111
112 # Initialize test result to pass.
113 typeset -i RESULT=${STF_UNRESOLVED}
114
115 # Set a trap to execute the cleanup function
116 trap cleanup 0 1 2 15
117
118 # Exit code for individual commands.
119 typeset -i tmp_rc=0
120
121 # Execute environmental sanity checks.
122 check_gl_env
123 tmp_rc=$?
124 if [[ $tmp_rc -ne 0 ]]
125 then
126 echo "--DIAG: [$assertion]
127 Invalid smf environment, quitting."
128 exit $RESULT
129 fi
130
131 echo "--INFO: [$assertion]
132 Verify that required manifest template exists"
133
134 if [ ! -s $registration_template ]; then
135 echo "--DIAG: [$assertion]
136 $registration_template not found"
137 exit $RESULT
138 fi
139
140 echo "--INFO: [$assertion]
141 Create test processes in /var/tmp"
142
143 echo "--INFO: [$assertion]
144 (for $test_service1):
145 $start_process1
146 $stop_process1"
147
148 cat > $start_process1 << EOF
149 #!/bin/ksh -p
150 /bin/rm -f $start_file1
151 sleep 1
152 /bin/date +\%Y\%m\%d\%H\%M\%S > $start_file1
153 exit 0
154 EOF
155
156 cat > $stop_process1 << EOF
157 #!/bin/ksh -p
158 /bin/rm -f $stop_file1
159 /bin/date +\%Y\%m\%d\%H\%M\%S > $stop_file1
160 exit 0
161 EOF
162
163 # Create process scripts for test_service2
164 echo "--INFO: [$assertion]
165 (for $test_service2):
166 $start_process2
167 $stop_process2"
168
169 cat > $start_process2 << EOF
170 #!/bin/ksh -p
171 /bin/rm -f $start_file2
172 sleep 1
173 /bin/date +\%Y\%m\%d\%H\%M\%S > $start_file2
174 exit 0
175 EOF
176
177 cat > $stop_process2 << EOF
178 #!/bin/ksh -p
179 /bin/rm -f $stop_file2
180 /bin/date +\%Y\%m\%d\%H\%M\%S > $stop_file2
181 exit 0
182 EOF
183 echo "--INFO: [$assertion]
184 chmod 755 $start_process1"
185
186 chmod 755 $start_process1
187 if [ $? -ne 0 ]; then
188 echo "--DIAG: [$assertion]
189 chmod 755 /var/tmp/$start_process1 failed"
190 exit $RESULT
191 fi
192
193 echo "--INFO: [$assertion]
194 chmod 755 $stop_process1"
195
196 chmod 755 $stop_process1
197 if [ $? -ne 0 ]; then
198 echo "--DIAG: [$assertion]
199 chmod 755 /var/tmp/$stop_process1 failed"
200 exit $RESULT
201 fi
202
203 echo "--INFO: [$assertion]
204 chmod 755 $start_process2"
205
206 chmod 755 $start_process2
207 if [ $? -ne 0 ]; then
208 echo "--DIAG: [$assertion]
209 chmod 755 /var/tmp/$start_process2 failed"
210 exit $RESULT
211 fi
212
213 echo "--INFO: [$assertion]
214 chmod 755 $stop_process2"
215
216 chmod 755 $stop_process2
217 if [ $? -ne 0 ]; then
218 echo "--DIAG: [$assertion]
219 chmod 755 /var/tmp/$stop_process2 failed"
220 exit $RESULT
221 fi
222
223 # Generate the manifest for test_service1
224 echo "--INFO: [$assertion]
225 Generate .xml required for $test_service1 using given template.xml"
226
227 manifest_generate $registration_template \
228 TEST_SERVICE=$test_service1 \
229 TEST_INSTANCE=$test_instance \
230 START_NAME=$start_process1 \
231 STOP_NAME=$stop_process1 \
232 SERVICE_APP=$service_app \
233 STATEFILE=$service_state > $registration_file1
234
235 # Generate the manifest for test_service2
236 echo "--INFO: [$assertion]
237 Generate .xml required for $test_service2 using given template.xml"
238
239 manifest_generate $registration_template \
240 TEST_SERVICE=$test_service2 \
241 TEST_INSTANCE=$test_instance \
242 START_NAME=$start_process2 \
243 STOP_NAME=$stop_process2 \
244 SERVICE_APP=$service_app \
245 STATEFILE=$service_state > $registration_file2
246
247 # Verify that non-zero sized manifests were creatd
248 echo "--INFO: [$assertion]
249 Verify that registration template exists and size > 0 bytes"
250
251 if [ ! -s $registration_file1 ]; then
252 echo "--DIAG: [$assertion]
253 $registration_file1 not found or size = 0 bytes"
254 exit $RESULT
255 fi
256
257 if [ ! -s $registration_file2 ]; then
258 echo "--DIAG: [$assertion]
259 $registration_file2 not found or size = 0 bytes"
260 exit $RESULT
261 fi
262
263 # Import the services into the repository
264 echo "--INFO: [$assertion]
265 Import $test_service1 into the repository using svccfg"
266
267 svccfg import $registration_file1 > /dev/null 2>&1
268 if [ $? -ne 0 ]; then
269 print "--DIAG: $assertion: Unable to import the service $test_service1"
270 exit $RESULT
271 fi
272
273 echo "--INFO: [$assertion]
274 Import $test_service2 into the repository using svccfg"
275
276 svccfg import $registration_file2 > /dev/null 2>&1
277 if [ $? -ne 0 ]; then
278 print "--DIAG: $assertion: Unable to import the service $test_service2"
279 exit $RESULT
280 fi
281
282 # Verify that the services were enabled on import
283 echo "--INFO: [$assertion]
284 Services should be enabled on import"
285
286 echo "--INFO: [$assertion]
287 Wait until $start_process1 is triggered"
288 wait_process $start_file1 2>/dev/null
289 if [ $? -ne 0 ]; then
290 echo "--DIAG: [$assertion]
291 $start_process1 was not started"
292 exit $RESULT
293 fi
294
295 echo "--INFO: [$assertion]
296 Wait until $start_process2 is triggered."
297
298 wait_process $start_file2 2>/dev/null
299 if [ $? -ne 0 ]; then
300 echo "--DIAG: [$assertion]
301 $start_process2 not started"
302 exit $RESULT
303 fi
304
305 # Remove the $start_files and call svcadm restart. Expect that the stop
306 # and start methods are triggered, IN THAT ORDER.
307
308 /usr/bin/rm -f $start_file1 >/dev/null 2>&1
309 if [ -f $start_file1 ]; then
310 echo "--DIAG: [$assertion]
311 EXPECTED: Removed $start_file1
312 OBSERVED: Could not remove $start_file1"
313 exit $RESULT
314 fi
315
316 /usr/bin/rm -f $start_file2 >/dev/null 2>&1
317 if [ -f $start_file2 ]; then
318 echo "--DIAG: [$assertion]
319 EXPECTED: Removed $start_file2
320 OBSERVED: Could not remove $start_file2"
321 exit $RESULT
322 fi
323
324 cat > $expected_output << EOF
325 Action restart set for $fmri1.
326 Action restart set for $fmri2.
327 EOF
328
329 echo "--INFO: [${assertion}]
330 restart <$fmri1> <$fmri2> using svcadm"
331
332 svcadm -v restart $fmri1 $fmri2 >$actual_output 2>/dev/null
333 ret=$?
334 if [ $ret -ne 0 ]; then
335 RESULT=$(update_result $STF_FAIL $RESULT)
336 echo "--DIAG: [$assertion]
337 svcadm -v restart $fmri1 $fmri2 fails
338 EXPECTED: ret = 0; output =
339 `cat $expected_output`
340 OBSERVED: ret = $ret; output =
341 `cat $actual_output`"
342 exit $RESULT
343 fi
344
345 diff -w $expected_output $actual_output >/dev/null 2>&1
346 if [ $? -ne 0 ]; then
347 RESULT=$(update_result $STF_FAIL $RESULT)
348 echo "--DIAG: [$assertion]
349 EXPECTED: `cat $expected_output`
350 OBSERVED: `cat $actual_output`"
351 exit $RESULT
352 fi
353
354 # Verify that the stop events were triggered
355
356 echo "--INFO: [$assertion]
357 Wait until $stop_process1 is triggered"
358
359 wait_process $stop_file1 2>/dev/null
360 if [ $? -ne 0 ]; then
361 RESULT=$(update_result $STF_FAIL $RESULT)
362 echo "--DIAG: [$assertion]
363 $stop_process1 was not triggered"
364 exit $RESULT
365 fi
366
367 echo "--INFO: [$assertion]
368 Wait until $stop_process2 is triggered"
369
370 wait_process $stop_file2 2>/dev/null
371 if [ $? -ne 0 ]; then
372 RESULT=$(update_result $STF_FAIL $RESULT)
373 echo "--DIAG: [$assertion]
374 $stop_process2 was not triggered"
375 exit $RESULT
376 fi
377
378 # Verify that the start events were triggered.
379 echo "--INFO: [$assertion]
380 Wait until $start_process1 is invoked"
381
382 wait_process $start_file1 2>/dev/null
383 if [ $? -ne 0 ]; then
384 RESULT=$(update_result $STF_FAIL $RESULT)
385 echo "--DIAG: [$assertion]
386 $start_process1 not invoked"
387 exit $RESULT
388 fi
389
390 echo "--INFO: [$assertion]
391 Wait until $start_process2 is invoked"
392
393 wait_process $start_file2 2>/dev/null
394 if [ $? -ne 0 ]; then
395 RESULT=$(update_result $STF_FAIL $RESULT)
396 echo "--DIAG: [$assertion]
397 $start_process2 not started"
398 exit $RESULT
399 fi
400
401 # Wait until both services are online
402 service_wait_state $fmri1 online
403 if [ $? -ne 0 ]; then
404 RESULT=$(update_result $STF_FAIL $RESULT)
405 echo "--DIAG: [$assertion]
406 <$fmri1> is not online"
407 print_result $RESULT
408 exit $RESULT
409 fi
410 service_wait_state $fmri2 online
411 if [ $? -ne 0 ]; then
412 RESULT=$(update_result $STF_FAIL $RESULT)
413 echo "--DIAG: [$assertion]
414 <$fmri2> is not online"
415 print_result $RESULT
416 exit $RESULT
417 fi
418
419 # Verify that the start method was not triggered BEFORE the stop method.
420 typeset -i stop_runtime=`cat $stop_file1`
421 typeset -i start_runtime=`cat $start_file1`
422 if [ $start_runtime -le $stop_runtime ]; then
423 RESULT=$(update_result $STF_FAIL $RESULT)
424 echo "--DIAG: [$assertion]
425 Restart error for \$fmri1 ($fmri1):
426 start method was not rerun or was run before stop method
427 stop method run time: `cat $stop_file1`
428 start method run time: `cat $start_file1`"
429 exit $RESULT
430 fi
431
432 stop_runtime=`cat $stop_file2`
433 start_runtime=`cat $start_file2`
434 if [ $start_runtime -le $stop_runtime ]; then
435 RESULT=$(update_result $STF_FAIL $RESULT)
436 echo "--DIAG: [$assertion]
437 Restart error on $fmri2:
438 start method was not rerun or was run before stop method
439 stop method run time: `cat $stop_file2`
440 start method run time: `cat $start_file2`"
441 exit $RESULT
442 fi
443
444 # Disable the test instance
445 svcadm disable $fmri1 $fmri2 >/dev/null 2>&1
446 ret=$?
447 if [ $ret -ne 0 ]; then
448 echo "--DIAG: [$assertion]
449 svcadm disable $fmri1 $fmri2 failed
450 EXPECTED: ret = 0
451 OBSERVED: ret = $ret"
452 exit $RESULT
453 fi
454
455 # exit, trap set to call cleanup
456 RESULT=$STF_PASS
457 print_result $RESULT
458 exit $RESULT
459
460 #
461 ### END
462 #