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_003
32 #
33 # DESCRIPTION:
34 # If the (valid) scope or service the name specified in the
35 # subcommand "select name" does not exist in the repository,
36 # the diagnostic message "Not found." is sent to stderr. The
37 # command exit status will be 1.
38 #
39 # STRATEGY:
40 #
41 # end __stf_assertion__
42 ###############################################################################
43
44
45 # First STF library
46 . ${STF_TOOLS}/include/stf.kshlib
47
48 # Load GL library
49 . ${STF_SUITE}/include/gltest.kshlib
50
51 # Assertion ID
52 readonly assertion=svccfg_select_003
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 function cleanup {
61
62 # Note that $TEST_SERVICE may or may not exist so don't check
63 # results. Just make sure the service is gone.
64 service_delete $TEST_SERVICE > /dev/null 2>&1
65
66 service_exists ${TEST_SERVICE}
67 [[ $? -eq 0 ]] && {
68 echo "--DIAG: [${assertion}, cleanup]
69 service ${TEST_SERVICE} should not exist in
70 repository after being deleted, but does"
71
72 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
73 }
74 rm -f $OUTFILE $ERRFILE $CMDFILE
75 exit $RESULT
76 }
77
78 trap cleanup 0 1 2 15
79
80 # make sure that the environment is sane - svc.configd is up and running
81 check_gl_env
82 [[ $? -ne 0 ]] && {
83 print_err "$assertion: invalid test environment"
84 exit $STF_UNRESOLVED
85 }
86
87 # extract and print assertion information from this source script.
88 extract_assertion_info $ME
89
90
91 #
92 # Test #1: Non-existent service
93 #
94 echo "--INFO: Starting $assertion, test 1 (select non-existent service)"
95
96 typeset -i TEST_RESULT=$STF_PASS
97
98 service_exists ${TEST_SERVICE}
99 [[ $? -eq 0 ]] && {
100 echo "--DIAG: [${assertion}, test 1]
101 service ${TEST_SERVICE} should not exist in
102 repository for test to run."
103
104 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
105 exit $RESULT
106 }
107
108 svccfg select ${TEST_SERVICE} > $OUTFILE 2>$ERRFILE
109 ret=$?
110
111 # Verify that the return value is as expected - non-fatal error
112 [[ $ret -ne 1 ]] && {
113 echo "--DIAG: [${assertion}, test 1]
114 svccfg expected to return 0, got $ret"
115
116 TEST_RESULT=$STF_FAIL
117 }
118
119 # Verify that nothing in stdout - non-fatal error
120 [[ -s $OUTFILE ]] && {
121 echo "--DIAG: [${assertion}, test 1]
122 stdout not expected, but got $(cat $OUTFILE)"
123
124 TEST_RESULT=$STF_FAIL
125 }
126
127 EMSG="svccfg: Pattern '$TEST_SERVICE' doesn't match any instances or services"
128
129 # Verify message to stderr - non-fatal error
130 if ! egrep -s "$EMSG" $ERRFILE
131 then
132 echo "--DIAG: [${assertion}, test 1]
133 Expected error message \"$EMSG\"
134 but got \"$(cat $ERRFILE)\""
135
136 TEST_RESULT=$STF_FAIL
137 fi
138
139 rm -f $ERRFILE $OUTFILE
140
141 print_result $TEST_RESULT
142 RESULT=$(update_result $TEST_RESULT $RESULT)
143
144
145
146 #
147 # Test #2: Non-existent instance
148 #
149
150 echo "--INFO: Starting $assertion, test 2 select non-existent instance)"
151
152 typeset -i TEST_RESULT=$STF_PASS
153
154 #
155 # Add the service. If this fails consider it a fatal error
156 #
157 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
158 ret=$?
159 [[ $ret -ne 0 ]] && {
160 echo "--DIAG: [${assertion}]
161 error adding service $TEST_SERVICE needed for test
162 error output is $(cat $ERRFILE)"
163
164 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
165 exit $RESULT
166 }
167
168 # Make sure the service is there
169 service_exists $TEST_SERVICE
170 [[ $? -ne 0 ]] && {
171 echo "--DIAG: [${assertion}, test 1]
172 service $TEST_SERVICE should exist in
173 repository after being added, but does not"
174
175 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
176 exit $RESULT
177 }
178
179 # Create svccfg file that select an non-existent instance
180 cat <<EOF >$CMDFILE
181 select ${TEST_SERVICE}
182 select ${TEST_INSTANCE}
183 end
184 EOF
185
186
187 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
188 ret=$?
189
190 # Verify that the return value is as expected - non-fatal error
191 [[ $ret -ne 1 ]] && {
192 echo "--DIAG: [${assertion}, test 1]
193 svccfg expected to return 0, got $ret"
194
195 TEST_RESULT=$STF_FAIL
196 }
197
198 # Verify that nothing in stdout - non-fatal error
199 [[ -s $OUTFILE ]] && {
200 echo "--DIAG: [${assertion}, test 1]
201 stdout not expected, but got $(cat $OUTFILE)"
202
203 TEST_RESULT=$STF_FAIL
204 }
205
206 NO_MATCH="doesn't match any instances or services"
207 EMSG="svccfg ($CMDFILE, line 2): Pattern '$TEST_INSTANCE' $NO_MATCH"
208
209 # Verify message to stderr - non-fatal error
210 if ! grep -sl "$EMSG" $ERRFILE >/dev/null 2>&1
211 then
212 echo "--DIAG: [${assertion}, test 1]
213 Expected error message:
214 $EMSG
215 but got
216 $(cat $ERRFILE)"
217
218 TEST_RESULT=$STF_FAIL
219 fi
220
221 rm -f $ERRFILE $OUTFILE $CMDFILE
222
223 print_result $TEST_RESULT
224 RESULT=$(update_result $TEST_RESULT $RESULT)
225
226 exit $RESULT