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_007
32 #
33 # DESCRIPTION:
34 # Calling 'svcadm refresh <service>, where service
35 # has multiple instances should pass and exit 0.
36 # STRATEGY:
37 # - Check for test setup.
38 # - Configure a service 'foo$$' using svccfg
39 # - Attempt to put multiple instances to the service.
40 # - Now attempt to put them in refresh mode.
41 # - Make sure svcadm for refresh <service> passes with
42 # exit 0.
43 #
44 # COMMANDS: svcadm(1)
45 #
46 # end __stf_assertion__
47 ################################################################################
48
49 # First load up definitions of STF result variables like STF_PASS etc.
50 . ${STF_TOOLS}/include/stf.kshlib
51
52 # Load up definitions of shell functionality common to all smf sub-suites.
53 . ${STF_SUITE}/include/gltest.kshlib
54
55 # Load up the functions for the tests in this directory
56 . ${STF_SUITE}/${STF_EXEC}/functions.kshlib
57
58 # Define the cleanup function for this test
59 function cleanup {
60 cleanup_leftovers $service_test $svccfg_add_script
61 print_result $RESULT
62 }
63
64 # Define Variables
65 readonly assertion=svcadm_refresh_007
66 readonly svccfg_add_script=/var/tmp/svcadm_refresh_007.$$.config
67 readonly service_test=foo$$
68 readonly instance_test=instance$$
69 readonly instance_test1=instance1$$
70 readonly ME=$(whence -p ${0})
71 readonly MYLOC=$(dirname ${ME})
72
73 # Extract and print the assertion 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 exit $RESULT
92 fi
93
94
95 # Execute environmental sanity checks.
96 check_gl_env
97 tmp_rc=$?
98 if [[ $tmp_rc -ne 0 ]]
99 then
100 echo "--DIAG: [$assertion]
101 Invalid smf environment, quitting."
102 exit $RESULT
103 fi
104
105 # Local 'return code' variable
106 typeset -i rc=0
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 add $instance_test1
119 EOF
120
121 #Add objects to repository
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 exit status 0
132 RETURNED: svccfg exit status $rc"
133 exit $RESULT
134 fi
135
136 echo "--INFO: [${assertion}]
137 enable <$service_test:$instance_test> using svcadm"
138
139 #Enable the service using svcadm
140 /usr/sbin/svcadm enable $service_test:$instance_test >/dev/null 2>&1
141 rc=$?
142 if [ $rc -ne 0 ]; then
143 echo "--DIAG: [$assertion]
144 svcadm enable $service_test:$instance_test failed.
145 EXPECTED: exit 0
146 RETURNED: exit $rc"
147 exit $RESULT
148 fi
149
150 echo "--INFO: [${assertion}]
151 enable <$service_test:$instance_test1> using svcadm"
152
153 #Enable the service using svcadm
154 /usr/sbin/svcadm enable $service_test:$instance_test1 >/dev/null 2>&1
155 rc=$?
156 if [ $rc -ne 0 ]; then
157 echo "--DIAG: [$assertion]
158 svcadm enable $service_test:$instance_test1 failed.
159 EXPECTED: exit 0
160 RETURNED: exit $rc"
161 exit $RESULT
162 fi
163
164 #Wait just for sometime, let the service STATE gets updated
165
166 echo "--INFO: [${assertion}]
167 Wait for sometime to state transition gets completed"
168
169 service_wait_state $service_test:$instance_test online
170 rc=$?
171 if [ $rc -ne 0 ]; then
172 echo "--DIAG: [$assertion]
173 <$service_test:$instance_test> is not online"
174 exit $RESULT
175 fi
176
177 service_wait_state $service_test:$instance_test1 online
178 rc=$?
179 if [ $rc -ne 0 ]; then
180 echo "--DIAG: [$assertion]
181 <$service_test:$instance_test1> is not online"
182 exit $RESULT
183 fi
184
185 echo "--INFO: [${assertion}]
186 Now attempt to refresh "
187
188 #Enable the service using svcadm
189 /usr/sbin/svcadm refresh $service_test >/dev/null 2>&1
190 rc=$?
191 if [ $rc -ne 0 ]; then
192 RESULT=$(update_result $STF_FAIL $RESULT)
193 echo "--DIAG: [$assertion]
194 svcadm refresh $service_test should pass
195 EXPECTED: exit 0
196 RETURNED: exit $rc"
197 exit $RESULT
198 fi
199
200 echo "--INFO: [${assertion}]
201 Assertion proved"
202
203 RESULT=$STF_PASS
204 print_result $RESULT
205 exit $RESULT
206
207 #
208 ### END
209 #