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_disable_001
40 #
41 # DESCRIPTION:
42 # Calling 'svcadm disable FMRI' where FMRI is a service instance that is
43 # already in the disabled state will have no effect on the service.
44 # The exit status is 0.
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 # - Using svcprop make sure 'foo$$' has its STATE disabled
51 # - Again attempt to disable it using svcadm
52 # - Make sure exit status is 0.
53 # - Also verify using svcprop and make sure 'foo$$' has STATE disabled
54 #
55 # COMMANDS: svcadm(1)
56 #
57 # end __stf_assertion__
58 ################################################################################
59
60 # First load up definitions of STF result variables like STF_PASS etc.
61 . ${STF_TOOLS}/include/stf.kshlib
62
63 # Load up definitions of shell functionality common to all smf sub-suites.
64 . ${STF_SUITE}/include/gltest.kshlib
65
66 # Define Variables
67 readonly assertion=svcadm_disable_001
68 readonly svccfg_add_script=/var/tmp/svcadm_disable_001.$$.config
69 readonly service_test=foo$$
70 readonly instance_test=instance$$
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 just for sometime, let the service STATE get updated
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 disable $service_test using svcadm"
161
162 #Disable the service using svcadm
163 /usr/sbin/svcadm disable $service_test >/dev/null 2>&1
164 ret=$?
165 if [ $ret -ne 0 ]; then
166 echo "--DIAG: [$assertion]
167 svcadm disable $service_test failed.
168 EXPECTED: ret = 0
169 ACTUAL: ret = $ret"
170 print_result $RESULT
171 exit $RESULT
172 fi
173
174 echo "--INFO: [${assertion}]
175 Wait for sometime to state transition gets completed"
176
177 inst_fmri=$service_test:$instance_test
178 service_wait_state $inst_fmri disabled
179 if [ $? -ne 0 ]; then
180 state=`svcprop -p restarter/state $inst_fmri 2>/dev/null`
181 echo "--DIAG: [$assertion]
182 EXPECTED: STATE= disabled
183 ACTUAL: STATE = $state"
184 print_result $RESULT
185 exit $RESULT
186 fi
187
188 echo "--INFO: [${assertion}]
189 Here's assertion part; attempt to disable again"
190
191 /usr/sbin/svcadm disable $service_test >/dev/null 2>&1
192 ret=$?
193 if [ $ret -ne 0 ]; then
194 RESULT=$(update_result $STF_FAIL $RESULT)
195 echo "--DIAG: [$assertion]
196 svcadm disable $service_test (already disabled) failed.
197 EXPECTED: ret = 0
198 ACTUAL: ret = $ret"
199 print_result $RESULT
200 exit $RESULT
201 fi
202
203 echo "--INFO: [${assertion}]
204 Verify state remains unchanged from disabled"
205
206 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
207 if [[ $? -ne 0 || "$state" != "disabled" ]]; then
208 RESULT=$(update_result $STF_FAIL $RESULT)
209 echo "--DIAG: [$assertion]
210 svcprop -p restarter/state $service_test:$instance_test
211 EXPECTED: ret =0; state=disabled
212 ACTUAL: ret = $ret; state= $state"
213 print_result $RESULT
214 exit $RESULT
215 fi
216
217 echo "--INFO: [${assertion}]
218 Assertion proved"
219 RESULT=$STF_PASS
220 print_result $RESULT
221 exit $RESULT