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: depends_031
32 # DESCRIPTION:
33 # If a service, service_A, has a dependency on another which has a
34 # dependency on another service and so on and one of the service has a
35 # dependency on service_A then the last service registered will go to
36 # the maintenance state while all other services will reach the offline
37 # state.
38 # (multi-link circular dependency)
39 #
40 # end __stf_assertion__
41 #
42
43 . ${STF_TOOLS}/include/stf.kshlib
44 . ${STF_SUITE}/include/gltest.kshlib
45 . ${STF_SUITE}/include/svc.startd_config.kshlib
46 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
47
48 typeset service_setup=0
49 function cleanup {
50 common_cleanup
51 rm -f $service_state1 $service_state2 $service_state3 $service_state4
52 }
53
54 trap cleanup 0 1 2 15
55
56 readonly ME=$(whence -p ${0})
57 readonly MYLOC=$(dirname ${ME})
58
59 DATA=$MYLOC
60
61 readonly registration_template=$DATA/service_031.xml
62
63 extract_assertion_info $ME
64
65 # make sure that the svc.startd is running
66 verify_daemon
67 if [ $? -ne 0 ]; then
68 print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
69 print -- " continue"
70 exit $STF_UNRESOLVED
71 fi
72
73 # Make sure the environment is clean - the test service isn't running
74 print -- "--INFO: Cleanup any old $test_FMRI1, $test_FMRI2, "
75 print -- " $test_FMRI3 and $test_FMRI4 state"
76 service_cleanup $test_service
77 if [ $? -ne 0 ]; then
78 print -- "--DIAG: $assertion: cleanup of a previous instance failed"
79 exit $STF_UNRESOLVED
80 fi
81
82 print -- "--INFO: generating manifest for importation into repository"
83 manifest_generate $registration_template \
84 TEST_SERVICE=$test_service \
85 TEST_INSTANCE1=$test_instance1 \
86 TEST_INSTANCE2=$test_instance2 \
87 TEST_INSTANCE3=$test_instance3 \
88 TEST_INSTANCE4=$test_instance4 \
89 SERVICE_APP=$service_app \
90 LOGFILE=$service_log \
91 STATEFILE1=$service_state1 \
92 STATEFILE2=$service_state2 \
93 STATEFILE3=$service_state3 \
94 STATEFILE4=$service_state4 \
95 > $registration_file
96
97 print -- "--INFO: Importing service into repository"
98 manifest_purgemd5 $registration_file
99 svccfg -v import $registration_file >$svccfg_errfile 2>&1
100
101 if [ $? -ne 0 ]; then
102 print -- "--DIAG: $assertion: Unable to import the services under"
103 print -- " svc:/$test_service error messages from svccfg: "
104 print -- " \"$(cat $svccfg_errfile)\""
105 exit $STF_UNRESOLVED
106 fi
107 service_setup=1
108
109
110 # one of the services wil reach maintenance, all the others will be offline
111 inmaint=0
112 inoffline=0
113
114 print -- "--INFO: check for $test_FMRI4 to go offline"
115 service_wait_state $test_FMRI4 offline
116 if [ $? -ne 0 ]; then
117 state=$(svcs -H -o STATE $test_FMRI4)
118 if [ "$state" != maintenance ]; then
119 print -- "--DIAG: $assertion: Service $test_FMRI4 didn't go to "
120 print -- " maintenance. It is in \"$state\" state."
121 exit $STF_FAIL
122 else
123 inmaint=$((inmaint + 1))
124 fi
125 else
126 inoffline=$((inoffline + 1))
127 fi
128
129 print -- "--INFO: Verifying that $test_FMRI1 is in the offline state"
130 service_wait_state $test_FMRI1 offline
131 if [ $? -ne 0 ]; then
132 state=$(svcs -H -o STATE $test_FMRI1)
133 if [ "$state" != maintenance ]; then
134 print -- "--DIAG: $assertion: Service $test_FMRI1 did not go to the"
135 print -- " maintenance state. It is in the \"$state\" state."
136 exit $STF_FAIL
137 else
138 inmaint=$((inmaint + 1))
139 fi
140 else
141 inoffline=$((inoffline + 1))
142 fi
143
144 print -- "--INFO: Verifying that $test_FMRI2 is in the offline state"
145 service_wait_state $test_FMRI2 offline
146 if [ $? -ne 0 ]; then
147 state=$(svcs -H -o STATE $test_FMRI2)
148 if [ "$state" != maintenance ]; then
149 print -- "--DIAG: $assertion: Service $test_FMRI2 did not go to the"
150 print -- " maintenance state. It is in the \"$state\" state."
151 exit $STF_FAIL
152 else
153 inmaint=$((inmaint + 1))
154 fi
155 else
156 inoffline=$((inoffline + 1))
157 fi
158
159 print -- "--INFO: Verifying that $test_FMRI3 is in the offline state"
160 service_wait_state $test_FMRI3 offline
161 if [ $? -ne 0 ]; then
162 state=$(svcs -H -o STATE $test_FMRI3)
163 if [ "$state" != maintenance ]; then
164 print -- "--DIAG: $assertion: Service $test_FMRI3 did not go to the"
165 print -- " maintenance state. It is in the \"$state\" state."
166 exit $STF_FAIL
167 else
168 inmaint=$((inmaint + 1))
169 fi
170 else
171 inoffline=$((inoffline + 1))
172 fi
173
174 if [ $inoffline -ne 3 -o $inmaint -ne 1 ]; then
175 print -- "--DIAG: $assertion: $inoffline services are in the offline state"
176 print -- " and $inmaint services are in the maintenance state. This should"
177 print -- " be 3 offline, and 1 in maintenance."
178 svcs -l $test_service
179 exit $STF_FAIL
180
181 fi
182
183 print -- "--INFO: Cleaning up service"
184 cleanup
185
186 exit $STF_PASS