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_017
  32 # DESCRIPTION:
  33 #  If a service instance in the degraded state dumps core than svc.startd 
  34 #  should attempt to restart the service. The service has one process
  35 #
  36 # end __stf_assertion__
  37 #
  38 
  39 . ${STF_TOOLS}/include/stf.kshlib
  40 . ${STF_SUITE}/include/gltest.kshlib
  41 . ${STF_SUITE}/include/svc.startd_config.kshlib
  42 . ${STF_SUITE}/tests/include/svc.startd_fileops.kshlib
  43 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  44 
  45 typeset service_setup=0
  46 function cleanup {
  47         rm -f $svcadm_errfile $monitor_errfile
  48         [[ "$pps" = "disabled" ]] && coreadm -d proc-setid 2>/dev/null
  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_017.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 typeset -i rc=0
  72 
  73 # Make sure the environment is clean - the test service isn't running
  74 print -- "--INFO: Cleanup any old $test_FMRI state"
  75 service_cleanup $test_service
  76 rm -f $service_state
  77 if [ $? -ne 0 ]; then
  78         print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
  79         exit $STF_UNRESOLVED
  80 fi
  81 
  82 pps=$(env LC_ALL=C coreadm | grep 'per-process setid' | awk '{print $NF }')
  83 
  84 if [ -z "$pps" ]; then
  85         print -- "--DIAG: could not get state from coreadm"
  86         exit $STF_UNRESOLVED
  87 fi
  88 
  89 if [ "$pps" = "disabled" ]; then
  90         print -- "--INFO: Enabling per-process setid coredumps"
  91         coreadm -e proc-setid
  92         if [ $? -ne 0 ]; then
  93                 print -- "--DIAG: Could not enable per-process setid coredumps"
  94                 exit $STF_UNRESOLVED
  95         fi
  96 fi
  97 
  98 print -- "--INFO: Creating monitor returncode file"
  99 echo "returncode $SVC_DEGRADED" > $monitor_errfile
 100 if [ $? -ne 0 ]; then
 101         print -- "--DIAG: $assertion: unable to create $monitor_errfile"
 102         exit $STF_UNRESOLVED
 103 fi
 104 
 105 print -- "--INFO: generating manifest for importation into repository"
 106 manifest_generate $registration_template \
 107         TEST_SERVICE=$test_service \
 108         TEST_INSTANCE=$test_instance \
 109         SERVICE_APP=$service_app \
 110         LOGFILE=$service_log \
 111         STATEFILE=$service_state \
 112         MONITOR_FILE=$monitor_errfile \
 113         > $registration_file
 114 
 115 print -- "--INFO: Importing service into repository"
 116 manifest_purgemd5 $registration_file
 117 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 118 rc=$?
 119 if [ $rc -ne 0 ]; then
 120         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
 121         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 122         exit $STF_UNRESOLVED
 123 fi
 124 service_setup=1
 125 
 126 print -- "--INFO: enabling $test_FMRI"
 127 svcadm enable $test_FMRI
 128 rc=$?
 129 if [ $rc -ne 0 ]; then
 130         print -- "--DIAG: $assertion: enable command of $test_FMRI failed
 131         EXPECTED: svcadm returned 0
 132         OBSERVED: svcadm returned $rc"
 133         exit $STF_FAIL
 134 fi
 135 
 136 print -- "--INFO: waiting for execution of start method"
 137 service_wait_method $test_FMRI start
 138 if [ $? -ne 0 ]; then
 139         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
 140         exit $STF_UNRESOLVED
 141 fi
 142 
 143 print -- "--INFO: marking state to degraded"
 144 svcadm mark degraded $test_FMRI
 145 rc=$?
 146 if [ $rc -ne 0 ]; then
 147         print -- "--DIAG: $assertion: Service $test_FMRI didn't enter degraded
 148         EXPECTED: 'svcadm mark degraded $test_FMRI' returned 0
 149         OBSERVED: 'svcadm mark degrated $test_FMRI' returned $rc"
 150         exit $STF_UNRESOLVED
 151 fi
 152 
 153 print -- "--INFO: Validating service reaches degraded mode"
 154 service_wait_state $test_FMRI degraded
 155 if [ $? -ne 0 ]; then
 156         print -- "--DIAG: $assertion: Service $test_FMRI didn't"
 157         print -- "      transition to degraded mode
 158         EXPECTED: service state = degraded
 159         OBSERVED: service state = `svcprop -p restarter/state $test_FMRI`"
 160         exit $STF_FAIL
 161 fi
 162 
 163 print -- "--INFO: get the services to generate core files into log dir"
 164 PIDS=`service_getpids -s $test_service -i $test_instance -f $service_state`
 165 print -- "--INFO: child pids are: $PIDS"
 166 coreadm -p "$RUNDIR/core.%p" $PIDS
 167 
 168 print -- "--INFO: make the service core dump... use dummy method"
 169 $service_app -s $test_service -i $test_instance \
 170         -m trigger -r "triggerservicesegv"
 171 
 172 print -- "--INFO: remove monitor's reason for issuing SVC_DEGRADED"
 173 echo "" > $monitor_errfile
 174 
 175 print -- "--INFO: checking for core file"
 176 for i in $PIDS; do
 177         file_wait_exist $RUNDIR/core.$i
 178         if [ $? -ne 0 ]; then
 179                 print -- "--DIAG: core file for service not found"
 180                 exit $STF_FAIL
 181         fi
 182         # blow it away... we actually don't care about the contents
 183         rm -f $RUNDIR/core.$i
 184 done
 185 
 186 print -- "--INFO: Waiting for service's start method"
 187 service_wait_method $test_FMRI start
 188 if [ $? -ne 0 ]; then
 189         print -- "--DIAG: $assertion: didn't issue start method"
 190         exit $STF_FAIL
 191 fi
 192 
 193 print -- "--INFO: Waiting for service to reach online state"
 194 service_wait_state $test_FMRI online
 195 if [ $? -ne 0 ]; then
 196         print -- "--DIAG: $assertion: service $test_FMRI didn't"
 197         print -- "  come online"
 198         exit $STF_FAIL
 199 fi
 200 
 201 print -- "--INFO: Cleaning up service"
 202 cleanup
 203 
 204 exit $STF_PASS