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_degraded_005
40 #
41 # DESCRIPTION:
42 # Calling 'svcadm mark degraded <service>, where service
43 # has multiple instances should pass and exit 0.
44 # STRATEGY:
45 # - Check for test setup.
46 # - Configure a service 'foo$$' using svccfg
47 # - Attempt to put multiple instances to the service.
48 # - Now attempt to put them in degraded mode.
49 # - Make sure svcadm for degraded <service> passes with
50 # exit 0.
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_degraded_005
65 readonly svccfg_add_script=/var/tmp/svcadm_degraded_005.$$.config
66 readonly service_test=foo$$
67 readonly instance_test=instance$$
68 readonly instance_test1=instance1$$
69 readonly ME=$(whence -p ${0})
70 readonly MYLOC=$(dirname ${ME})
71
72 # gltest.kshlib functions to extract and print assertion information
73 # from this source script.
74 extract_assertion_info $ME
75
76 # Initialize test result to pass.
77 typeset -i RESULT=${STF_UNRESOLVED}
78
79 # Set a trap to execute the cleanup function when specified signals
80 # are received.
81 trap cleanup 0 1 2 15
82
83 # Exit code for individual commands.
84 typeset -i tmp_rc=0
85
86 # Make sure we run as root
87 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
88 then
89 echo "--DIAG: [$assertion]
90 This test must be run from root."
91 print_result $RESULT
92 exit $RESULT
93 fi
94
95
96 # Execute environmental sanity checks.
97 check_gl_env
98 tmp_rc=$?
99 if [[ $tmp_rc -ne 0 ]]
100 then
101 echo "--DIAG: [$assertion]
102 Invalid smf environment, quitting."
103 print_result $RESULT
104 exit $RESULT
105 fi
106
107 # Create the svccfg add script which will add entities to the
108 # repository for this test case.
109
110 echo "--INFO: [${assertion}]
111 configure $service_test using svccfg"
112
113 cat > $svccfg_add_script <<EOF
114 add $service_test
115 select $service_test
116 add $instance_test
117 add $instance_test1
118 EOF
119
120 #Add objects to repository
121 typeset -i rc=0
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 rc=$?
128 if [ $rc -ne 0 ]; then
129 echo "--DIAG: [$assertion]
130 Adding entities using svccfg failed.
131 EXPECTED: svccfg returned 0
132 RETURNED: svccfg returned $rc"
133 print_result $RESULT
134 exit $RESULT
135 fi
136
137 echo "--INFO: [${assertion}]
138 enable <$service_test:$instance_test> using svcadm"
139
140 #Enable the service using svcadm
141 /usr/sbin/svcadm enable $service_test:$instance_test >/dev/null 2>&1
142 rc=$?
143 if [ $rc -ne 0 ]; then
144 echo "--DIAG: [$assertion]
145 svcadm enable $service_test:$instance_test failed.
146 EXPECTED: 0
147 RETURNED: $rc"
148 print_result $RESULT
149 exit $RESULT
150 fi
151
152 echo "--INFO: [${assertion}]
153 enable <$service_test:$instance_test1> using svcadm"
154
155 #Enable the service using svcadm
156 /usr/sbin/svcadm enable $service_test:$instance_test1 >/dev/null 2>&1
157 rc=$?
158 if [ $rc -ne 0 ]; then
159 echo "--DIAG: [$assertion]
160 svcadm enable $service_test:$instance_test1 failed.
161 EXPECTED: 0
162 RETURNED: $rc"
163 print_result $RESULT
164 exit $RESULT
165 fi
166
167 #Wait just for sometime, let the service STATE gets updated
168
169 echo "--INFO: [${assertion}]
170 Wait for sometime to state transition gets completed"
171
172 service_wait_state $service_test:$instance_test online
173 rc=$?
174 if [ $rc -ne 0 ]; then
175 echo "--DIAG: [$assertion]
176 <$service_test:$instance_test> is not online"
177 print_result $RESULT
178 exit $RESULT
179 fi
180
181 service_wait_state $service_test:$instance_test1 online
182 rc=$?
183 if [ $rc -ne 0 ]; then
184 echo "--DIAG: [$assertion]
185 <$service_test:$instance_test1> is not online"
186 print_result $RESULT
187 exit $RESULT
188 fi
189
190 echo "--INFO: [${assertion}]
191 Now attempt to mark degraded "
192
193 #Enable the service using svcadm
194 /usr/sbin/svcadm mark degraded $service_test >/dev/null 2>&1
195 rc=$?
196 if [ $rc -ne 0 ]; then
197 RESULT=$(update_result $STF_FAIL $RESULT)
198 echo "--DIAG: [$assertion]
199 svcadm mark degraded $service_test should pass
200 EXPECTED: 0
201 RETURNED: $rc"
202 print_result $RESULT
203 exit $RESULT
204 fi
205
206 echo "--INFO: [${assertion}]
207 Assertion proved"
208
209 RESULT=$STF_PASS
210 print_result $RESULT
211 exit $RESULT