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_012
32 # DESCRIPTION:
33 # If svc.startd invokes a service's refresh method and that method
34 # returns the defined straight to maintenance exit code then the
35 # service is considered to have failed due to an unrecoverable
36 # error and service is immediately transitioned to the maintenance state.
37 #
38 # end __stf_assertion__
39 #
40
41 . ${STF_TOOLS}/include/stf.kshlib
42 . ${STF_SUITE}/include/gltest.kshlib
43 . ${STF_SUITE}/include/svc.startd_config.kshlib
44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
45
46 typeset service_setup=0
47 function cleanup {
48 rm -f $svccfg_errfile $svcadm_errfile
49
50 if [[ $service_setup -ne 0 ]]; then
51 manifest_purgemd5 $registration_file
52 $service_app -s $test_service -i $test_instance \
53 -f $service_state -m stop
54 service_cleanup $test_service
55 service_dumpstate -f $service_state
56 rm -f $service_state $returncodefile
57 service_setup=0
58 fi
59
60 pkill -9 -z $(zonename) service_app
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_012.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 RETURNCODEFILE=$returncodefile \
109 > $registration_file
110
111 print -- "--INFO: Generating $returncodefile"
112 echo "returncode $SVC_METHOD_MAINTEXIT" > $returncodefile
113 if [ $? -ne 0 ]; then
114 print -- "--DIAG: Could not create $returncodefile"
115 exit $STF_UNRESOLVED
116 fi
117
118 print -- "--INFO: Importing service into repository"
119 manifest_purgemd5 $registration_file
120 svccfg -v import $registration_file >$svccfg_errfile 2>&1
121 if [ $? -ne 0 ]; then
122 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
123 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
124 exit $STF_UNRESOLVED
125 fi
126 service_setup=1
127
128 print -- "--INFO: enabling $test_FMRI"
129 svcadm enable $test_FMRI
130 if [ $? -ne 0 ]; then
131 print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
132 exit $STF_FAIL
133 fi
134
135 print -- "--INFO: waiting for execution of start method"
136 service_wait_method $test_FMRI start
137 if [ $? -ne 0 ]; then
138 print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
139 exit $STF_UNRESOLVED
140 fi
141
142 print -- "--INFO: Validating service reaches online mode"
143 service_wait_state $test_FMRI online
144 if [ $? -ne 0 ]; then
145 print -- "--DIAG: $assertion: Service $test_FMRI didn't"
146 print -- " transition to online mode"
147 exit $STF_FAIL
148 fi
149
150 print -- "--INFO: Issuing refresh request"
151 svcadm refresh $test_FMRI >$svcadm_errfile 2>&1
152 if [ $? -ne 0 -o -s $svcadm_errfile ]; then
153 print -- "--DIAG: $assertion: refresh of service $test_FMRI did not "
154 print -- " succeed. Error output: \"$(cat $svcadm_errfile)\""
155 exit $STF_UNRESOLVED
156 fi
157
158 print -- "--INFO: Waiting for call of $test_FMRI refresh method"
159 service_wait_method $test_FMRI refresh
160 if [ $? -ne 0 ]; then
161 print -- "--DIAG: $assertion: didn't issue refresh method"
162 exit $STF_FAIL
163 fi
164
165 print -- "--INFO: Validating service reached maintenance state"
166 service_wait_state $test_FMRI maintenance
167 if [ $? -ne 0 ]; then
168 print -- "--DIAG: $assertion: Service $test_FMRI did not"
169 print -- " transition to the maintenance state"
170 exit $STF_FAIL
171 fi
172
173 print -- "--INFO: Cleaning up service"
174 cleanup
175
176 exit $STF_PASS