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: svccfg_apply_001
32 #
33 # DESCRIPTION:
34 # Calling the "apply file" subcommand where the file contains a
35 # valid service profile will result in the service instances
36 # specified within the file being enabled, if the services are
37 # specified to be enabled. If no errors have occurred during
38 # processing, there is nothing seen on stderr and the
39 # command exist status is 0.
40 #
41 # STRATEGY:
42 # This test uses a service that is existing in the repository.
43 # - Create and import a test service, with enabled=true
44 # (at this point the service is up and running)
45 # - Create a test profile with the test service enabled (enabled=true)
46 # - Apply the profile
47 # (this should have no impact on the state of the services)
48 # - Update the profile such that enable is not true (enabled=false)
49 # - Apply the profile
50 # (this should disable the service)
51 #
52 # end __stf_assertion__
53 ###############################################################################
54
55
56 # First STF library
57 . ${STF_TOOLS}/include/stf.kshlib
58
59 # Load GL library
60 . ${STF_SUITE}/include/gltest.kshlib
61
62 # Load svc.startd library for manifest_generate
63 . ${STF_SUITE}/include/svc.startd_config.kshlib
64
65 readonly ME=$(whence -p ${0})
66 readonly MYLOC=$(dirname ${ME})
67
68 # Initialize test result
69 typeset -i RESULT=$STF_PASS
70
71
72 function cleanup {
73
74 # Note that $TEST_SERVICE may or may not exist so don't check
75 # results. Just make sure the service is gone.
76
77 manifest_purgemd5 $manifest_file
78
79 service_cleanup ${TEST_SERVICE}
80
81 service_exists ${TEST_SERVICE}
82 [[ $? -eq 0 ]] && {
83 echo "--DIAG: [${assertion}, cleanup]
84 service ${TEST_SERVICE} should not exist in
85 repository after being deleted, but does"
86
87 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
88 }
89
90 rm -f $OUTFILE $ERRFILE $LOGFILE $STATEFILE $manifest_file $profile_file
91
92 exit $RESULT
93 }
94
95 trap cleanup 0 1 2 15
96
97 # make sure that the environment is sane - svc.configd is up and running
98 check_gl_env
99 [[ $? -ne 0 ]] && {
100 echo "--DIAG:
101 Invalid test environment - svc.configd not available"
102
103 RESULT=$STF_UNRESOLVED
104 exit $RESULT
105 }
106
107 assertion=svccfg_apply_001
108
109 # extract and print assertion information from this source script.
110 extract_assertion_info $ME
111
112 # Before starting make sure that the test service doesn't already exist.
113 # If it does then consider it a fatal error.
114
115 service_exists $TEST_SERVICE
116 ret=$?
117 [[ $ret -eq 0 ]] && {
118 echo "--DIAG: [${assertion}]
119 service $TEST_SERVICE should not exist in
120 repository but does"
121
122 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
123 exit $RESULT
124 }
125
126 # Make sure that no instances of the test service are running. This
127 # is to ensure that the subsequent pgrep used to verify the assertion
128 # does not falsely fail.
129 #
130 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
131 ret=$?
132 [[ $ret -eq 0 ]] && {
133 echo "--DIAG: [${assertion}]
134 an instance of $(basename $SERVICE_APP) is running but should not be
135 to ensure correct validation of this test"
136
137 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
138 exit $RESULT
139 }
140
141
142 # # Start assertion testing
143 #
144
145 readonly manifest_template=$MYLOC/apply_001_manifest.xml
146 readonly manifest_file=/tmp/apply_001_manifest.xml
147
148 readonly LOGFILE=/tmp/log.$$
149 readonly STATEFILE=/tmp/state.$$
150
151 manifest_generate $manifest_template \
152 TEST_SERVICE=$TEST_SERVICE \
153 TEST_INSTANCE=$TEST_INSTANCE \
154 SERVICE_APP=$SERVICE_APP \
155 LOGFILE=$LOGFILE \
156 STATEFILE=$STATEFILE | sed 's/ENABLE_VALUE/true/' >$manifest_file
157
158 manifest_purgemd5 $manifest_file
159
160 svccfg import $manifest_file > $OUTFILE 2>$ERRFILE
161 ret=$?
162 [[ $ret -ne 0 ]] && {
163 echo "--DIAG: [${assertion}]
164 svccfg import failed unexpectedly
165 error output is $(cat $ERRFILE)"
166
167 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
168 exit $RESULT
169 }
170
171 service_wait_state $TEST_SERVICE:$TEST_INSTANCE online
172 ret=$?
173 [[ $ret -ne 0 ]] && {
174 echo "--DIAG: [${assertion}]
175 $TEST_SERVICE:$TEST_INSTANCE did not transition to online as expected"
176
177 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
178 exit $RESULT
179 }
180
181
182 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
183 ret=$?
184 [[ $ret -ne 0 ]] && {
185 echo "--DIAG: [${assertion}]
186 app $(basename $SERVICE_APP) is not running but should be"
187
188 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
189 exit $RESULT
190 }
191
192 readonly profile_template=$MYLOC/apply_001_profile.xml
193 readonly profile_file=/tmp/apply_001_profile.xml
194
195 manifest_generate $profile_template \
196 TEST_SERVICE=$TEST_SERVICE \
197 TEST_INSTANCE=$TEST_INSTANCE | sed 's/ENABLE_VALUE/true/' >$profile_file
198
199 svccfg apply $profile_file > $OUTFILE 2>$ERRFILE
200 ret=$?
201 [[ $ret -ne 0 ]] && {
202 echo "--DIAG: [${assertion}]
203 svccfg apply expected to return 0, got $ret"
204
205 RESULT=$STF_FAIL
206 }
207
208
209 # Verify that nothing in stdout - this is a non-fatal error
210 [[ -s $OUTFILE ]] && {
211 echo "--DIAG: [${assertion}]
212 stdout not expected, but got $(cat $OUTFILE)"
213
214 RESULT=$STF_FAIL
215 }
216
217 # Verify that nothing in stderr - this is a non-fatal error
218 [[ -s $ERRFILE ]] && {
219 echo "--DIAG: [${assertion}]
220 stderr not expected, but got $(cat $ERRFILE)"
221
222 RESULT=$STF_FAIL
223 }
224
225
226 service_wait_state $TEST_SERVICE:$TEST_INSTANCE online
227 ret=$?
228 [[ $ret -ne 0 ]] && {
229 echo "--DIAG: [${assertion}]
230 $TEST_SERVICE:$TEST_INSTANCE did not transition to online as expected"
231 RESULT=$STF_FAIL
232 }
233
234 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
235 ret=$?
236 [[ $ret -ne 0 ]] && {
237 echo "--DIAG: [${assertion}]
238 app $(basename $SERVICE_APP) is not running but should be"
239
240 RESULT=$STF_FAIL
241 }
242
243 # If the result is not pass at this point than just exit (don't continue)
244 [[ $RESULT -ne $STF_PASS ]] && exit $RESULT
245
246 manifest_generate $profile_template \
247 TEST_SERVICE=$TEST_SERVICE \
248 TEST_INSTANCE=$TEST_INSTANCE | sed 's/ENABLE_VALUE/false/' >$profile_file
249
250 svccfg apply $profile_file > $OUTFILE 2>$ERRFILE
251 ret=$?
252 [[ $ret -ne 0 ]] && {
253 echo "--DIAG: [${assertion}]
254 svccfg apply expected to return 0, got $ret"
255
256 RESULT=$STF_FAIL
257 }
258
259 # Verify that nothing in stdout - this is a non-fatal error
260 [[ -s $OUTFILE ]] && {
261 echo "--DIAG: [${assertion}]
262 stdout not expected, but got $(cat $OUTFILE)"
263
264 RESULT=$STF_FAIL
265 }
266
267 # Verify that nothing in stderr - this is a non-fatal error
268 [[ -s $ERRFILE ]] && {
269 echo "--DIAG: [${assertion}]
270 stderr not expected, but got $(cat $ERRFILE)"
271
272 RESULT=$STF_FAIL
273 }
274
275 service_wait_state $TEST_SERVICE:$TEST_INSTANCE disabled
276 ret=$?
277 [[ $ret -ne 0 ]] && {
278 echo "--DIAG: [${assertion}]
279 $TEST_SERVICE:$TEST_INSTANCE did not transition to disabled as expected"
280 RESULT=$STF_FAIL
281 }
282
283
284 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
285 ret=$?
286 [[ $ret -eq 0 ]] && {
287 echo "--DIAG: [${assertion}]
288 app $(basename $SERVICE_APP) is running but should not be"
289
290 RESULT=$STF_FAIL
291 }
292
293 exit $RESULT