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: methods_022
32 # DESCRIPTION:
33 # If all processes associated with an degraded service exit then the
34 # svc.startd should attempt to restart the service. the service has
35 # more than one process.
36 #
37 # end __stf_assertion__
38 #
39
40 . ${STF_TOOLS}/include/stf.kshlib
41 . ${STF_SUITE}/include/gltest.kshlib
42 . ${STF_SUITE}/include/svc.startd_config.kshlib
43 . ${STF_SUITE}/tests/include/svc.startd_fileops.kshlib
44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
45
46 typeset service_setup=0
47 function cleanup {
48 rm -f $svcadm_errfile $monitor_errfile
49 common_cleanup
50 return $?
51 }
52
53 trap cleanup 0 1 2 15
54
55 readonly ME=$(whence -p ${0})
56 readonly MYLOC=$(dirname ${ME})
57
58 DATA=$MYLOC
59
60 registration_template=$DATA/service_022.xml
61
62 extract_assertion_info $ME
63
64 # make sure that the svc.startd is running
65 verify_daemon
66 if [ $? -ne 0 ]; then
67 print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
68 print -- " continue"
69 exit $STF_UNRESOLVED
70 fi
71
72 # Make sure the environment is clean - the test service isn't running
73 print -- "--INFO: Cleanup any old $test_FMRI state"
74 service_cleanup $test_service
75 rm -f $service_state
76 if [ $? -ne 0 ]; then
77 print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
78 exit $STF_UNRESOLVED
79 fi
80
81 print -- "--INFO: generating monitor returncode file"
82 echo "returncode $SVC_DEGRADED" >$monitor_errfile
83 if [ $? -ne 0 ]; then
84 print -- "--DIAG: $assertion: unable to write to $monitor_errfile"
85 exit $STF_UNRESOLVED
86 fi
87
88 print -- "--INFO: generating manifest for importation into repository"
89 manifest_generate $registration_template \
90 TEST_SERVICE=$test_service \
91 TEST_INSTANCE=$test_instance \
92 SERVICE_APP=$service_app \
93 LOGFILE=$service_log \
94 STATEFILE=$service_state \
95 MONITOR_FILE=$monitor_errfile \
96 > $registration_file
97
98 print -- "--INFO: Importing service into repository"
99 manifest_purgemd5 $registration_file
100 svccfg -v import $registration_file >$svccfg_errfile 2>&1
101 if [ $? -ne 0 ]; then
102 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
103 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
104 exit $STF_UNRESOLVED
105 fi
106 service_setup=1
107
108 print -- "--INFO: enabling $test_FMRI"
109 svcadm enable $test_FMRI
110 if [ $? -ne 0 ]; then
111 print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
112 exit $STF_FAIL
113 fi
114
115 print -- "--INFO: waiting for execution of start method"
116 service_wait_method $test_FMRI start
117 if [ $? -ne 0 ]; then
118 print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
119 exit $STF_UNRESOLVED
120 fi
121
122 print -- "--INFO: sending service to degraded state"
123 svcadm mark degraded $test_FMRI
124 if [ $? -ne 0 ]; then
125 print -- "--DIAG: Could not send service $test_FMRI to degraded"
126 exit $STF_FAIL
127 fi
128
129 print -- "--INFO: Validating service reaches degraded mode"
130 service_wait_state $test_FMRI degraded
131 if [ $? -ne 0 ]; then
132 print -- "--DIAG: $assertion: Service $test_FMRI didn't"
133 print -- " transition to online mode"
134 exit $STF_FAIL
135 fi
136
137 print -- "--INFO: get the services to generate core files into log dir"
138 PIDS=`service_getpids -s $test_service -i $test_instance -f $service_state`
139 print -- "--INFO: child pids are: $PIDS"
140 typeset pid1=
141 typeset pid2=
142
143 echo $PIDS | read pid1 pid2
144
145 if [ -z "$pid2" ]; then
146 print -- "--DIAG: there should have been 2 child processes"
147 exit $STF_FAIL
148 fi
149
150 print -- "--INFO: make the one of the service processes exit"
151 $service_app -s $test_service -i $test_instance \
152 -m trigger -r "triggerchildrv 1 0"
153
154 print -- "--INFO: Waiting for service's start method ... should not be called"
155 service_wait_method $test_FMRI start
156 if [ $? -eq 0 ]; then
157 print -- "--DIAG: $assertion: issued start method for $test_FMRI"
158 exit $STF_FAIL
159 fi
160
161 print -- "--INFO: Finishing off second process"
162 $service_app -s $test_service -i $test_instance \
163 -m trigger -r "triggerchildrv 0 0"
164
165 print -- "--INFO: Waiting for service's start method"
166 service_wait_method $test_FMRI start
167 if [ $? -ne 0 ]; then
168 print -- "--DIAG: $assertion: didn't issue start method"
169 exit $STF_FAIL
170 fi
171
172 print -- "--INFO: Waiting for service to reach degraded state"
173 service_wait_state $test_FMRI degraded
174 if [ $? -ne 0 ]; then
175 print -- "--DIAG: $assertion: service $test_FMRI didn't"
176 print -- " come to degraded"
177 exit $STF_FAIL
178 fi
179
180 print -- "--INFO: Cleaning up service"
181 cleanup
182
183 exit $STF_PASS