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_enable_002
32 #
33 # DESCRIPTION:
34 # Calling 'svcadm -v enable <service>' where service is a service
35 # instance that is already in the enabled state will have no effect.
36 # A message will be sent to stdout. The exit status will be 0 (zero).
37 #
38 # STRATEGY:
39 # - Configure a service 'foo$$' using svccfg with a single instance
40 # - Enable the instance using 'svcadm enable <service>'
41 # - Verify that the instance state is online.
42 # - Invoke 'svcadm -v enable <instance>' to enable the instance again.
43 # - Verify that the exit status is 0 (zero) and that the verbose output
44 # message is as expected.
45 # - Disable the service and exit the test.
46 #
47 # COMMANDS: svcadm(1)
48 #
49 # end __stf_assertion__
50 ################################################################################
51
52 # First load up definitions of STF result variables like STF_PASS etc.
53 . ${STF_TOOLS}/include/stf.kshlib
54
55 # Load up definitions of shell functionality common to all smf sub-suites.
56 . ${STF_SUITE}/include/gltest.kshlib
57
58 # Define the cleanup function for this test
59 function cleanup {
60 service_cleanup $service_test
61 /usr/bin/rm -f $svccfg_add_script
62 print_result $RESULT
63 }
64
65 # Define Variables
66 readonly assertion=svcadm_enable_002
67 readonly svccfg_add_script=/var/tmp/svcadm_enable_002.$$.config
68 readonly service_test=foo$$
69 readonly instance_test=instance$$
70 readonly target_fmri="svc:/$service_test:$instance_test"
71 readonly ME=$(whence -p ${0})
72 readonly MYLOC=$(dirname ${ME})
73
74 # Extract and print assertion from this source file.
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
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 print_result $RESULT
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 $service_test using svccfg"
111
112 cat > $svccfg_add_script <<EOF
113 add $service_test
114 select $service_test
115 add $instance_test
116 EOF
117
118 # Add objects to repository
119 echo "--INFO: [${assertion}]
120 Add entities to repository using svccfg
121 <$service_test>
122 <$service_test:$instance_test>"
123
124 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
125 if [ $? -ne 0 ]; then
126 echo "--DIAG: [$assertion]
127 Adding entities using svccfg failed."
128 print_result $RESULT
129 exit $RESULT
130 fi
131
132 echo "--INFO: [${assertion}]
133 enable <$service_test> using svcadm"
134
135 # Enable the service using svcadm
136 svcadm enable $service_test >/dev/null 2>&1
137 if [ $? -ne 0 ]; then
138 echo "--DIAG: [$assertion]
139 svcadm enable $service_test failed."
140 print_result $RESULT
141 exit $RESULT
142 fi
143
144 # Wait until the service state transition is complete
145
146 echo "--INFO: [${assertion}]
147 Wait until state transition gets completed"
148
149 service_wait_state $target_fmri online
150 if [ $? -ne 0 ]; then
151 echo "--DIAG: [$assertion]
152 <$target_fmri> is not online"
153 print_result $RESULT
154 exit $RESULT
155 fi
156
157 echo "--INFO: [${assertion}]
158 Again enable $service_test using svcadm -v enable and verify output"
159
160 # Enable the service using svcadm using -v option and verify the output message.
161 output=`/usr/sbin/svcadm -v enable $service_test 2>/dev/null`
162 ret=$?
163 exp_out="$target_fmri enabled."
164 if [[ $ret -ne 0 || "$output" != "$exp_out" ]]; then
165 RESULT=$(update_result $STF_FAIL $RESULT)
166 echo "--DIAG: [$assertion]
167 svcadm -v enable $service_test failed.
168 EXPECTED: ret = 0; output = $exp_out
169 OBSERVED: ret = $ret; output = $output"
170 exit $RESULT
171 fi
172
173 echo "--INFO: [${assertion}]
174 Verify that state is unchanged from 'online'"
175
176 state=`svcprop -p restarter/state $target_fmri 2>/dev/null`
177 ret=$?
178 if [[ $ret -ne 0 || "$state" != "online" ]]; then
179 RESULT=$(update_result $STF_FAIL $RESULT)
180 echo "--DIAG: [$assertion]
181 EXPECTED: ret = 0; STATE= online
182 OBSERVED: ret = $ret; STATE = $state"
183 exit $RESULT
184 fi
185
186 RESULT=$STF_PASS
187 print_result $RESULT
188 exit $RESULT
189
190 #
191 ### END
192 #