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_clear_002
40 #
41 # DESCRIPTION:
42 # svcadm -v <clear> FMRI, where FMRI is a service instance which
43 # is currently in online STATE should fail with exit 1
44 #
45 # STRATEGY:
46 # - Check for test setup.
47 # - Configure a service 'foo$$' using svccfg
48 # - Enable it using svcadm
49 # - Call svcadm -v <clear> <FMRI>
50 # - Verify that above step fails with exit 1
51 # - Also make sure STATE doesn't change from online.
52 #
53 # COMMANDS: svcadm(1)
54 #
55 # end __stf_assertion__
56 ################################################################################
57
58 # First load up definitions of STF result variables like STF_PASS etc.
59 . ${STF_TOOLS}/include/stf.kshlib
60
61 # Load up definitions of shell functionality common to all smf sub-suites.
62 . ${STF_SUITE}/include/gltest.kshlib
63
64 # Define Variables
65 readonly assertion=svcadm_clear_002
66 readonly svccfg_add_script=/var/tmp/svcadm_clear_002.$$.config
67 readonly service_test=foo$$
68 readonly instance_test=instance$$
69 readonly fmri="svc:/$service_test:$instance_test"
70 readonly ME=$(whence -p ${0})
71 readonly MYLOC=$(dirname ${ME})
72
73 # gltest.kshlib functions to extract and print assertion information
74 # from this source script.
75 extract_assertion_info $ME
76
77 # Initialize test result to pass.
78 typeset -i RESULT=${STF_UNRESOLVED}
79
80 # Set a trap to execute the cleanup function when specified signals
81 # are received.
82 trap cleanup 0 1 2 15
83
84 # Exit code for individual commands.
85 typeset -i tmp_rc=0
86
87 # Make sure we run as root
88 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
89 then
90 echo "--DIAG: [$assertion]
91 This test must be run from root."
92 print_result $RESULT
93 exit $RESULT
94 fi
95
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 $service_test using svccfg"
113
114 cat > $svccfg_add_script <<EOF
115 add $service_test
116 select $service_test
117 add $instance_test
118 EOF
119
120 # Add objects to repository
121
122 echo "--INFO: [${assertion}]
123 Adding entities <$service_test> to repository using svccfg"
124
125 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
126 if [ $? -ne 0 ]; then
127 echo "--DIAG: [$assertion]
128 Adding entities using svccfg failed."
129 print_result $RESULT
130 exit $RESULT
131 fi
132
133 echo "--INFO: [${assertion}]
134 enable <$service_test> using svcadm"
135
136 # Enable the service using svcadm
137 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
138 if [ $? -ne 0 ]; then
139 echo "--DIAG: [$assertion]
140 svcadm enable $service_test failed."
141 print_result $RESULT
142 exit $RESULT
143 fi
144
145 # Wait until state transition is complete
146
147 echo "--INFO: [${assertion}]
148 Wait until state transition gets completed"
149
150 service_wait_state $service_test:$instance_test online
151 if [ $? -ne 0 ]; then
152 echo "--DIAG: [$assertion]
153 <$service_test> is not online"
154 print_result $RESULT
155 exit $RESULT
156 fi
157
158 echo "--INFO: [${assertion}]
159 Verify that state = online"
160
161 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
162 ret=$?
163 if [[ $ret -ne 0 || "$state" != "online" ]]; then
164 RESULT=$(update_result $STF_FAIL $RESULT)
165 echo "--DIAG: [$assertion]
166 EXPECTED: ret = 0; STATE= online
167 ACTUAL: ret = $ret; STATE = $state"
168 print_result $RESULT
169 exit $RESULT
170 fi
171
172 echo "--INFO: [${assertion}]
173 Clear <$fmri> using svcadm"
174
175 # Invoke clear on the service
176 /usr/sbin/svcadm -v clear $fmri >/dev/null 2>&1
177 if [ $? -ne 1 ]; then
178 echo "--DIAG: [$assertion]
179 svcadm -v clear $service_test should fail with exit 1"
180 print_result $RESULT
181 exit $RESULT
182 fi
183
184 echo "--INFO: [${assertion}]
185 Verify that state is unchanged from online"
186
187 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
188 ret=$?
189 if [[ $ret -ne 0 || "$state" != "online" ]]; then
190 RESULT=$(update_result $STF_FAIL $RESULT)
191 echo "--DIAG: [$assertion]
192 EXPECTED: ret = 0; STATE= online
193 ACTUAL: ret = $ret; STATE = $state"
194 print_result $RESULT
195 exit $RESULT
196 fi
197
198
199 echo "--INFO: [${assertion}]
200 Assertion proved"
201 RESULT=$STF_PASS
202 print_result $RESULT
203 exit $RESULT