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_unselect_001
32 #
33 # DESCRIPTION:
34 # The 'unselect' subcommand causes the parent of the
35 # current selection to become the currently selected
36 # entity. Upon success, no error is printed to stderr.
37 # In the absence of any other errors during processing,
38 # the exit status will be 0.
39 #
40 # STRATEGY:
41 # Test unselect from the service and service instance level.
42 #
43 # end __stf_assertion__
44 ###############################################################################
45
46 # First STF library
47 . ${STF_TOOLS}/include/stf.kshlib
48
49 # Load GL library
50 . ${STF_SUITE}/include/gltest.kshlib
51
52 readonly ME=$(whence -p ${0})
53 readonly MYLOC=$(dirname ${ME})
54
55 # Initialize test result
56 typeset -i RESULT=$STF_PASS
57
58 typeset readonly SERVICE_LIST=/tmp/sl.$$
59 typeset readonly SERVICE_LIST_2=/tmp/sl_2.$$
60 typeset readonly INSTANCE_LIST=/tmp/il.$$
61 typeset readonly INSTANCE_LIST_2=/tmp/il_2.$$
62
63 assertion=svccfg_unselect_001
64
65
66 function cleanup {
67
68 # Note that $TEST_SERVICE may or may not exist so don't check
69 # results. Just make sure the service is gone.
70 service_delete $TEST_SERVICE
71
72 service_exists ${TEST_SERVICE}
73 [[ $? -eq 0 ]] && {
74 echo "--DIAG: [${assertion}, cleanup]
75 service ${TEST_SERVICE} should not exist in
76 repository after being deleted, but does"
77
78 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
79 }
80
81
82 rm -f $SERVICE_LIST $SERVICE_LIST_2 $INSTANCE_LIST $INSTANCE_LIST_2
83 rm -f $OUTFILE $ERRFILE $CMDFILE
84
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 echo "--DIAG:
94 Invalid test environment - svc.configd not available"
95
96 RESULT=$STF_UNRESOLVED
97 exit $RESULT
98 }
99
100 # extract and print assertion information from this source script.
101 extract_assertion_info $ME
102
103
104 # Before starting make sure that the test service doesn't already exist.
105 # If it does then consider it a fatal error.
106 service_exists $TEST_SERVICE
107 [[ $? -eq 0 ]] && {
108 echo "--DIAG: [${assertion}]
109 service $TEST_SERVICE should not exist in repository but does"
110
111 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
112 exit $RESULT
113 }
114
115
116 # Add the service and a service instance
117 cat << EOF > $CMDFILE
118 add ${TEST_SERVICE}
119 select ${TEST_SERVICE}
120 add ${TEST_INSTANCE}
121 EOF
122
123 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
124 ret=$?
125 [[ $? -ne 0 ]] && {
126 echo "--DIAG: [${assertion}]
127 error setting up service $TEST_SERVICE and
128 $instance TEST_INSTANCE; here is error output:
129 $(cat $ERRFILE)"
130
131 RESULT=$STF_UNRESOLVED
132 exit $RESULT
133 }
134
135 # Capture the listing of the service
136 svccfg list > $SERVICE_LIST 2>$ERRFILE
137 ret=$?
138 [[ $? -ne 0 ]] && {
139 echo "--DIAG: [${assertion}]
140 error getting listing from service $TEST_SERVICE;
141 here is error output:
142 $(cat $ERRFILE)"
143
144 RESULT=$STF_UNRESOLVED
145 exit $RESULT
146 }
147
148
149 # Capture the listing of the service instance
150 cat << EOF > $CMDFILE
151 select ${TEST_SERVICE}
152 list
153 EOF
154
155 svccfg -f $CMDFILE > $INSTANCE_LIST 2>$ERRFILE
156 ret=$?
157 [[ $? -ne 0 ]] && {
158 echo "--DIAG: [${assertion}]
159 error getting listing from instance $TEST_INSTANCE;
160 here is error output:
161 $(cat $ERRFILE)"
162
163 RESULT=$STF_UNRESOLVED
164 exit $RESULT
165 }
166
167 echo "--INFO: Starting $assertion, test 1 (unselect from instance)"
168
169 typeset -i TEST_RESULT=$STF_PASS
170
171 # Call unselect from the instance level
172 cat << EOF > $CMDFILE
173 select ${TEST_SERVICE}
174 select ${TEST_INSTANCE}
175 unselect
176 list
177 EOF
178
179 svccfg -f $CMDFILE > ${INSTANCE_LIST_2} 2>$ERRFILE
180 ret=$?
181 [[ $? -ne 0 ]] && {
182 echo "--DIAG: [${assertion}, test 1]
183 error getting listing from instance $TEST_INSTANCE;
184 here is error output:
185 $(cat $ERRFILE)"
186
187 TEST_RESULT=$STF_FAIL
188 }
189
190 # Verify that nothing in stderr - this is a non-fatal error
191 [[ -s $ERRFILE ]] && {
192 echo "--DIAG: [${assertion}, test 1]
193 stderr not expected, but got $(cat $ERRFILE)"
194
195 TEST_RESULT=$STF_FAIL
196 }
197
198
199 diff ${INSTANCE_LIST} ${INSTANCE_LIST_2}
200 [[ $? -ne 0 ]] && {
201 echo "--DIAG: [${assertion}, test 1]
202 error in instance unselect"
203
204 TEST_RESULT=$STF_FAIL
205 }
206
207 print_result $TEST_RESULT
208 RESULT=$(update_result $TEST_RESULT $RESULT)
209
210
211 echo "--INFO: Starting $assertion, test 2 (unselect from service)"
212
213 typeset -i TEST_RESULT=$STF_PASS
214
215
216 # Call unselect from the service level
217 cat << EOF > $CMDFILE
218 select ${TEST_SERVICE}
219 unselect
220 list
221 EOF
222
223 svccfg -f $CMDFILE > ${SERVICE_LIST_2} 2>$ERRFILE
224 ret=$?
225 [[ $? -ne 0 ]] && {
226 echo "--DIAG: [${assertion}, test 2]
227 error getting listing from instance $TEST_SERVICE;
228 here is error output:
229 cat $(ERRFILE)"
230
231 TEST_RESULT=$STF_FAIL
232 }
233
234 # Verify that nothing in stderr - this is a non-fatal error
235 [[ -s $ERRFILE ]] && {
236 echo "--DIAG: [${assertion}]
237 stderr not expected, but got $(cat $ERRFILE)"
238
239 TEST_RESULT=$STF_FAIL
240 }
241
242 diff ${SERVICE_LIST} ${SERVICE_LIST_2}
243 [[ $? -ne 0 ]] && {
244 echo "--DIAG: [${assertion}]
245 error in service unselect"
246
247 TEST_RESULT=$STF_FAIL
248 }
249
250 print_result $TEST_RESULT
251 RESULT=$(update_result $TEST_RESULT $RESULT)
252
253 exit $RESULT