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_014
  32 # DESCRIPTION:
  33 #  If svc.startd invokes a service's refresh method and that method
  34 #  returns a non zero exit code other than the defined straight to
  35 #  maintenance exit code then the service is considered
  36 #  to have failed, but not irrevocably. svc.startd will retry the
  37 #  refresh method. Should the method succeed before the error
  38 #  threshold is reached then the service will stay in the online state.
  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         rm -f $svcadm_errfile $returncode_file
  51         common_cleanup
  52         return $?
  53 }
  54 
  55 trap cleanup 0 1 2 15
  56 
  57 readonly ME=$(whence -p ${0})
  58 readonly MYLOC=$(dirname ${ME})
  59 
  60 DATA=$MYLOC
  61 
  62 registration_template=$DATA/service_014.xml
  63 
  64 extract_assertion_info $ME
  65 
  66 # make sure that the svc.startd is running
  67 verify_daemon
  68 if [ $? -ne 0 ]; then
  69         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  70         print -- "  continue"
  71         exit $STF_UNRESOLVED
  72 fi
  73 
  74 # make sure that the features are available
  75 features=`feature_test REFRESH`
  76 if [ $? -ne 0 ]; then
  77         print -- "--DIAG: $assertion: $features missing from startd"
  78         exit $STF_UNTESTED
  79 fi
  80 
  81 # Make sure the environment is clean - the test service isn't running
  82 print -- "--INFO: Cleanup any old $test_FMRI state"
  83 service_cleanup $test_service
  84 rm -f $service_state
  85 if [ $? -ne 0 ]; then
  86         print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
  87         exit $STF_UNRESOLVED
  88 fi
  89 
  90 print -- "--INFO: Creating returncode file"
  91 echo "returncode $SVC_METHOD_OTHEREXIT" > $returncode_file
  92 if [ $? -ne 0 ]; then
  93         print -- "--DIAG: $assertion: unable to create returncode file"
  94         exit $STF_UNRESOLVED
  95 fi
  96 
  97 print -- "--INFO: generating manifest for importation into repository"
  98 manifest_generate $registration_template \
  99         TEST_SERVICE=$test_service \
 100         TEST_INSTANCE=$test_instance \
 101         SERVICE_APP=$service_app \
 102         LOGFILE=$service_log \
 103         STATEFILE=$service_state \
 104         REFRESH_EVENT=$returncode_file \
 105         > $registration_file
 106 
 107 print -- "--INFO: Importing service into repository"
 108 manifest_purgemd5 $registration_file
 109 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 110 if [ $? -ne 0 ]; then
 111         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
 112         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 113         exit $STF_UNRESOLVED
 114 fi
 115 service_setup=1
 116 
 117 print -- "--INFO: enabling $test_FMRI"
 118 svcadm enable $test_FMRI
 119 if [ $? -ne 0 ]; then
 120         print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
 121         exit $STF_FAIL
 122 fi
 123 
 124 print -- "--INFO: waiting for execution of start method"
 125 service_wait_method $test_FMRI start
 126 if [ $? -ne 0 ]; then
 127         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
 128         exit $STF_UNRESOLVED
 129 fi
 130 
 131 print -- "--INFO: Validating service reaches online mode"
 132 service_wait_state $test_FMRI online
 133 if [ $? -ne 0 ]; then
 134         print -- "--DIAG: $assertion: Service $test_FMRI didn't"
 135         print -- "  transition to online mode"
 136         exit $STF_FAIL
 137 fi
 138 
 139 print -- "--INFO: Issuing refresh request"
 140 svcadm refresh $test_FMRI >$svcadm_errfile 2>&1
 141 if [ $? -ne 0 -o -s $svcadm_errfile ]; then
 142         print -- "--DIAG: $assertion: refresh of Service $test_FMRI did not "
 143         print -- "  succeed. Error output: \"$(cat $svcadm_errfile)\""
 144         exit $STF_UNRESOLVED
 145 fi
 146 
 147 print -- "--INFO: Waiting for call of $test_FMRI refresh method"
 148 service_wait_method $test_FMRI refresh
 149 if [ $? -ne 0 ]; then
 150         print -- "--DIAG: $assertion: didn't issue refresh method"
 151         exit $STF_FAIL
 152 fi
 153 
 154 print -- "--INFO: Changing the returncode for refresh to 0"
 155 print --  "returncode 0" >$returncode_file
 156 if [ $? -ne 0 ]; then
 157         print -- "--DIAG: $assertion: could not alter returncode to 0"
 158         print -- "  for the stop method."
 159         exit $STF_UNRESOLVED
 160 fi
 161 
 162 print -- "--INFO: Validating service doesn't reach maintenance state"
 163 service_wait_state $test_FMRI maintenance
 164 if [ $? -eq 0 ]; then
 165         print -- "--DIAG: $assertion: Service $test_FMRI did"
 166         print -- "  transition to the maintenance state."
 167         exit $STF_FAIL
 168 fi
 169 
 170 print -- "--INFO: Validating many invocations of refresh method"
 171 service_countcall -f $service_state -s $test_service -i $test_instance refresh
 172 countstops=$?
 173 if [ $countstops -lt $((ERROR_THRESHOLD / 2)) ]; then
 174         print -- "--DIAG: $assertion: Service $test_FMRI called"
 175         print -- "  stop method insufficient times"
 176         exit $STF_FAIL
 177 fi
 178 
 179 print -- "--INFO: Validating the online state of the service"
 180 service_wait_state $test_FMRI online
 181 if [ $? -ne 0 ]; then
 182         print -- "--DIAG: $assertion: Service $test_FMRI is not "
 183         print -- "  online."
 184         exit $STF_FAIL
 185 fi
 186 
 187 print -- "--INFO: Cleaning up service"
 188 cleanup
 189 
 190 exit $STF_PASS