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 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 ###############################################################################
29 # start __stf_assertion__
30 #
31 # ASSERTION: svcadm_refresh_003
32 #
33 # DESCRIPTION:
34 # Calling 'svcadm refresh FMRI' where FMRI is a service instance that is
35 # in the disabled state will have no effect on the service.
36 # The exit status will be 0.
37 #
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 refresh 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 the common utility functions for tests in this directory
58 . ${STF_SUITE}/${STF_EXEC}/functions.kshlib
59
60 # Define the cleanup function for this test
61 function cleanup {
62 service_cleanup $refresh_test_service $svccfg_add_script
63 print_result $RESULT
64 }
65
66 # Define Variables
67 readonly assertion=svcadm_refresh_003
68 readonly ME=$(whence -p ${0})
69 readonly MYLOC=$(dirname ${ME})
70 readonly refresh_test_service="refresh_003$$"
71 readonly refresh_test_instance="refresh_003$$"
72 readonly refresh_test_fmri="svc:/$refresh_test_service:$refresh_test_instance"
73 readonly svccfg_add_script=/var/tmp/refresh_003$$.cfg
74
75 # Make sure we run as root
76 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
77 then
78 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
79 echo "--DIAG: [$assertion]
80 This test must be run from root."
81 exit $RESULT
82 fi
83
84 # Extract and print assertion 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 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 $refresh_test_service using svccfg"
111
112 cat > $svccfg_add_script <<EOF
113 add $refresh_test_service
114 select $refresh_test_service
115 add $refresh_test_instance
116 EOF
117
118 # Add objects to repository
119 echo "--INFO: [${assertion}]
120 Adding entities <$refresh_test_service> to repository using svccfg"
121
122 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
123 if [ $? -ne 0 ]; then
124 echo "--DIAG: [$assertion]
125 Adding entities using svccfg failed."
126 exit $RESULT
127 fi
128
129
130 echo "--INFO: [${assertion}]
131 Enable $refresh_test_fmri using svcadm enable"
132
133 svcadm enable $refresh_test_fmri >/dev/null 2>&1
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 echo "--DIAG: [$assertion]
137 svcadm enable $refresh_test_fmri failed
138 EXPECTED: ret = 0
139 OBSERVED: ret = $ret"
140 exit $RESULT
141 fi
142
143 # Wait until the start method has been executed
144 echo "--INFO: [${assertion}]
145 Wait for the start method to be triggered"
146
147 service_wait_state $refresh_test_fmri online
148 if [ $? -ne 0 ]; then
149 echo "--DIAG: [$assertion]
150 <$refresh_test_fmri> is not online"
151 exit $RESULT
152 fi
153
154 echo "--INFO: [${assertion}]
155 Disable $refresh_test_fmri"
156
157 svcadm disable $refresh_test_fmri >/dev/null 2>&1
158 ret=$?
159 if [ $ret -ne 0 ]; then
160 echo "--DIAG: [$assertion]
161 svcadm disable $refresh_test_fmri failed
162 EXPECTED: ret = 0
163 OBSERVED: ret = $ret"
164 exit $RESULT
165 fi
166
167 # Wait until state transition is complete
168 echo "--INFO: [${assertion}]
169 Wait until state transition is complete"
170
171 service_wait_state $refresh_test_fmri disabled
172 if [ $? -ne 0 ]; then
173 echo "--DIAG: [$assertion]
174 <$refresh_test_fmri> is not disabled"
175 exit $RESULT
176 fi
177
178 #
179 # VERIFY ASSERTION
180 #
181 echo "--INFO: [$assertion]
182 Invoke \"svcadm refresh $refresh_test_fmri\""
183 svcadm refresh $refresh_test_fmri >/dev/null 2>&1
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 RESULT=$(update_result $STF_FAIL $RESULT)
187 echo "--DIAG: [$assertion]
188 svcadm refresh $refresh_test_fmri failed
189 EXPECTED: ret = 0
190 OBSERVED: ret = $ret"
191 exit $RESULT
192 fi
193
194 echo "--INFO: [${assertion}]
195 Verify $refresh_test_fmri is still disabled"
196
197 state=`svcprop -p restarter/state $refresh_test_fmri 2>/dev/null`
198 ret=$?
199 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
200 RESULT=$(update_result $STF_FAIL $RESULT)
201 echo "--DIAG: [$assertion]
202 EXPECTED: svcprop ret = 0; STATE= disabled
203 OBSERVED: svcprop ret = $ret; STATE = $state"
204 exit $RESULT
205 fi
206
207 RESULT=$STF_PASS
208 print_result $RESULT
209 exit $RESULT
210
211 #
212 ### END
213 #