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_011
  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 defined
  36 #  straight to maintenance exit code then the method is considered to
  37 #  have failed, but not irrevocably. svc.startd will retry the start
  38 #  method. If the method succeeds before the error threshold is exceeded
  39 #  then it will transition to the online state.
  40 #
  41 # end __stf_assertion__
  42 #
  43 
  44 . ${STF_TOOLS}/include/stf.kshlib
  45 . ${STF_SUITE}/include/gltest.kshlib
  46 . ${STF_SUITE}/include/svc.startd_config.kshlib
  47 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  48 
  49 typeset service_setup=0
  50 function cleanup {
  51         rm -f $returncode_file
  52         [[ $service_setup -ne 0 ]] && \
  53                 $service_app -s $test_service -i $test_instance -m force_stop
  54         common_cleanup
  55         return $?
  56 }
  57 
  58 trap cleanup 0 1 2 15
  59 
  60 readonly ME=$(whence -p ${0})
  61 readonly MYLOC=$(dirname ${ME})
  62 
  63 DATA=$MYLOC
  64 
  65 registration_template=$DATA/service_011.xml
  66 
  67 extract_assertion_info $ME
  68 
  69 # make sure that the svc.startd is running
  70 verify_daemon
  71 if [ $? -ne 0 ]; then
  72         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  73         print -- "  continue"
  74         exit $STF_UNRESOLVED
  75 fi
  76 
  77 # Make sure the environment is clean - the test service isn't running
  78 print -- "--INFO: Cleanup any old $test_FMRI state"
  79 service_cleanup $test_service
  80 rm -f $service_state
  81 if [ $? -ne 0 ]; then
  82         print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
  83         exit $STF_UNRESOLVED
  84 fi
  85 
  86 print -- "--INFO: creating returncode file"
  87 echo "returncode $SVC_METHOD_OTHEREXIT" > $returncode_file
  88 if [ $? -ne 0 ]; then
  89         print -- "--DIAG: $assertion: unable to write to file $returncode_file"
  90         exit $STF_UNRESOLVED
  91 fi
  92 
  93 print -- "--INFO: generating manifest for importation into repository"
  94 manifest_generate $registration_template \
  95         TEST_SERVICE=$test_service \
  96         TEST_INSTANCE=$test_instance \
  97         SERVICE_APP=$service_app \
  98         LOGFILE=$service_log \
  99         STATEFILE=$service_state \
 100         START_EVENT=$returncode_file \
 101         > $registration_file
 102 
 103 print -- "--INFO: Importing service into repository"
 104 manifest_purgemd5 $registration_file
 105 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 106 if [ $? -ne 0 ]; then
 107         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
 108         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 109         exit $STF_UNRESOLVED
 110 fi
 111 service_setup=1
 112 
 113 print -- "--INFO: enabling $test_FMRI"
 114 svcadm enable $test_FMRI
 115 if [ $? -ne 0 ]; then
 116         print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
 117         exit $STF_FAIL
 118 fi
 119 
 120 print -- "--INFO: waiting for execution of start method"
 121 service_wait_method $test_FMRI start
 122 if [ $? -ne 0 ]; then
 123         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
 124         exit $STF_UNRESOLVED
 125 fi
 126 
 127 print -- "--INFO: Validating service is not in maintenance mode"
 128 service_wait_state $test_FMRI maintenance $((ERROR_THRESHOLD / 2))
 129 if [ $? -eq 0 ]; then
 130         print -- "--DIAG: $assertion: Service $test_FMRI went"
 131         print -- "  to maintenance mode too quickly"
 132         exit $STF_FAIL
 133 fi
 134 
 135 print -- "--INFO: Validating multiple invocations of start method"
 136 service_countcall -f $service_state -s $test_service -i $test_instance start
 137 countstarts=$?
 138 if [ $countstarts -lt $((ERROR_THRESHOLD / 2)) ]; then
 139         print -- "--DIAG: $assertion: Service $test_FMRI did not "
 140         print -- "  call start method enough times"
 141         exit $STF_FAIL
 142 fi
 143 
 144 print -- "--INFO: Changing the returncode of start method to 0"
 145 echo "returncode 0" > $returncode_file
 146 if [ $? -ne 0 ]; then
 147         print -- "--DIAG: $assertion: could not alter returncode to 0"
 148         print -- "  for the stop method."
 149         exit $STF_UNRESOLVED
 150 fi
 151 
 152 # XXX: hack for maintenance mode and error_threshold being too low
 153 service_wait_state $test_FMRI maintenance $ERROR_THRESHOLD
 154 if [ $? -eq 0 ]; then
 155         print -- "--INFO: clearing maintenance mode"
 156         svcadm clear $test_FMRI
 157         if [ $? -ne 0 ]; then
 158                 print -- "--DIAG: Could not clear maintenance mode"
 159                 exit $STF_UNRESOLVED
 160         fi
 161 fi
 162 
 163 print -- "--INFO: Validating service reaching online state"
 164 service_wait_state $test_FMRI online
 165 if [ $? -ne 0 ]; then
 166         print -- "--DIAG: $assertion: Service $test_FMRI did not"
 167         print -- "  transition to the online state"
 168         exit $STF_FAIL
 169 fi
 170 
 171 print -- "--INFO: Cleaning up service"
 172 cleanup
 173 
 174 exit $STF_PASS