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_test
33 /usr/bin/rm -f $svccfg_add_script
34 }
35
36 ###############################################################################
37 # start __stf_assertion__
38 #
39 # ASSERTION: svcadm_clear_005
40 #
41 # DESCRIPTION:
42 # svcadm -v <clear> FMRI, where FMRI is a service instance which
43 # is currently in disabled STATE should fail with exit 1
44 #
45 # STRATEGY:
46 # - Check for test setup.
47 # - Configure a service 'foo$$' using svccfg
48 # - Enable it using svcadm
49 # - Disable it using svcadm
50 # - Call svcadm -v <clear> <FMRI>
51 # - Verify that above step fails with exit 1
52 # - Also make sure STATE doesn't change from 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_clear_005
67 readonly svccfg_add_script=/var/tmp/svcadm_clear_005.$$.config
68 readonly service_test=foo$$
69 readonly instance_test=instance$$
70 readonly fmri="svc:/$service_test:$instance_test"
71 readonly ME=$(whence -p ${0})
72 readonly MYLOC=$(dirname ${ME})
73
74 # gltest.kshlib functions to extract and print assertion information
75 # from this source script.
76 extract_assertion_info $ME
77
78 # Initialize test result to pass.
79 typeset -i RESULT=${STF_UNRESOLVED}
80
81 # Set a trap to execute the cleanup function when specified signals
82 # are received.
83 trap cleanup 0 1 2 15
84
85 # Exit code for individual commands.
86 typeset -i tmp_rc=0
87
88 # Make sure we run as root
89 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
90 then
91 echo "--DIAG: [$assertion]
92 This test must be run from root."
93 print_result $RESULT
94 exit $RESULT
95 fi
96
97
98 # Execute environmental sanity checks.
99 check_gl_env
100 tmp_rc=$?
101 if [[ $tmp_rc -ne 0 ]]
102 then
103 echo "--DIAG: [$assertion]
104 Invalid smf environment, quitting."
105 print_result $RESULT
106 exit $RESULT
107 fi
108
109 # Create the svccfg add script which will add entities to the
110 # repository for this test case.
111
112 echo "--INFO: [${assertion}]
113 configure $service_test using svccfg"
114
115 cat > $svccfg_add_script <<EOF
116 add $service_test
117 select $service_test
118 add $instance_test
119 EOF
120
121 #Add objects to repository
122
123 echo "--INFO: [${assertion}]
124 Adding entities <$service_test> to repository using svccfg"
125
126 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
127 if [ $? -ne 0 ]; then
128 echo "--DIAG: [$assertion]
129 Adding entities using svccfg failed."
130 print_result $RESULT
131 exit $RESULT
132 fi
133
134 echo "--INFO: [${assertion}]
135 enable <$service_test> using svcadm"
136
137 #Enable the service using svcadm
138 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
139 if [ $? -ne 0 ]; then
140 echo "--DIAG: [$assertion]
141 svcadm enable $service_test failed."
142 print_result $RESULT
143 exit $RESULT
144 fi
145
146 # Wait until state transition is complete
147
148 echo "--INFO: [${assertion}]
149 Wait until state transition gets completed"
150
151 service_wait_state $fmri online
152 if [ $? -ne 0 ]; then
153 echo "--DIAG: [$assertion]
154 <$fmri> is not online"
155 print_result $RESULT
156 exit $RESULT
157 fi
158
159 echo "--INFO: [${assertion}]
160 Verify that state = online"
161
162 state=`svcprop -p restarter/state $fmri 2>/dev/null`
163 ret=$?
164 if [[ $ret -ne 0 || "$state" != "online" ]]; then
165 RESULT=$(update_result $STF_FAIL $RESULT)
166 echo "--DIAG: [$assertion]
167 EXPECTED: ret = 0; STATE= online
168 ACTUAL: ret = $ret; STATE = $state"
169 print_result $RESULT
170 exit $RESULT
171 fi
172
173 echo "--INFO: [${assertion}]
174 disable <$service_test> using svcadm"
175
176 #Disable the service using svcadm
177 /usr/sbin/svcadm disable $service_test >/dev/null 2>&1
178 if [ $? -ne 0 ]; then
179 echo "--DIAG: [$assertion]
180 svcadm disable $service_test failed."
181 print_result $RESULT
182 exit $RESULT
183 fi
184
185 echo "--INFO: [${assertion}]
186 Wait until state transition gets completed"
187
188 service_wait_state $fmri disabled
189 if [ $? -ne 0 ]; then
190 echo "--DIAG: [$assertion]
191 <$fmri not disabled"
192 print_result $RESULT
193 exit $RESULT
194 fi
195
196 echo "--INFO: [${assertion}]
197 Verify that state = disabled"
198
199 state=`svcprop -p restarter/state $fmri 2>/dev/null`
200 ret=$?
201 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
202 RESULT=$(update_result $STF_FAIL $RESULT)
203 echo "--DIAG: [$assertion]
204 EXPECTED: ret = 0; STATE= disabled
205 ACTUAL: ret = $ret; STATE = $state"
206 print_result $RESULT
207 exit $RESULT
208 fi
209
210 echo "--INFO: [${assertion}]
211 Clear <$fmri> using svcadm"
212
213 # Invoke clear on the service
214 /usr/sbin/svcadm -v clear $fmri >/dev/null 2>&1
215 if [ $? -ne 1 ]; then
216 echo "--DIAG: [$assertion]
217 svcadm -v clear $fmri should fail with exit 1"
218 print_result $RESULT
219 exit $RESULT
220 fi
221
222 echo "--INFO: [${assertion}]
223 Verify that state is unchanged from disabled"
224
225 state=`svcprop -p restarter/state $fmri 2>/dev/null`
226 ret=$?
227 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
228 RESULT=$(update_result $STF_FAIL $RESULT)
229 echo "--DIAG: [$assertion]
230 EXPECTED: ret = 0; STATE= disabled
231 ACTUAL: ret = $ret; STATE = $state"
232 print_result $RESULT
233 exit $RESULT
234 fi
235
236
237 echo "--INFO: [${assertion}]
238 Assertion proved"
239 RESULT=$STF_PASS
240 print_result $RESULT
241 exit $RESULT