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_025
  32 # DESCRIPTION:
  33 #  A service with a single process.
  34 #  If a service instance in the degraded state dies due to receipt of
  35 #  a fatal signal from another process then the svc.startd should attempt 
  36 #  to restart the service.
  37 #
  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/include/svc.startd_fileops.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 }
  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_025.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. Cannot "
  67         print -- "  continue"
  68         exit $STF_UNRESOLVED
  69 fi
  70 
  71 # Make sure the environment is clean - the test service isn't running
  72 print -- "--INFO: Cleanup any old $test_FMRI state"
  73 service_cleanup $test_service
  74 rm -f $service_state
  75 if [ $? -ne 0 ]; then
  76         print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
  77         exit $STF_UNRESOLVED
  78 fi
  79 
  80 print -- "--INFO: generating manifest for importation into repository"
  81 manifest_generate $registration_template \
  82         TEST_SERVICE=$test_service \
  83         TEST_INSTANCE=$test_instance \
  84         SERVICE_APP=$service_app \
  85         LOGFILE=$service_log \
  86         STATEFILE=$service_state \
  87         MONITOR_RESULT="returncode $SVC_DEGRADED" \
  88         > $registration_file
  89 
  90 print -- "--INFO: Importing service into repository"
  91 manifest_purgemd5 $registration_file
  92 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  93 if [ $? -ne 0 ]; then
  94         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
  95         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
  96         exit $STF_UNRESOLVED
  97 fi
  98 service_setup=1
  99 
 100 print -- "--INFO: enabling $test_FMRI"
 101 svcadm enable $test_FMRI
 102 if [ $? -ne 0 ]; then
 103         print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
 104         exit $STF_FAIL
 105 fi
 106 
 107 print -- "--INFO: waiting for execution of start method"
 108 service_wait_method $test_FMRI start
 109 if [ $? -ne 0 ]; then
 110         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
 111         exit $STF_UNRESOLVED
 112 fi
 113 
 114 print -- "--INFO: marking service as degraded"
 115 svcadm mark degraded $test_FMRI
 116 if [ $? -ne 0 ]; then
 117         print -- "--DIAG: $assertion: Service $test_FMRI could not be placed"
 118         print -- "  in the degraded state"
 119         exit $STF_UNRESOLVED
 120 fi
 121 
 122 print -- "--INFO: Validating service reaches degraded mode"
 123 service_wait_state $test_FMRI degraded
 124 if [ $? -ne 0 ]; then
 125         print -- "--DIAG: $assertion: Service $test_FMRI didn't"
 126         print -- "  transition to degraded mode"
 127         exit $STF_FAIL
 128 fi
 129 
 130 PIDS=`service_getpids -s $test_service -i $test_instance -f $service_state`
 131 print -- "--INFO: child pids are: $PIDS"
 132 
 133 # pad run log
 134 $service_app -s $test_service -i $test_instance -l $service_log -m "blank"
 135 
 136 print -- "--INFO: issue a kill to the service pid"
 137 kill $PIDS
 138 if [ $? -ne 0 ]; then
 139         print "--DIAG: $assertion: could not issue kill to $PID"
 140         exit $STF_UNRESOLVED
 141 fi
 142 
 143 print -- "--INFO: Waiting for service's start method"
 144 service_wait_method $test_FMRI start
 145 if [ $? -ne 0 ]; then
 146         print -- "--DIAG: $assertion: didn't issue start method"
 147         exit $STF_FAIL
 148 fi
 149 
 150 print -- "--INFO: Waiting for service to reach degraded state"
 151 service_wait_state $test_FMRI degraded
 152 if [ $? -ne 0 ]; then
 153         print -- "--DIAG: $assertion: service $test_FMRI didn't"
 154         print -- "  come degraded"
 155         exit $STF_FAIL
 156 fi
 157 
 158 print -- "--INFO: Cleaning up service"
 159 cleanup
 160 
 161 exit $STF_PASS