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_041
  32 # DESCRIPTION:
  33 #  A service that possesses a "failing, but not unrecoverable" enable
  34 #  method will upon the issuing of 'svcadm enable' result in the enable
  35 #  method being executed until the error threshold is reached; However
  36 #  should the enable method succeed before the error threshold is
  37 #  reached then it will transition to the online state.
  38 # end __stf_assertion__
  39 #
  40 
  41 . ${STF_TOOLS}/include/stf.kshlib
  42 . ${STF_SUITE}/include/gltest.kshlib
  43 . ${STF_SUITE}/include/svc.startd_config.kshlib
  44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  45 
  46 typeset service_setup=0
  47 function cleanup {
  48         rm -f $returncode_file
  49         common_cleanup
  50 }
  51 
  52 trap cleanup 0 1 2 15
  53 
  54 readonly ME=$(whence -p ${0})
  55 readonly MYLOC=$(dirname ${ME})
  56 
  57 DATA=$MYLOC
  58 
  59 registration_template=$DATA/service_041.xml
  60 
  61 extract_assertion_info $ME
  62 
  63 # make sure that the svc.startd is running
  64 verify_daemon
  65 if [ $? -ne 0 ]; then
  66         print -- "--DIAG: $assertion: svc.startd is not executing. "
  67         print -- "  Cannot continue"
  68         exit $STF_UNRESOLVED
  69 fi
  70 
  71 # feature testing
  72 features=`feature_test METH_ENABLE`
  73 if [ $? -ne 0 ]; then
  74         print -- "--DIAG: $assertion: $features missing from startd"
  75         exit $STF_UNTESTED
  76 fi
  77 
  78 # Make sure the environment is clean - the test service isn't running
  79 print -- "--INFO: Cleanup any old $test_FMRI state"
  80 service_cleanup $test_service
  81 if [ $? -ne 0 ]; then
  82         print -- "--DIAG: $assertion: cleanup of previous service state failed"
  83         exit $STF_UNRESOLVED
  84 fi
  85 
  86 print -- "--INFO: generating returncode file"
  87 echo "returncode $SVC_METHOD_OTHEREXIT" > $returncode_file
  88 if [ $? -ne 0 ]; then
  89         print -- "--DIAG: could not create the 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         ENABLE_RESULT=$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: Wait for $test_FMRI to come online ... it should not!"
 114 service_wait_state $test_FMRI online
 115 if [ $? -eq 0 ]; then
 116         print -- "--DIAG: $assertion: Service $test_FMRI went online"
 117         exit $STF_FAIL
 118 fi
 119 
 120 print -- "--INFO: Enabling service"
 121 svcadm enable $test_FMRI
 122 if [ $? -ne 0 ]; then
 123         print -- "--DIAG: $assertion: Service $test_FMRI didn't try to enable"
 124         exit $STF_UNRESOLVED
 125 fi
 126 
 127 print -- "--INFO: Waiting for invocation of enable method"
 128 service_wait_method $test_FMRI enable
 129 if [ $? -ne 0 ]; then
 130         print -- "--DIAG: $assertion: $test_FMRI didn't execute enable method"
 131         exit $STF_FAIL
 132 fi
 133 
 134 print -- "--INFO: Waiting for transition of $test_FMRI back to disabled"
 135 service_wait_state $test_FMRI disabled
 136 if [ $? -ne 0 ]; then
 137         print -- "--DIAG: $assertion: Service $test_FMRI didn't goto disabled"
 138         exit $STF_FAIL
 139 fi
 140 
 141 print -- "--INFO: removing reason to fail to enable"
 142 echo "returncode 0" > $returncode_file
 143 
 144 print -- "--INFO: waiting for service to come online"
 145 service_wait_state $test_FMRI online
 146 if [ $? -ne 0 ]; then
 147         print -- "--DIAG: $assertion: Service $test_FMRI didn't come online"
 148         exit $STF_FAIL
 149 fi
 150 
 151 print -- "--INFO: Validating multiple calls of enable"
 152 service_countcalls -f $service_state -s $test_service -i $test_instance enable
 153 count=$?
 154 if [ $count -lt $((ERROR_THRESHOLD / 2)) ]; then
 155         print -- "--DIAG: $assertion: Service $test_FMRI didn't call "
 156         print -- "  enable method enough times."
 157         print -- "      EXPECTED: called >= $((ERROR_THRESHOLD / 2)) times"
 158         print -- "      OBSERVED: called    $count times"
 159         exit $STF_FAIL
 160 fi
 161 
 162 print -- "--INFO: Cleaning up service"
 163 cleanup
 164 
 165 exit $STF_PASS