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