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_004
40 #
41 # DESCRIPTION:
42 # svcadm <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 <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_004
67 readonly svccfg_add_script=/var/tmp/svcadm_clear_004.$$.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 $service_test:$instance_test online
152 if [ $? -ne 0 ]; then
153 echo "--DIAG: [$assertion]
154 <$service_test> 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 $service_test:$instance_test 2>/dev/null`
163 ret=$?
164 if [[ $ret -ne 0 || "$state" != "online" ]]; then
165 echo "--DIAG: [$assertion]
166 EXPECTED: ret = 0; STATE= online
167 ACTUAL: ret = $ret; STATE = $state"
168 print_result $RESULT
169 exit $RESULT
170 fi
171
172 echo "--INFO: [${assertion}]
173 disable <$service_test> using svcadm"
174
175 # Disable the service using svcadm
176 /usr/sbin/svcadm disable $service_test >/dev/null 2>&1
177 if [ $? -ne 0 ]; then
178 echo "--DIAG: [$assertion]
179 svcadm disable $service_test failed."
180 print_result $RESULT
181 exit $RESULT
182 fi
183
184 echo "--INFO: [${assertion}]
185 Wait until state transition gets completed"
186
187 service_wait_state $service_test:$instance_test disabled
188 if [ $? -ne 0 ]; then
189 echo "--DIAG: [$assertion]
190 <$service_test> is not disabled"
191 print_result $RESULT
192 exit $RESULT
193 fi
194
195 echo "--INFO: [${assertion}]
196 Verify that state = disabled"
197
198 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
199 ret=$?
200 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
201 echo "--DIAG: [$assertion]
202 EXPECTED: ret = 0; STATE= disabled
203 ACTUAL: ret = $ret; STATE = $state"
204 print_result $RESULT
205 exit $RESULT
206 fi
207
208 echo "--INFO: [${assertion}]
209 Clear <$fmri> using svcadm"
210
211 # Invoke clear on the service
212 /usr/sbin/svcadm clear $fmri >/dev/null 2>&1
213 if [ $? -ne 1 ]; then
214 RESULT=$(update_result $STF_FAIL $RESULT)
215 echo "--DIAG: [$assertion]
216 svcadm clear $service_test should fail with exit 1"
217 print_result $RESULT
218 exit $RESULT
219 fi
220
221 echo "--INFO: [${assertion}]
222 Verify that state is unchanged from disabled"
223
224 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
225 ret=$?
226 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
227 RESULT=$(update_result $STF_FAIL $RESULT)
228 echo "--DIAG: [$assertion]
229 EXPECTED: ret = 0; STATE= disabled
230 ACTUAL: ret = $ret; STATE = $state"
231 print_result $RESULT
232 exit $RESULT
233 fi
234
235
236 echo "--INFO: [${assertion}]
237 Assertion proved"
238 RESULT=$STF_PASS
239 print_result $RESULT
240 exit $RESULT