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: methods_010
32 # DESCRIPTION:
33 # Upon starting a service the svc.startd invokes the service's start
34 # method.
35 # Should the method returns a non-zero exit code other than the
36 # defined straight to maintenance exit code it is considered to have
37 # failed, but not irrevocably.
38 # The svc.startd will re-attempt to start the service until the
39 # error threshold is reached at which point the service is
40 # transitioned to the maintenance state.
41 #
42 # end __stf_assertion__
43 #
44
45 . ${STF_TOOLS}/include/stf.kshlib
46 . ${STF_SUITE}/include/gltest.kshlib
47 . ${STF_SUITE}/include/svc.startd_config.kshlib
48 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
49
50 typeset service_setup=0
51 function cleanup {
52 common_cleanup
53 return $?
54 }
55
56 trap cleanup 0 1 2 15
57
58 readonly ME=$(whence -p ${0})
59 readonly MYLOC=$(dirname ${ME})
60
61 DATA=$MYLOC
62
63 registration_template=$DATA/service_010.xml
64
65 extract_assertion_info $ME
66
67 # make sure that the svc.startd is running
68 verify_daemon
69 if [ $? -ne 0 ]; then
70 print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
71 print -- " continue"
72 exit $STF_UNRESOLVED
73 fi
74
75 # Make sure the environment is clean - the test service isn't running
76 print -- "--INFO: Cleanup any old $test_FMRI state"
77 service_cleanup $test_service
78 rm -f $service_state
79 if [ $? -ne 0 ]; then
80 print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
81 exit $STF_UNRESOLVED
82 fi
83
84 print -- "--INFO: generating manifest for importation into repository"
85 manifest_generate $registration_template \
86 TEST_SERVICE=$test_service \
87 TEST_INSTANCE=$test_instance \
88 SERVICE_APP=$service_app \
89 LOGFILE=$service_log \
90 STATEFILE=$service_state \
91 START_EVENT="returncode $SVC_METHOD_OTHEREXIT" \
92 > $registration_file
93
94 print -- "--INFO: Importing service into repository"
95 manifest_purgemd5 $registration_file
96 svccfg -v import $registration_file >$svccfg_errfile 2>&1
97 if [ $? -ne 0 ]; then
98 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
99 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
100 exit $STF_UNRESOLVED
101 fi
102 service_setup=1
103
104 print -- "--INFO: enabling $test_FMRI"
105 svcadm enable $test_FMRI
106 if [ $? -ne 0 ]; then
107 print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
108 exit $STF_FAIL
109 fi
110
111 print -- "--INFO: waiting for execution of start method"
112 service_wait_method $test_FMRI start
113 if [ $? -ne 0 ]; then
114 print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
115 exit $STF_UNRESOLVED
116 fi
117
118 print -- "--INFO: Validating service is in maintenance mode"
119 service_wait_state $test_FMRI maintenance
120 if [ $? -ne 0 ]; then
121 print -- "--DIAG: $assertion: Service $test_FMRI did not "
122 print -- " transition to maintenance mode"
123 exit $STF_FAIL
124 fi
125
126 print -- "--INFO: Validating multiple invocations of start method"
127 service_countcall -f $service_state -s $test_service -i $test_instance start
128 countstarts=$?
129 if [ $countstarts -lt $ERROR_THRESHOLD ]; then
130 print -- "--DIAG: $assertion: Service $test_FMRI did not "
131 print -- " call start method enough times"
132 exit $STF_FAIL
133 fi
134
135 print -- "--INFO: Cleaning up service"
136 cleanup
137
138 exit $STF_PASS