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_013
32 # DESCRIPTION:
33 # If svc.startd invokes a service's refresh method and that method
34 # returns a non-zero exit value other than the defined straight to
35 # maintenance return code then the service is considered to have
36 # failed, but not irrevocably. The svc.startd will re-attempt to
37 # refresh the service until the error threshold is reached at
38 # which point the service is transitioned to the maintenance state.
39 #
40 # end __stf_assertion__
41 #
42
43 . ${STF_TOOLS}/include/stf.kshlib
44 . ${STF_SUITE}/include/gltest.kshlib
45 . ${STF_SUITE}/include/svc.startd_config.kshlib
46 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
47
48 typeset service_setup=0
49 function cleanup {
50 rm -f $svccfg_errfile $svcadm_errfile
51
52 if [[ $service_setup -ne 0 ]]; then
53 manifest_purgemd5 $registration_file
54 $service_app -s $test_service -i $test_instance \
55 -f $service_state -m stop
56 service_cleanup $test_service
57 service_dumpstate -f $service_state
58 rm -f $service_state $returncodefile
59 service_setup=0
60 fi
61
62 rm -f $registration_file
63 rm -f $service_log
64 }
65
66 trap cleanup 0 1 2 15
67
68 readonly ME=$(whence -p ${0})
69 readonly MYLOC=$(dirname ${ME})
70
71 DATA=$MYLOC
72
73 registration_template=$DATA/service_013.xml
74
75 extract_assertion_info $ME
76
77 # make sure that the svc.startd is running
78 verify_daemon
79 if [ $? -ne 0 ]; then
80 print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
81 print -- " continue"
82 exit $STF_UNRESOLVED
83 fi
84
85 # make sure that the features are available
86 features=`feature_test REFRESH`
87 if [ $? -ne 0 ]; then
88 print -- "--DIAG: $assertion: $features missing from startd"
89 exit $STF_UNTESTED
90 fi
91
92 # Make sure the environment is clean - the test service isn't running
93 print -- "--INFO: Cleanup any old $test_FMRI state"
94 service_cleanup $test_service
95 rm -f $service_state
96 if [ $? -ne 0 ]; then
97 print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
98 exit $STF_UNRESOLVED
99 fi
100
101 print -- "--INFO: generating manifest for importation into repository"
102 manifest_generate $registration_template \
103 TEST_SERVICE=$test_service \
104 TEST_INSTANCE=$test_instance \
105 SERVICE_APP=$service_app \
106 LOGFILE=$service_log \
107 STATEFILE=$service_state \
108 REFRESH_EVENT="returncode $SVC_METHOD_OTHEREXIT" \
109 > $registration_file
110
111 print -- "--INFO: Importing service into repository"
112 manifest_purgemd5 $registration_file
113 svccfg -v import $registration_file >$svccfg_errfile 2>&1
114 if [ $? -ne 0 ]; then
115 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
116 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
117 exit $STF_UNRESOLVED
118 fi
119 service_setup=1
120
121 print -- "--INFO: enabling $test_FMRI"
122 svcadm enable $test_FMRI
123 if [ $? -ne 0 ]; then
124 print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
125 exit $STF_FAIL
126 fi
127
128 print -- "--INFO: waiting for execution of start method"
129 service_wait_method $test_FMRI start
130 if [ $? -ne 0 ]; then
131 print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
132 exit $STF_UNRESOLVED
133 fi
134
135 print -- "--INFO: Validating service reaches online mode"
136 service_wait_state $test_FMRI online
137 if [ $? -ne 0 ]; then
138 print -- "--DIAG: $assertion: Service $test_FMRI didn't"
139 print -- " transition to online mode"
140 exit $STF_FAIL
141 fi
142
143 print -- "--INFO: Issuing refresh request"
144 svcadm refresh $test_FMRI >$svcadm_errfile 2>&1
145 if [ $? -ne 0 -o -s $svcadm_errfile ]; then
146 print -- "--DIAG: $assertion: refresh of Service $test_FMRI did not "
147 print -- " succeed. Error output: \"$(cat $svcadm_errfile)\""
148 exit $STF_UNRESOLVED
149 fi
150
151 print -- "--INFO: Waiting for call of $test_FMRI refresh method"
152 service_wait_method $test_FMRI refresh
153 if [ $? -ne 0 ]; then
154 print -- "--DIAG: $assertion: didn't issue refresh method"
155 exit $STF_FAIL
156 fi
157
158 print -- "--INFO: Validating service reached maintenance state"
159 service_wait_state $test_FMRI maintenance
160 if [ $? -ne 0 ]; then
161 print -- "--DIAG: $assertion: Service $test_FMRI did not"
162 print -- " transition to the maintenance state"
163 exit $STF_FAIL
164 fi
165
166 print -- "--INFO: Cleaning up service"
167 cleanup
168
169 exit $STF_PASS