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_add_001
32 #
33 # DESCRIPTION:
34 # The 'add name' subcommand adds an entity with the given
35 # name as a child of the current selection. The entity will
36 # be empty. If no errors have occurred during processing,
37 # there is nothing seen on stderr and the command exit status
38 # is 0.
39 #
40 # STRATEGY:
41 # This assertion has two sub-tests associated:
42 # 1) add a service using the command-line
43 # 2) add an instance using an input file.
44 #
45 # end __stf_assertion__
46 ###############################################################################
47
48 ###############################################################################
49 # start __stf_assertion__
50 #
51 # ASSERTION: svccfg_add_002
52 #
53 # DESCRIPTION:
54 # Calling the 'add name' subcommand with "name" being an entity
55 # that already exists will return with a diagnostic message
56 # displayed on stderr. The exit status will be 1.
57 #
58 # STRATEGY:
59 # This assertion has two sub-tests associated:
60 # 1) add an already existing service using the command-line
61 # 2) add an already existing instance using an input file.
62 #
63 # end __stf_assertion__
64 ###############################################################################
65
66 # First STF library
67 . ${STF_TOOLS}/include/stf.kshlib
68
69 # Load GL library
70 . ${STF_SUITE}/include/gltest.kshlib
71
72 readonly ME=$(whence -p ${0})
73 readonly MYLOC=$(dirname ${ME})
74
75 # Initialize test result
76 typeset -i RESULT=$STF_PASS
77
78
79 function cleanup {
80
81 # Note that $TEST_SERVICE may or may not exist so don't check
82 # results. Just make sure the service is gone.
83 service_delete $TEST_SERVICE
84
85 service_exists ${TEST_SERVICE}
86 [[ $? -eq 0 ]] && {
87 echo "--DIAG: [${assertion}, cleanup]
88 service ${TEST_SERVICE} should not exist in
89 repository after being deleted, but does"
90
91 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
92 }
93
94 rm -f $OUTFILE $ERRFILE $CMDFILE
95
96 exit $RESULT
97 }
98
99 trap cleanup 0 1 2 15
100
101 # make sure that the environment is sane - svc.configd is up and running
102 check_gl_env
103 [[ $? -ne 0 ]] && {
104 echo "--DIAG:
105 Invalid test environment - svc.configd not available"
106
107 RESULT=$STF_UNRESOLVED
108 exit $RESULT
109 }
110
111 # extract and print assertion information from this source script.
112 extract_assertion_info $ME
113
114 #
115 # Start assertion testing
116 #
117
118 assertion=svccfg_add_001
119
120 #
121 # Test #1: Add a service
122 #
123
124 echo "--INFO: Starting $assertion, test 1 (add a service)"
125
126 typeset -i TEST_RESULT=$STF_PASS
127
128 # Before starting make sure that the test service doesn't already exist.
129 # If it does then consider it a fatal error.
130 service_exists $TEST_SERVICE
131 [[ $? -eq 0 ]] && {
132 echo "--DIAG: [${assertion}, test 1]
133 service $TEST_SERVICE should not exist in
134 repository but does"
135
136 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
137 exit $RESULT
138 }
139
140
141 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
142 ret=$?
143
144 # Verify that the return value is as expected - this is a non-fatal error
145 [[ $ret -ne 0 ]] && {
146 echo "--DIAG: [${assertion}, test 1]
147 svccfg add expected to return 0, got $ret"
148
149 TEST_RESULT=$STF_FAIL
150
151 }
152
153 # Verify that nothing in stdout - this is a non-fatal error
154 [[ -s $OUTFILE ]] && {
155 echo "--DIAG: [${assertion}, test 1]
156 stdout not expected, but got $(cat $OUTFILE)"
157
158 TEST_RESULT=$STF_FAIL
159 }
160
161 # Verify that nothing in stderr - this is a non-fatal error
162 [[ -s $ERRFILE ]] && {
163 echo "--DIAG: [${assertion}, test 1]
164 stderr not expected, but got $(cat $ERRFILE)"
165
166 TEST_RESULT=$STF_FAIL
167 }
168
169 service_exists $TEST_SERVICE
170 [[ $? -ne 0 ]] && {
171 echo "--DIAG: [${assertion}, test 1]
172 service $TEST_SERVICE should exist in repository but does not"
173
174
175 exit $STF_FAIL
176 }
177
178 rm -f $ERRFILE $OUTFILE
179
180
181 print_result $TEST_RESULT
182 RESULT=$(update_result $TEST_RESULT $RESULT)
183
184
185 #
186 # Test #2: Add a service/service_instance
187 #
188 echo "--INFO: Starting $assertion, test 2 (add a service instance)"
189 typeset -i TEST_RESULT=$STF_PASS
190
191 cat <<EOF >$CMDFILE
192 select ${TEST_SERVICE}
193 add ${TEST_INSTANCE}
194 EOF
195
196 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
197 ret=$?
198
199 # Verify that the return value is as expected - non-fatal error
200 [[ $ret -ne 0 ]] && {
201 echo "--DIAG: [${assertion}, test 2]
202 svccfg add expected to return 0, got $ret"
203
204 TEST_RESULT=$STF_FAIL
205 }
206
207 # Verify that nothing in stdout - non-fatal error
208 [[ -s $OUTFILE ]] && {
209 echo "--DIAG: [${assertion}, test 2]
210 stdout not expected, but got $(cat $OUTFILE)"
211
212 TEST_RESULT=$STF_FAIL
213 }
214
215 # Verify that nothing in stderr - non-fatal error
216 [[ -s $ERRFILE ]] && {
217 echo "--DIAG: [${assertion}, test 2]
218 stderr not expected, but got $(cat $ERRFILE)"
219
220 TEST_RESULT=$STF_FAIL
221 }
222
223 service_exists ${TEST_SERVICE}:${TEST_INSTANCE}
224 [[ $? -ne 0 ]] && {
225 echo "--DIAG: [${assertion}, test 2]
226 service ${TEST_SERVICE}:${TEST_INSTANCE} should exist in
227 repository after being added, but does not"
228
229
230 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
231 exit $RESULT
232 }
233
234
235
236 rm -f $OUTFILE $ERRFILE $CMDFILE
237
238 print_result $TEST_RESULT
239 RESULT=$(update_result $TEST_RESULT $RESULT)
240
241
242 #
243 # Start assertion testing
244 #
245
246 assertion=svccfg_add_002
247
248 echo "--INFO: Starting $assertion, test 1 (add an existing service)"
249 typeset -i TEST_RESULT=$STF_PASS
250
251 #
252 # Test #1: Attempt to add an already existing service
253 #
254
255 svccfg add ${TEST_SERVICE} > $OUTFILE 2>$ERRFILE
256 ret=$?
257
258 # Verify that the return value is as expected - non-fatal error
259 [[ $ret -ne 1 ]] && {
260 echo "--DIAG: [${assertion}, test 1]
261 svccfg expected to return 1, got $ret"
262
263 TEST_RESULT=$STF_FAIL
264 }
265
266 # Verify that nothing in stdout - non-fatal error
267 [[ -s $OUTFILE ]] && {
268 echo "--DIAG: [${assertion}, test 1]
269 stdout not expected, but got $(cat $OUTFILE)"
270
271 TEST_RESULT=$STF_FAIL
272 }
273
274 # Verify that a message is sent to stderr - non-fatal error
275 if ! egrep -s "$SERVICE_EXISTS_ERRMSG" $ERRFILE
276 then
277 echo "--DIAG: [${assertion}, test 1]
278 Expected error message \"$SERVICE_EXISTS_ERRMSG\"
279 but got \"$(cat $ERRFILE)\""
280
281 TEST_RESULT=$STF_FAIL
282 fi
283
284
285 print_result $TEST_RESULT
286 RESULT=$(update_result $TEST_RESULT $RESULT)
287
288 rm -f $ERRFILE $OUTFILE
289
290
291
292 #
293 # Test #2: Attempt to add the same service and service/instance that was
294 # already added
295 #
296
297 echo "--INFO: Starting $assertion, test 2 (add an existing instance)"
298 typeset -i TEST_RESULT=$STF_PASS
299
300 cat <<EOF >$CMDFILE
301 select ${TEST_SERVICE}
302 add ${TEST_INSTANCE}
303 EOF
304
305 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
306 ret=$?
307
308 # Verify that the return value is as expected - non-fatal error
309 [[ $ret -ne 1 ]] && {
310 echo "--DIAG: [${assertion}, test 2]
311 svccfg expected to return 1, got $ret"
312
313 TEST_RESULT=$STF_FAIL
314 }
315
316 # Verify that nothing in stdout - non-fatal error
317 [[ -s $OUTFILE ]] && {
318 echo "--DIAG: [${assertion}, test 2]
319 stdout not expected, but got $(cat $OUTFILE)"
320
321 TEST_RESULT=$STF_FAIL
322 }
323
324 # Verify that a message is sent to stderr - non-fatal error
325 if ! egrep -s "$INSTANCE_EXISTS_ERRMSG" $ERRFILE
326 then
327 echo "--DIAG: [${assertion}, test 2]
328 Expected error message \"$INSTANCE_EXISTS_ERRMSG\"
329 but got \"$(cat $ERRFILE)\""
330
331 TEST_RESULT=$STF_FAIL
332 fi
333
334 rm -f $ERRFILE $OUTFILE $CMDFILE
335
336
337 print_result $TEST_RESULT
338 RESULT=$(update_result $TEST_RESULT $RESULT)
339
340 exit $RESULT