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