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_enable_009
40 #
41 # DESCRIPTION:
42 # Calling 'svcadm enable <service>' which doesn't have any instance
43 # should fail with exit 1.
44 # STRATEGY:
45 # - Check for test setup.
46 # - Configure a service 'foo$$' without instance(s) using svccfg
47 # - Enable it using svcadm enable service
48 # - Make sure svcadm enable fails, with exit 1.
49 #
50 # COMMANDS: svcadm(1)
51 #
52 # end __stf_assertion__
53 ################################################################################
54
55 # First load up definitions of STF result variables like STF_PASS etc.
56 . ${STF_TOOLS}/include/stf.kshlib
57
58 # Load up definitions of shell functionality common to all smf sub-suites.
59 . ${STF_SUITE}/include/gltest.kshlib
60
61 # Define Variables
62 readonly assertion=svcadm_enable_009
63 readonly svccfg_add_script=/var/tmp/svcadm_enable_009.$$.config
64 readonly service_test=foo$$
65 readonly ME=$(whence -p ${0})
66 readonly MYLOC=$(dirname ${ME})
67
68 # gltest.kshlib functions to extract and print assertion information
69 # from this source script.
70 extract_assertion_info $ME
71
72 # Initialize test result to pass.
73 typeset -i RESULT=${STF_UNRESOLVED}
74
75 # Set a trap to execute the cleanup function when specified signals
76 # are received.
77 trap cleanup 0 1 2 15
78
79 # Exit code for individual commands.
80 typeset -i tmp_rc=0
81
82 # Make sure we run as root
83 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
84 then
85 echo "--DIAG: [$assertion]
86 This test must be run from root."
87 print_result $RESULT
88 exit $RESULT
89 fi
90
91
92 # Execute environmental sanity checks.
93 check_gl_env
94 tmp_rc=$?
95 if [[ $tmp_rc -ne 0 ]]
96 then
97 echo "--DIAG: [$assertion]
98 Invalid smf environment, quitting."
99 print_result $RESULT
100 exit $RESULT
101 fi
102
103 # Create the svccfg add script which will add entities to the
104 # repository for this test case.
105
106 echo "--INFO: [${assertion}]
107 configure $service_test using svccfg"
108
109 cat > $svccfg_add_script <<EOF
110 add $service_test
111 EOF
112
113 #Add objects to repository
114
115 echo "--INFO: [${assertion}]
116 Adding entities <$service_test> to repository using svccfg"
117
118 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
119 if [ $? -ne 0 ]; then
120 echo "--DIAG: [$assertion]
121 Adding entities using svccfg failed."
122 print_result $RESULT
123 exit $RESULT
124 fi
125
126 echo "--INFO: [${assertion}]
127 enable <$service_test> using svcadm"
128
129 #Enable the service using svcadm
130 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
131 ret=$?
132 if [ $ret -ne 1 ]; then
133 RESULT=$(update_result $STF_FAIL $RESULT)
134 echo "--DIAG: [$assertion]
135 svcadm enable $service_test(without any instance) should fail
136 EXPECTED : ret = 1
137 ACTUAL : ret = $ret"
138 print_result $RESULT
139 exit $RESULT
140 fi
141
142 /usr/bin/svcs $service_test | grep online >/dev/null 2>&1
143 ret=$?
144 if [ $ret -eq 0 ]; then
145 RESULT=$(update_result $STF_FAIL $RESULT)
146 echo "--DIAG: [$assertion]
147 svcs $service_test | grep online should fail
148 EXPECTED : ret = 1
149 ACTUAL : ret = $ret"
150 print_result $RESULT
151 exit $RESULT
152 fi
153
154 echo "--INFO: [${assertion}]
155 Assertion proved"
156
157 RESULT=$STF_PASS
158 print_result $RESULT
159 exit $RESULT