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_test1
33 service_cleanup $service_test2
34 /usr/bin/rm -f $svccfg_add_script1
35 /usr/bin/rm -f $svccfg_add_script2
36 }
37
38 ###############################################################################
39 # start __stf_assertion__
40 #
41 # ASSERTION: svcadm_enable_012
42 #
43 # DESCRIPTION:
44 # svcadm enable <FMRI list> should succeed
45 # STRATEGY:
46 # - Check for test setup.
47 # - Configure a service 'foo$$1' using svccfg
48 # - configure another service foo$$2 using svccfg
49 # - Enable them using svcadm
50 # - Make sure their state is online
51 # - svcadm enable <fmrilist> and make sure it exits 0.
52 # - Make sure state is online.
53 #
54 # COMMANDS: svcadm(1)
55 #
56 # end __stf_assertion__
57 ################################################################################
58
59 # First load up definitions of STF result variables like STF_PASS etc.
60 . ${STF_TOOLS}/include/stf.kshlib
61
62 # Load up definitions of shell functionality common to all smf sub-suites.
63 . ${STF_SUITE}/include/gltest.kshlib
64
65 # Define Variables
66 readonly assertion=svcadm_enable_012
67 readonly svccfg_add_script1=/var/tmp/svcadm_enable_012.$$.config1
68 readonly svccfg_add_script2=/var/tmp/svcadm_enable_012.$$.config2
69 readonly service_test1=foo$$1
70 readonly service_test2=foo$$2
71 readonly instance_test=instance$$
72 readonly fmri1=svc:/$service_test1:$instance_test
73 readonly fmri2=svc:/$service_test2:$instance_test
74 readonly ME=$(whence -p ${0})
75 readonly MYLOC=$(dirname ${ME})
76
77 # gltest.kshlib functions to extract and print assertion information
78 # from this source script.
79 extract_assertion_info $ME
80
81 # Initialize test result to pass.
82 typeset -i RESULT=${STF_UNRESOLVED}
83
84 # Set a trap to execute the cleanup function when specified signals
85 # are received.
86 trap cleanup 0 1 2 15
87
88 # Exit code for individual commands.
89 typeset -i tmp_rc=0
90
91 # Make sure we run as root
92 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
93 then
94 echo "--DIAG: [$assertion]
95 This test must be run from root."
96 print_result $RESULT
97 exit $RESULT
98 fi
99
100
101 # Execute environmental sanity checks.
102 check_gl_env
103 tmp_rc=$?
104 if [[ $tmp_rc -ne 0 ]]
105 then
106 echo "--DIAG: [$assertion]
107 Invalid smf environment, quitting."
108 print_result $RESULT
109 exit $RESULT
110 fi
111
112 # Create the svccfg add script which will add entities to the
113 # repository for this test case.
114
115 echo "--INFO: [${assertion}]
116 configure $service_test1 using svccfg"
117
118 cat > $svccfg_add_script1 <<EOF
119 add $service_test1
120 select $service_test1
121 add $instance_test
122 EOF
123
124 echo "--INFO: [${assertion}]
125 configure $service_test2 using svccfg"
126
127 cat > $svccfg_add_script2 <<EOF
128 add $service_test2
129 select $service_test2
130 add $instance_test
131 EOF
132
133 #Add objects to repository
134
135 echo "--INFO: [${assertion}]
136 Adding entities <$service_test1> to repository using svccfg"
137
138 /usr/sbin/svccfg -f $svccfg_add_script1 >/dev/null 2>&1
139 if [ $? -ne 0 ]; then
140 echo "--DIAG: [$assertion]
141 Adding entities using svccfg failed."
142 print_result $RESULT
143 exit $RESULT
144 fi
145 #Add objects to repository
146
147 echo "--INFO: [${assertion}]
148 Adding entities <$service_test2> to repository using svccfg"
149
150 /usr/sbin/svccfg -f $svccfg_add_script2 >/dev/null 2>&1
151 if [ $? -ne 0 ]; then
152 echo "--DIAG: [$assertion]
153 Adding entities using svccfg failed."
154 print_result $RESULT
155 fi
156
157 echo "--INFO: [${assertion}]
158 enable services using svcadm enable fmrilist"
159
160 #Enable the service using svcadm enable <fmrilist>?
161 /usr/sbin/svcadm enable $fmri1 $fmri2 >/dev/null 2>&1
162 if [ $? -ne 0 ]; then
163 RESULT=$(update_result $STF_FAIL $RESULT)
164 echo "--DIAG: [$assertion]
165 svcadm enable $fmri1 $fmri2 should succeed with return 0"
166 print_result $RESULT
167 exit $RESULT
168 fi
169
170 #Wait just for sometime, let the service STATE gets updated
171
172 echo "--INFO: [${assertion}]
173 Wait until state transition gets completed"
174
175 service_wait_state $fmri1 online
176 if [ $? -ne 0 ]; then
177 RESULT=$(update_result $STF_FAIL $RESULT)
178 echo "--DIAG: [$assertion]
179 <$fmri1> is not online"
180 print_result $RESULT
181 exit $RESULT
182 fi
183
184 service_wait_state $fmri2 online
185 if [ $? -ne 0 ]; then
186 RESULT=$(update_result $STF_FAIL $RESULT)
187 echo "--DIAG: [$assertion]
188 <$fmri2> is not online"
189 print_result $RESULT
190 exit $RESULT
191 fi
192
193 echo "--INFO: [${assertion}]
194 Assertion proved"
195
196
197 RESULT=$STF_PASS
198 print_result $RESULT
199 exit $RESULT