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_select_001
32 #
33 # DESCRIPTION:
34 # The subcommand "select name" selects the scope or service
35 # specified by the name parameter. On success no error is
36 # seen and the exit status is 0.
37 #
38 # STRATEGY:
39 # This assertion is verified in many other svccfg test cases.
40 # For this test case we'll verify scope by selecting with
41 # absolute names vs. relative names.
42 #
43 # end __stf_assertion__
44 ###############################################################################
45
46
47 # First STF library
48 . ${STF_TOOLS}/include/stf.kshlib
49
50 # Load GL library
51 . ${STF_SUITE}/include/gltest.kshlib
52
53 # Assertion ID
54 readonly assertion=svccfg_select_001
55
56 readonly ME=$(whence -p ${0})
57 readonly MYLOC=$(dirname ${ME})
58
59 # Initialize test result
60 typeset -i RESULT=$STF_PASS
61
62 typeset -r num_entities=10
63
64 function cleanup {
65
66 # Note that $TEST_SERVICE may or may not exist so don't check
67 # results. Just make sure the service is gone.
68 typeset i=1
69 while [[ $i -le $num_entities ]]
70 do
71 service_delete ${TEST_SERVICE}_$i > /dev/null 2>&1
72
73 service_exists ${TEST_SERVICE}_$i
74 [[ $? -eq 0 ]] && {
75 echo "--DIAG: [${assertion}, cleanup]
76 service ${TEST_SERVICE} should not exist in
77 repository after being deleted, but does"
78
79 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
80 }
81 (( i = i + 1 ))
82 done
83
84 rm -f $OUTFILE $ERRFILE $CMDFILE
85 exit $RESULT
86 }
87
88 trap cleanup 0 1 2 15
89
90 # make sure that the environment is sane - svc.configd is up and running
91 check_gl_env
92 [[ $? -ne 0 ]] && {
93 print_err "$assertion: invalid test environment"
94 exit $STF_UNRESOLVED
95 }
96
97 # extract and print assertion information from this source script.
98 extract_assertion_info $ME
99
100 typeset -i index=1
101 # create the test services/instance for testing
102 while [ $index -le $num_entities ]
103 do
104 SERVICE=${TEST_SERVICE}_${index}
105
106 service_exists $SERVICE
107 [[ $? -eq 0 ]] && {
108 echo "--DIAG: [${assertion}, setup]
109 service ${SERVICE} should not exist in
110 repository for test to run."
111
112 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
113 exit $RESULT
114 }
115
116 svccfg add $SERVICE > $OUTFILE 2>$ERRFILE
117 [[ $? -ne 0 ]] && {
118 echo "--DIAG: [${assertion}, setup]
119 error adding service ${SERVICE}, can not continue test
120 error output is $(cat $ERRFILE)"
121
122 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
123 exit $RESULT
124 }
125
126 # Create svccfg file that select an non-existent instance
127 i=1
128 while [ $i -le $num_entities ]
129 do
130 cat <<EOF >>$CMDFILE
131 select ${SERVICE}
132 add ${SERVICE}_${TEST_INSTANCE}_$i
133 EOF
134 (( i = i + 1 ))
135 done
136
137 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
138 ret=$?
139
140 # Verify that the return value is as expected - fatal error
141 [[ $ret -ne 0 ]] && {
142 echo "--DIAG: [${assertion}, setup]
143 svccfg expected to return 0, got $ret
144 error output is $(cat $ERRFILE)"
145
146 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
147
148 exit $RESULT
149
150 }
151
152 (( index = index + 1 ))
153
154 rm -f $OUTFILE $ERRFILE $CMDFILE
155 done
156
157
158 #
159 # Now execute the test
160 #
161
162 typeset -i index=1
163 # create the test services/instance for testing
164 while [ $index -le $num_entities ]
165 do
166
167 echo "--INFO: Starting $assertion, test $index"
168 typeset -i TEST_RESULT=$STF_PASS
169
170 ((nindex = (index % num_entities) + 1))
171
172 SERVICE=${TEST_SERVICE}_$index
173 NSERVICE=${TEST_SERVICE}_${nindex}
174
175 # Create svccfg file that select an non-existent instance
176 cat <<EOF >$CMDFILE
177 select ${SERVICE}
178 select ${NSERVICE}
179 list ${NSERVICE}*
180 select ${SERVICE}:${SERVICE}_${TEST_INSTANCE}_${index}
181 list
182 EOF
183
184 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
185 ret=$?
186
187 # Verify that the return value is as expected - non-fatal error
188 [[ $ret -ne 0 ]] && {
189 echo "--DIAG: [${assertion}, test $index]
190 svccfg select expected to return 0, got $ret"
191
192 TEST_RESULT=$STF_FAIL
193 }
194
195 # Verify that nothing in stderr - non-fatal error
196 [[ -s $ERRFILE ]] && {
197 echo "--DIAG: [${assertion}, test $index]
198 stderr not expected, but got $(cat $ERRFILE)"
199
200 TEST_RESULT=$STF_FAIL
201 }
202
203 # Verify the output of the file
204 num_lines=$(egrep -c ":properties" $OUTFILE)
205 [[ $num_lines -ne 2 ]] && {
206 echo "--DIAG: [${assertion}, test $index]
207 expected 2 \":properties\" lines"
208
209 TEST_RESULT=$STF_FAIL
210 }
211
212 typeset i=1
213 while [ $i -le $num_entities ]
214 do
215 num_lines=$(egrep -c "^${NSERVICE}_${TEST_INSTANCE}_${i}$" $OUTFILE)
216 [[ $num_lines -ne 1 ]] && {
217 echo "--DIAG: [${assertion}, test $index]
218 expected list to show ${NSERVICE}_${TEST_INSTANCE}_${i} but did not"
219
220 TEST_RESULT=$STF_FAIL
221 }
222 (( i = i + 1 ))
223 done
224
225 num_lines=$(wc -l $OUTFILE | awk '{print $1}')
226
227 (( total_lines = num_entities + 2 ))
228
229 [[ $num_lines -ne $total_lines ]] && {
230 echo "--DIAG: [${assertion}, test $index]
231 expected $total_lines, lines but got $num_lines"
232
233 TEST_RESULT=$STF_FAIL
234 }
235 [[ $TEST_RESULT -eq $STF_FAIL ]] && {
236 echo "--DIAG: Here is the output:
237 $(cat $OUTFILE)"
238 }
239
240 (( index = index + 1 ))
241
242 rm -f $OUTFILE $ERRFILE $CMDFILE
243
244 print_result $TEST_RESULT
245
246 RESULT=$(update_result $TEST_RESULT $RESULT)
247 done
248
249 exit $RESULT