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 #
25 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
26 # Use is subject to license terms.
27 #
28
29 #This function is to cleanup the leftovers by this test
30
31 function cleanup {
32 service_cleanup $service_test1
33 service_cleanup $service_test2
34 /usr/bin/rm -f $svccfg_add_script1
35 /usr/bin/rm -f $svccfg_add_script2
36 }
37
38 ###############################################################################
39 # start __stf_assertion__
40 #
41 # ASSERTION: svcadm_disable_009
42 #
43 # DESCRIPTION:
44 # svcadm disable <service list> should succeed
45 # STRATEGY:
46 # - Check for test setup.
47 # - Configure a service 'foo$$1' using svccfg
48 # - configure another service foo$$2 using svccfg
49 # - Enable them using svcadm
50 # - Make sure their state is online
51 # - Call svcadm disable <service list> and make sure it exits 0.
52 # - Make sure state is disabled.
53 #
54 # COMMANDS: svcadm(1)
55 #
56 # end __stf_assertion__
57 ################################################################################
58
59 # First load up definitions of STF result variables like STF_PASS etc.
60 . ${STF_TOOLS}/include/stf.kshlib
61
62 # Load up definitions of shell functionality common to all smf sub-suites.
63 . ${STF_SUITE}/include/gltest.kshlib
64
65 # Define Variables
66 readonly assertion=svcadm_disable_009
67 readonly svccfg_add_script1=/var/tmp/svcadm_disable_009.$$.config1
68 readonly svccfg_add_script2=/var/tmp/svcadm_disable_009.$$.config2
69 readonly service_test1=foo$$1
70 readonly service_test2=foo$$2
71 readonly instance_test=instance$$
72 readonly inst1_fmri=$service_test1:$instance_test
73 readonly inst2_fmri=$service_test2:$instance_test
74 readonly ME=$(whence -p ${0})
75 readonly MYLOC=$(dirname ${ME})
76
77 # gltest.kshlib functions to extract and print assertion information
78 # from this source script.
79 extract_assertion_info $ME
80
81 # Initialize test result to pass.
82 typeset -i RESULT=${STF_UNRESOLVED}
83
84 # Set a trap to execute the cleanup function when specified signals
85 # are received.
86 trap cleanup 0 1 2 15
87
88 # Exit code for individual commands.
89 typeset -i tmp_rc=0
90
91 # Make sure we run as root
92 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
93 then
94 echo "--DIAG: [$assertion]
95 This test must be run from root."
96 print_result $RESULT
97 exit $RESULT
98 fi
99
100
101 # Execute environmental sanity checks.
102 check_gl_env
103 tmp_rc=$?
104 if [[ $tmp_rc -ne 0 ]]
105 then
106 echo "--DIAG: [$assertion]
107 Invalid smf environment, quitting."
108 print_result $RESULT
109 exit $RESULT
110 fi
111
112 # Create the svccfg add script which will add entities to the
113 # repository for this test case.
114
115 echo "--INFO: [${assertion}]
116 configure $service_test1 using svccfg"
117
118 cat > $svccfg_add_script1 <<EOF
119 add $service_test1
120 select $service_test1
121 add $instance_test
122 EOF
123
124 echo "--INFO: [${assertion}]
125 configure $service_test2 using svccfg"
126
127 cat > $svccfg_add_script2 <<EOF
128 add $service_test2
129 select $service_test2
130 add $instance_test
131 EOF
132
133 #Add objects to repository
134
135 echo "--INFO: [${assertion}]
136 Adding entities <$service_test1> to repository using svccfg"
137
138 /usr/sbin/svccfg -f $svccfg_add_script1 >/dev/null 2>&1
139 if [ $? -ne 0 ]; then
140 echo "--DIAG: [$assertion]
141 Adding entities using svccfg failed."
142 print_result $RESULT
143 exit $RESULT
144 fi
145 #Add objects to repository
146
147 echo "--INFO: [${assertion}]
148 Adding entities <$service_test2> to repository using svccfg"
149
150 /usr/sbin/svccfg -f $svccfg_add_script2 >/dev/null 2>&1
151 if [ $? -ne 0 ]; then
152 echo "--DIAG: [$assertion]
153 Adding entities using svccfg failed."
154 print_result $RESULT
155 fi
156
157 echo "--INFO: [${assertion}]
158 enable <$service_test1> using svcadm"
159
160 #Enable the service using svcadm
161 /usr/sbin/svcadm enable $service_test1 >/dev/null 2>&1
162 if [ $? -ne 0 ]; then
163 echo "--DIAG: [$assertion]
164 svcadm enable $service_test1 failed."
165 print_result $RESULT
166 exit $RESULT
167 fi
168
169 #Enable the service using svcadm
170 /usr/sbin/svcadm enable $service_test2 >/dev/null 2>&1
171 if [ $? -ne 0 ]; then
172 echo "--DIAG: [$assertion]
173 svcadm enable $service_test2 failed."
174 print_result $RESULT
175 exit $RESULT
176 fi
177
178 #Wait just for sometime, let the service STATE gets updated
179
180 echo "--INFO: [${assertion}]
181 Wait until state transition gets completed"
182
183 service_wait_state $inst1_fmri online
184 if [ $? -ne 0 ]; then
185 echo "--DIAG: [$assertion]
186 <$service_test1> is not online"
187 print_result $RESULT
188 exit $RESULT
189 fi
190
191 service_wait_state $inst2_fmri online
192 if [ $? -ne 0 ]; then
193 echo "--DIAG: [$assertion]
194 <$service_test2> is not online"
195 print_result $RESULT
196 exit $RESULT
197 fi
198
199 echo "--INFO: [${assertion}]
200 Verify that state = online"
201
202 state=`svcprop -p restarter/state $inst1_fmri 2>/dev/null`
203 ret=$?
204 if [[ $ret -ne 0 || "$state" != "online" ]]; then
205 echo "--DIAG: [$assertion]
206 EXPECTED: ret = 0; STATE= online
207 ACTUAL: ret = $ret; STATE = $state"
208 print_result $RESULT
209 exit $RESULT
210 fi
211
212 state=`svcprop -p restarter/state $inst2_fmri 2>/dev/null`
213 ret=$?
214 if [[ $ret -ne 0 || "$state" != "online" ]]; then
215 echo "--DIAG: [$assertion]
216 EXPECTED: ret = 0; STATE= online
217 ACTUAL: ret = $ret; STATE = $state"
218 print_result $RESULT
219 exit $RESULT
220 fi
221
222 echo "--INFO: [${assertion}]
223 disable $service_test1 $service_test2 using svcadm"
224
225 #Disable the service using svcadm
226 /usr/sbin/svcadm disable $service_test1 $service_test2 >/dev/null 2>&1
227 ret=$?
228 if [ $ret -ne 0 ]; then
229 RESULT=$(update_result $STF_FAIL $RESULT)
230 echo "--DIAG: [$assertion]
231 svcadm disable $service_test1 $service_test2 failed.
232 EXPECTED: ret = 0
233 ACTUAL: ret = $ret"
234 print_result $RESULT
235 exit $RESULT
236 fi
237
238 echo "--INFO: [${assertion}]
239 Wait until state transition gets completed"
240
241 service_wait_state $inst1_fmri disabled
242 if [ $? -ne 0 ]; then
243 RESULT=$(update_result $STF_FAIL $RESULT)
244 state=`svcprop -p restarter/state $inst1_fmri 2>/dev/null`
245 echo "--DIAG: [$assertion]
246 EXPECTED: STATE= disabled
247 ACTUAL: STATE = $state"
248 print_result $RESULT
249 exit $RESULT
250 fi
251
252 service_wait_state $inst2_fmri disabled
253 if [ $? -ne 0 ]; then
254 RESULT=$(update_result $STF_FAIL $RESULT)
255 state=`svcprop -p restarter/state $inst2_fmri 2>/dev/null`
256 echo "--DIAG: [$assertion]
257 EXPECTED: STATE= disabled
258 ACTUAL: STATE = $state"
259 print_result $RESULT
260 exit $RESULT
261 fi
262
263 echo "--INFO: [${assertion}]
264 Verify that state = disabled"
265
266 state=`svcprop -p restarter/state $inst1_fmri 2>/dev/null`
267 ret=$?
268 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
269 RESULT=$(update_result $STF_FAIL $RESULT)
270 echo "--DIAG: [$assertion]
271 EXPECTED: ret = 0; STATE= disabled
272 ACTUAL: ret = $ret; STATE = $state"
273 print_result $RESULT
274 exit $RESULT
275 fi
276
277 state=`svcprop -p restarter/state $inst2_fmri 2>/dev/null`
278 ret=$?
279 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
280 RESULT=$(update_result $STF_FAIL $RESULT)
281 echo "--DIAG: [$assertion]
282 EXPECTED: ret = 0; STATE= disabled
283 ACTUAL: ret = $ret; STATE = $state"
284 print_result $RESULT
285 exit $RESULT
286 fi
287
288 echo "--INFO: [${assertion}]
289 Assertion proved"
290
291 RESULT=$STF_PASS
292 print_result $RESULT
293 exit $RESULT