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 ###############################################################################
30 # start __stf_assertion__
31 #
32 # ASSERTION: svcadm_maintenance_002
33 #
34 # DESCRIPTION:
35 # Calling 'svcadm -v mark maintenance FMRI' where FMRI is a service
36 # instance that is in the disabled state should get STATE transit to
37 # maintenance state.
38 # STRATEGY:
39 # - Create a service instance configuration.
40 # - Enable it using svcadm enable
41 # - Disable the service instance using svcadm disable.
42 # - Call svcadm mark maintenance FMRI and make sure it exits 0.
43 # - Also verify it prints the message "Action maint_on set for
44 # $FMRI"
45 # - Verify state of "service instance" is unchanged from disable.
46 #
47 # COMMANDS: svcadm(1)
48 #
49 # end __stf_assertion__
50 ################################################################################
51
52 # First load up definitions of STF result variables like STF_PASS etc.
53 . ${STF_TOOLS}/include/stf.kshlib
54
55 # Load up definitions of shell functionality common to all smf sub-suites.
56 . ${STF_SUITE}/include/gltest.kshlib
57 . ${STF_SUITE}/include/svc.startd_config.kshlib
58
59 # Define the cleanup function for this test
60 function cleanup {
61 service_cleanup $test_service
62 /usr/bin/rm -f $svccfg_add_script
63 }
64
65 # Define Variables
66 readonly assertion=svcadm_maintenance_002
67 readonly ME=$(whence -p ${0})
68 readonly MYLOC=$(dirname ${ME})
69 readonly test_service="maintenance_002$$"
70 readonly test_instance="maintenance_002$$"
71 readonly test_fmri="svc:/$test_service:$test_instance"
72 readonly svccfg_add_script=/var/tmp/maintenance_002$$.cfg
73
74 # Make sure we run as root
75 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
76 then
77 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
78 echo "--DIAG: [$assertion]
79 This test must be run from root."
80 print_result $RESULT
81 exit $RESULT
82 fi
83
84 # Extract and print assertion information from this source script.
85 extract_assertion_info $ME
86
87 # Initialize test result to pass.
88 typeset -i RESULT=${STF_UNRESOLVED}
89
90 # Set a trap to execute the cleanup function
91 trap cleanup 0 1 2 15
92
93 # Exit code for individual commands.
94 typeset -i tmp_rc=0
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 test service $test_service using svccfg"
112
113 cat > $svccfg_add_script <<EOF
114 add $test_service
115 select $test_service
116 add $test_instance
117 EOF
118
119 #Add objects to repository
120
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 fails
141 EXPECTED: ret = 0
142 OBSERVED: ret = $ret"
143 print_result $RESULT
144 exit $RESULT
145 fi
146
147 # Wait until the service state is updated
148 target_state="online"
149
150 echo "--INFO: [${assertion}]
151 Wait until state transition to $target_state is completed"
152
153 service_wait_state $test_fmri $target_state
154 if [ $? -ne 0 ]; then
155 echo "--DIAG: [$assertion]
156 EXPECTED: <$test_fmri>: $target_state
157 OBSERVED: <$test_fmri>: `svcprop -p restarter/state $test_fmri`"
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 the service STATE gets updated
178
179 target_state="disabled"
180
181 echo "--INFO: [${assertion}]
182 Wait until transition to state $target_state is completed"
183
184 service_wait_state $test_fmri $target_state
185 if [ $? -ne 0 ]; then
186 echo "--DIAG: [$assertion]
187 EXPECTED: <$test_fmri>: $target_state
188 OBSERVED: <$test_fmri>: `svcprop -p restarter/state $test_fmri`"
189 print_result $RESULT
190 exit $RESULT
191 fi
192
193 #
194 # VERIFY ASSERTION
195 #
196 output=`svcadm -v mark maintenance $test_fmri 2>/dev/null`
197 ret=$?
198 if [[ "$output" != "Action maint_on set for $test_fmri." || $ret -ne 0 ]]; then
199 RESULT=$(update_result $STF_FAIL $RESULT)
200 echo "--DIAG: [$assertion]
201 svcadm mark maintenance $test_fmri fails
202 EXPECTED: ret = 0
203 OBSERVED: ret = $ret"
204 print_result $RESULT
205 exit $RESULT
206 fi
207
208 echo "--INFO: [${assertion}]
209 output = $output"
210
211
212 echo "--INFO: [${assertion}]
213 Verify that state = maintenance"
214
215 state=`svcprop -p restarter/state $test_fmri 2>/dev/null`
216 ret=$?
217 if [[ $ret -ne 0 || "$state" != "maintenance" ]]; then
218 RESULT=$(update_result $STF_FAIL $RESULT)
219 echo "--DIAG: [$assertion]
220 EXPECTED: ret = 0; STATE= maintenance
221 OBSERVED: ret = $ret; STATE = $state"
222 print_result $RESULT
223 exit $RESULT
224 fi
225
226 RESULT=$STF_PASS
227 print_result $RESULT
228 exit $RESULT
229
230 #
231 ### END
232 #