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_011
33 #
34 # DESCRIPTION:
35 # Calling 'svcadm restart <service>, where service
36 # has multiple instances should pass and exit 0.
37 # STRATEGY:
38 # - Check for test setup.
39 # - Configure a service 'foo$$' using svccfg
40 # - Attempt to put multiple instances to the service.
41 # - Now attempt to put them in restart mode.
42 # - Make sure svcadm for restart <service> passes with
43 # exit 0.
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
56 # Load up common functions for tests in this directory
57 . ${STF_SUITE}/tests/svcadm/restart/functions.kshlib
58
59 # Define the test's cleanup function
60 function cleanup {
61 cleanup_leftovers $test_service $svccfg_add_script
62 }
63
64 # Define Variables
65 readonly assertion=svcadm_restart_011
66 readonly svccfg_add_script=/var/tmp/svcadm_restart_011.$$.config
67 readonly test_service="smftest_svcadm"
68 readonly test_instance1="${assertion}_1"
69 readonly test_instance2="${assertion}_2"
70 readonly ME=$(whence -p ${0})
71 readonly MYLOC=$(dirname ${ME})
72
73 # Extract and print assertion information 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 print_result $RESULT
92 exit $RESULT
93 fi
94
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
108 typeset -i rc=$?
109
110 # Create the svccfg add script which will add entities to the
111 # repository for this test case.
112
113 echo "--INFO: [${assertion}]
114 configure $test_service using svccfg"
115
116 cat > $svccfg_add_script <<EOF
117 add $test_service
118 select $test_service
119 add $test_instance1
120 add $test_instance2
121 EOF
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 rc=$?
130 if [ $rc -ne 0 ]; then
131 echo "--DIAG: [$assertion]
132 Adding entities using svccfg failed.
133 EXPECTED: svccfg exit status 0
134 RETURNED: svccfg exit status $rc"
135 print_result $RESULT
136 exit $RESULT
137 fi
138
139 echo "--INFO: [${assertion}]
140 enable <$test_service:$test_instance1> using svcadm"
141
142 #Enable the service using svcadm
143 /usr/sbin/svcadm enable $test_service:$test_instance1 >/dev/null 2>&1
144 rc=$?
145 if [ $rc -ne 0 ]; then
146 echo "--DIAG: [$assertion]
147 svcadm enable $test_service:$test_instance1 failed.
148 EXPECTED: exit 0
149 RETURNED: exit $rc"
150 print_result $RESULT
151 exit $RESULT
152 fi
153
154 echo "--INFO: [${assertion}]
155 enable <$test_service:$test_instance2> using svcadm"
156
157 #Enable the service using svcadm
158 /usr/sbin/svcadm enable $test_service:$test_instance2 >/dev/null 2>&1
159 rc=$?
160 if [ $rc -ne 0 ]; then
161 echo "--DIAG: [$assertion]
162 svcadm enable $test_service:$test_instance2 failed.
163 EXPECTED: exit 0
164 RETURNED: exit $rc"
165 print_result $RESULT
166 exit $RESULT
167 fi
168
169 #Wait just for sometime, let the service STATE gets updated
170
171 echo "--INFO: [${assertion}]
172 Wait for sometime to state transition gets completed"
173
174 service_wait_state $test_service:$test_instance1 online
175 rc=$?
176 if [ $rc -ne 0 ]; then
177 echo "--DIAG: [$assertion]
178 <$test_service:$test_instance1> is not online"
179 print_result $RESULT
180 exit $RESULT
181 fi
182
183 service_wait_state $test_service:$test_instance2 online
184 rc=$?
185 if [ $rc -ne 0 ]; then
186 echo "--DIAG: [$assertion]
187 <$test_service:$test_instance2> is not online"
188 print_result $RESULT
189 exit $RESULT
190 fi
191
192 echo "--INFO: [${assertion}]
193 Now attempt to restart "
194
195 # Enable the service using svcadm
196 /usr/sbin/svcadm restart $test_service >/dev/null 2>&1
197 rc=$?
198 if [ $rc -ne 0 ]; then
199 RESULT=$(update_result $STF_FAIL $RESULT)
200 echo "--DIAG: [$assertion]
201 svcadm restart $test_service should pass
202 EXPECTED: exit 0
203 RETURNED: exit $rc"
204 print_result $RESULT
205 exit $RESULT
206 fi
207
208 echo "--INFO: [${assertion}]
209 Assertion proved"
210
211 RESULT=$STF_PASS
212 print_result $RESULT
213 exit $RESULT
214
215 #
216 ### END
217 #