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_validate_001
32 #
33 # DESCRIPTION:
34 # Calling the "validate file" subcommand where the file
35 # contains a valid manifest will validate the file. No
36 # changes will be made to the repository, nothing seen on
37 # stderr and the command exit status is 0.
38 #
39 #
40 # end __stf_assertion__
41 ###############################################################################
42
43
44 # First STF library
45 . ${STF_TOOLS}/include/stf.kshlib
46
47 # Load GL library
48 . ${STF_SUITE}/include/gltest.kshlib
49
50 # Load svc.startd library for manifest_generate
51 . ${STF_SUITE}/include/svc.startd_config.kshlib
52
53
54 readonly ME=$(whence -p ${0})
55 readonly MYLOC=$(dirname ${ME})
56
57 # Initialize test result
58 typeset -i RESULT=$STF_PASS
59
60
61 function cleanup {
62
63 rm -f $OUTFILE $ERRFILE $LOGFILE $STATEFILE $registration_file
64
65 exit $RESULT
66 }
67
68 trap cleanup 0 1 2 15
69
70 # make sure that the environment is sane - svc.configd is up and running
71 check_gl_env
72 [[ $? -ne 0 ]] && {
73 echo "--DIAG:
74 Invalid test environment - svc.configd not available"
75
76 RESULT=$STF_UNRESOLVED
77 exit $RESULT
78 }
79
80 assertion=svccfg_validate_001
81
82 # extract and print assertion information from this source script.
83 extract_assertion_info $ME
84
85
86 # Before starting make sure that the test service doesn't already exist.
87 # If it does then consider it a fatal error.
88
89 service_exists $TEST_SERVICE
90 [[ $? -eq 0 ]] && {
91 echo "--DIAG: [${assertion}]
92 service $TEST_SERVICE should not exist in
93 repository but does"
94
95 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
96 exit $RESULT
97 }
98
99 # Make sure that no instances of the test service are running. This
100 # is to ensure that the subsequent pgrep used to verify the assertion
101 # does not falsely fail.
102 #
103 pgrep $(basename $SERVICE_APP) > /dev/null 2>&1
104 ret=$?
105 [[ $ret -eq 0 ]] && {
106 echo "--DIAG: [${assertion}]
107 an instance of $(basename SERVICE_APP) is running but should not be
108 to ensure correct validation of this test"
109
110 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
111 exit $RESULT
112 }
113
114 #
115 # Start assertion testing
116 #
117
118 # Test #1: validate a good xml file
119
120 typeset -i TEST_RESULT=$STF_PASS
121
122 echo "--INFO: Validate a good service bundle"
123
124 registration_template=$MYLOC/validate_001_good.xml
125 registration_file=/tmp/validate_001_good.xml
126
127 readonly LOGFILE=/tmp/log.$$
128 readonly STATEFILE=/tmp/state.$$
129
130 manifest_generate $registration_template \
131 TEST_SERVICE=$TEST_SERVICE \
132 TEST_INSTANCE=$TEST_INSTANCE \
133 SERVICE_APP=$SERVICE_APP \
134 LOGFILE=$LOGFILE \
135 STATEFILE=$STATEFILE >$registration_file
136
137
138 manifest_purgemd5 $registration_file
139
140 svccfg validate $registration_file > $OUTFILE 2>$ERRFILE
141 ret=$?
142
143 [[ $ret -ne 0 ]] && {
144 echo "--DIAG: [${assertion}]
145 svccfg validate expected to return 0, got $ret"
146
147 TEST_RESULT=$STF_FAIL
148 }
149
150 # Verify that nothing in stdout - this is a non-fatal error
151 [[ -s $OUTFILE ]] && {
152 echo "--DIAG: [${assertion}]
153 stdout not expected, but got $(cat $OUTFILE)"
154
155 TEST_RESULT=$STF_FAIL
156 }
157
158 # Verify that nothing in stderr - this is a non-fatal error
159 [[ -s $ERRFILE ]] && {
160 echo "--DIAG: [${assertion}]
161 stderr not expected, but got $(cat $ERRFILE)"
162
163 TEST_RESULT=$STF_FAIL
164 }
165
166 service_exists $TEST_SERVICE
167 [[ $? -eq 0 ]] && {
168 echo "--DIAG: [${assertion}]
169 service $TEST_SERVICE should not exist in repository but does not"
170
171 TEST_RESULT=$STF_FAIL
172 }
173
174
175 pgrep $(basename $SERVICE_APP) > /dev/null 2>&1
176 ret=$?
177 [[ $ret -eq 0 ]] && {
178 echo "--DIAG: [${assertion}]
179 app $(basename SERVICE_APP) is running but should not be"
180
181 TEST_RESULT=$STF_FAIL
182 }
183
184 print_result $TEST_RESULT
185 RESULT=$(update_result $TEST_RESULT $RESULT)
186
187 # Test #2: validate a bad xml file
188
189 typeset -i TEST_RESULT=$STF_PASS
190
191 echo "--INFO: Validate a bad service bundle"
192
193 registration_template=$MYLOC/validate_001_bad.xml
194 registration_file=/tmp/validate_001_bad.xml
195
196 manifest_generate $registration_template \
197 TEST_SERVICE=$TEST_SERVICE \
198 TEST_INSTANCE=$TEST_INSTANCE \
199 SERVICE_APP=$SERVICE_APP \
200 LOGFILE=$LOGFILE \
201 STATEFILE=$STATEFILE >$registration_file
202
203
204 manifest_purgemd5 $registration_file
205
206 svccfg validate $registration_file > $OUTFILE 2>$ERRFILE
207 ret=$?
208 [[ $ret -ne 1 ]] && {
209 echo "--DIAG: [${assertion}]
210 svccfg validate expected to return 1, got $ret"
211
212 TEST_RESULT=$STF_FAIL
213 }
214
215 # Verify that nothing in stdout - this is a non-fatal error
216 [[ -s $OUTFILE ]] && {
217 echo "--DIAG: [${assertion}]
218 stdout not expected, but got $(cat $OUTFILE)"
219
220 TEST_RESULT=$STF_FAIL
221 }
222
223 # Verify that nothing in stderr - this is a non-fatal error
224 if ! egrep -s "$UNPARSEABLE_ERRMSG" $ERRFILE
225 then
226 echo "--DIAG: [${assertion}]
227 Expected error message \"$UNPARSEABLE_ERRMSG\"
228 but got \"$(cat $ERRFILE)\""
229
230 RESULT=$STF_FAIL
231 fi
232
233 service_exists $TEST_SERVICE
234 [[ $? -eq 0 ]] && {
235 echo "--DIAG: [${assertion}]
236 service $TEST_SERVICE should not exist in repository but does not"
237
238 TEST_RESULT=$STF_FAIL
239 }
240
241
242 pgrep $(basename $SERVICE_APP) > /dev/null 2>&1
243 ret=$?
244 [[ $ret -eq 0 ]] && {
245 echo "--DIAG: [${assertion}]
246 app $(basename SERVICE_APP) is running but should not be"
247
248 TEST_RESULT=$STF_FAIL
249 }
250
251 print_result $TEST_RESULT
252 RESULT=$(update_result $TEST_RESULT $RESULT)
253
254
255
256 exit $RESULT