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_007
  32 # DESCRIPTION:
  33 #  A service that is online is disabled. It's stop method exits with a
  34 #  non-zero value that is not the defined straight to maintenance exit
  35 #  code. The starter will continue to try to stop the service until
  36 #  the error threshold is reached, at which point the service will
  37 #  transition to the maintenance mode.
  38 #
  39 # end __stf_assertion__
  40 #
  41 
  42 . ${STF_TOOLS}/include/stf.kshlib
  43 . ${STF_SUITE}/include/gltest.kshlib
  44 . ${STF_SUITE}/include/svc.startd_config.kshlib
  45 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  46 
  47 typeset service_setup=0
  48 function cleanup {
  49         common_cleanup
  50         ret=$?
  51 
  52         # Forcibly kill the start/stop method process
  53         pkill -9 -z $(zonename) service_app
  54 
  55         return $ret
  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_007.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: generating manifest for importation into repository"
  87 manifest_generate $registration_template \
  88         TEST_SERVICE=$test_service \
  89         TEST_INSTANCE=$test_instance \
  90         SERVICE_APP=$service_app \
  91         LOGFILE=$service_log \
  92         STATEFILE=$service_state \
  93         STOP_EVENT="returncode $SVC_METHOD_OTHEREXIT" \
  94         > $registration_file
  95 
  96 print -- "--INFO: Importing service into repository"
  97 manifest_purgemd5 $registration_file
  98 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  99 if [ $? -ne 0 ]; then
 100         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
 101         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 102         exit $STF_UNRESOLVED
 103 fi
 104 service_setup=1
 105 
 106 print -- "--INFO: Wait for $test_FMRI to come online"
 107 service_wait_state $test_FMRI online
 108 if [ $? -ne 0 ]; then
 109         print -- "--DIAG: $assertion: Service $test_FMRI didn't go online"
 110         exit $STF_FAIL
 111 fi
 112 
 113 print -- "--INFO: disabling service"
 114 svcadm disable $test_FMRI
 115 if [ $? -ne 0 ]; then
 116         print -- "--DIAG: $assertion: disable command for Service "
 117         print -- "  $test_FMRI didn't succeed"
 118         exit $STF_UNRESOLVED
 119 fi
 120 
 121 print -- "--INFO: Waiting for issue of $test_FMRI stop method"
 122 service_wait_method $test_FMRI stop
 123 if [ $? -ne 0 ]; then
 124         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue stop"
 125         exit $STF_FAIL
 126 fi
 127 
 128 print -- "--INFO: Validating service is in maintenance mode"
 129 service_wait_state $test_FMRI maintenance
 130 if [ $? -ne 0 ]; then
 131         print -- "--DIAG: $assertion: Service $test_FMRI did not "
 132         print -- "  transition to maintenance mode"
 133         exit $STF_FAIL
 134 fi
 135 
 136 print -- "--INFO: Validating many invocations of stop method"
 137 service_countcall -f $service_state -s $test_service -i $test_instance stop
 138 countstops=$?
 139 if [ $countstops -lt $ERROR_THRESHOLD ]; then
 140         print -- "--DIAG: $assertion: Service $test_FMRI called stop method"
 141         print -- "  insufficient times"
 142         exit $STF_FAIL
 143 fi
 144 
 145 print -- "--INFO: Cleaning up service"
 146 cleanup
 147 
 148 exit $STF_PASS