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_005
40 #
41 # DESCRIPTION:
42 # Calling 'svcadm disable <online FMRI>' where FMRI is a service instance
43 # should transit from state online to disabled.
44 # STRATEGY:
45 # - Check for test setup.
46 # - Configure a service 'foo$$' using svccfg
47 # - Enable it using svcadm
48 # - Make sure state is online
49 # - Disable it using svcadm
50 # - Make sure state is disabled.
51 #
52 # COMMANDS: svcadm(1)
53 #
54 # end __stf_assertion__
55 ################################################################################
56
57 # First load up definitions of STF result variables like STF_PASS etc.
58 . ${STF_TOOLS}/include/stf.kshlib
59
60 # Load up definitions of shell functionality common to all smf sub-suites.
61 . ${STF_SUITE}/include/gltest.kshlib
62
63 # Define Variables
64 readonly assertion=svcadm_disable_005
65 readonly svccfg_add_script=/var/tmp/svcadm_disable_005.$$.config
66 readonly service_test=foo$$
67 readonly instance_test=instance$$
68 readonly ME=$(whence -p ${0})
69 readonly MYLOC=$(dirname ${ME})
70
71 # gltest.kshlib functions to extract and print assertion information
72 # from this source script.
73 extract_assertion_info $ME
74
75 # Initialize test result to pass.
76 typeset -i RESULT=${STF_UNRESOLVED}
77
78 # Set a trap to execute the cleanup function when specified signals
79 # are received.
80 trap cleanup 0 1 2 15
81
82 # Exit code for individual commands.
83 typeset -i tmp_rc=0
84
85 # Make sure we run as root
86 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
87 then
88 echo "--DIAG: [$assertion]
89 This test must be run from root."
90 print_result $RESULT
91 exit $RESULT
92 fi
93
94
95 # Execute environmental sanity checks.
96 check_gl_env
97 tmp_rc=$?
98 if [[ $tmp_rc -ne 0 ]]
99 then
100 echo "--DIAG: [$assertion]
101 Invalid smf environment, quitting."
102 print_result $RESULT
103 exit $RESULT
104 fi
105
106 # Create the svccfg add script which will add entities to the
107 # repository for this test case.
108
109 echo "--INFO: [${assertion}]
110 configure $service_test using svccfg"
111
112 cat > $svccfg_add_script <<EOF
113 add $service_test
114 select $service_test
115 add $instance_test
116 EOF
117
118 #Add objects to repository
119
120 echo "--INFO: [${assertion}]
121 Adding entities <$service_test> to repository using svccfg"
122
123 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
124 if [ $? -ne 0 ]; then
125 echo "--DIAG: [$assertion]
126 Adding entities using svccfg failed."
127 print_result $RESULT
128 exit $RESULT
129 fi
130
131 echo "--INFO: [${assertion}]
132 enable <$service_test> using svcadm"
133
134 #Enable the service using svcadm
135 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
136 if [ $? -ne 0 ]; then
137 echo "--DIAG: [$assertion]
138 svcadm enable $service_test failed."
139 print_result $RESULT
140 exit $RESULT
141 fi
142
143 #Wait just for sometime, let the service STATE get updated
144
145 echo "--INFO: [${assertion}]
146 Wait until state transition gets completed"
147
148 inst_fmri=$service_test:$instance_test
149
150 service_wait_state $inst_fmri online
151 if [ $? -ne 0 ]; then
152 echo "--DIAG: [$assertion]
153 <$service_test> is not online"
154 print_result $RESULT
155 exit $RESULT
156 fi
157
158 echo "--INFO: [${assertion}]
159 Verify that state = online"
160
161 state=`svcprop -p restarter/state $inst_fmri 2>/dev/null`
162 ret=$?
163 if [[ $ret -ne 0 || "$state" != "online" ]]; then
164 echo "--DIAG: [$assertion]
165 EXPECTED: ret = 0; STATE= online
166 ACTUAL: ret = $ret; STATE = $state"
167 print_result $RESULT
168 exit $RESULT
169 fi
170
171 echo "--INFO: [${assertion}]
172 disable $service_test using svcadm"
173
174 #Disable the service using svcadm
175 /usr/sbin/svcadm disable $service_test >/dev/null 2>&1
176 ret=$?
177 if [ $ret -ne 0 ]; then
178 RESULT=$(update_result $STF_FAIL $RESULT)
179 echo "--DIAG: [$assertion]
180 svcadm disable $service_test failed.
181 EXPECTED: ret = 0
182 ACTUAL: ret = $ret"
183 print_result $RESULT
184 exit $RESULT
185 fi
186
187 echo "--INFO: [${assertion}]
188 Wait until state transition gets completed"
189
190 service_wait_state $inst_fmri disabled
191 if [ $? -ne 0 ]; then
192 RESULT=$(update_result $STF_FAIL $RESULT)
193 state=`svcprop -p restarter/state $inst_fmri 2>/dev/null`
194 echo "--DIAG: [$assertion]
195 EXPECTED: STATE= disabled
196 ACTUAL: STATE = $state"
197 print_result $RESULT
198 exit $RESULT
199 fi
200
201 echo "--INFO: [${assertion}]
202 Verify that state = disabled"
203
204 state=`svcprop -p restarter/state $inst_fmri 2>/dev/null`
205 ret=$?
206 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
207 RESULT=$(update_result $STF_FAIL $RESULT)
208 echo "--DIAG: [$assertion]
209 EXPECTED: ret = 0; STATE= disabled
210 ACTUAL: ret = $ret; STATE = $state"
211 print_result $RESULT
212 exit $RESULT
213 fi
214
215 echo "--INFO: [${assertion}]
216 Assertion proved"
217
218 RESULT=$STF_PASS
219 print_result $RESULT
220 exit $RESULT