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_008
  32 # DESCRIPTION:
  33 #  If a service in the online state receives a request to disable
  34 #  svc.startd will invoke the stop method for the service. If the stop
  35 #  method returns a non zero value other than the defined straight to
  36 #  maintenance return code. svc.startd will retry the stop method.
  37 #  It will end the effort if the stop method succeeds before exceeding
  38 #  the error threshold.
  39 #  The service will enter the disabled 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 $servicecode_file
  52         [[ $service_setup -ne 0 ]] && $service_app -s $test_service \
  53                         -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_008.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 print --  "returncode $SVC_METHOD_OTHEREXIT" >$servicecode_file
  88 if [ $? -ne 0 ]; then
  89         printf -- "--DIAG: $assertion: unable to write to $servicecode_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         RETURNCODE="$servicecode_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"
 114 service_wait_state $test_FMRI online
 115 if [ $? -ne 0 ]; then
 116         print -- "--DIAG: $assertion: Service $test_FMRI didn't go online"
 117         exit $STF_FAIL
 118 fi
 119 
 120 print -- "--INFO: disabling service"
 121 svcadm disable $test_FMRI
 122 if [ $? -ne 0 ]; then
 123         print -- "$assertion: disable command for Service $test_FMRI didn't "
 124         print -- "  succeed"
 125         exit $STF_UNRESOLVED
 126 fi
 127 
 128 print -- "--INFO: Waiting for issue of $test_FMRI stop method"
 129 service_wait_method $test_FMRI stop
 130 if [ $? -ne 0 ]; then
 131         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue stop"
 132         exit $STF_FAIL
 133 fi
 134 
 135 print -- "--INFO: Validating service is not in maintenance mode"
 136 service_wait_state $test_FMRI maintenance $((ERROR_THRESHOLD / 2))
 137 if [ $? -eq 0 ]; then
 138         print -- "--DIAG: $assertion: Service $test_FMRI transitioned "
 139         print -- "  to maintenance mode"
 140         exit $STF_FAIL
 141 fi
 142 
 143 print -- "--INFO: Validating many invocations of stop method"
 144 service_countcall -f $service_state -s $test_service -i $test_instance stop
 145 countstops=$?
 146 if [ $countstops -lt $((ERROR_THRESHOLD / 2)) ]; then
 147         print -- "--DIAG: $assertion: Service $test_FMRI called "
 148         print -- "  stop method insufficient times"
 149         exit $STF_FAIL
 150 fi
 151 
 152 print -- "--INFO: Changing the returncode for stop to 0"
 153 print --  "returncode 0" >$servicecode_file
 154 if [ $? -ne 0 ]; then
 155         print -- "--DIAG: $assertion: could not alter returncode to 0"
 156         print -- "  for the stop method."
 157         exit $STF_UNRESOLVED
 158 fi
 159 
 160 # XXX: this is a hack. Maintenance mode may by reached because of the low
 161 # error threshold (3)
 162 service_wait_state $test_FMRI maintenance $ERROR_THRESHOLD
 163 if [ $? -eq 0 ]; then
 164         print -- "--INFO: clearing maintenance state from service"
 165         svcadm clear $test_FMRI
 166         if [ $? -ne 0 ]; then
 167                 print -- "--DIAG: $assertion: could not clear $test_FMRI"
 168                 print -- "  from maintenance state."
 169                 exit $STF_UNRESOLVED
 170         fi
 171 fi
 172 
 173 print -- "--INFO: Validating the disabling of the service"
 174 service_wait_state $test_FMRI disabled
 175 if [ $? -ne 0 ]; then
 176         print -- "--DIAG: $assertion: Service $test_FMRI did not "
 177         print -- "  transition to disabled mode"
 178         exit $STF_FAIL
 179 fi
 180 
 181 print -- "--INFO: Cleaning up service"
 182 cleanup
 183 
 184 exit $STF_PASS