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_021
  32 # DESCRIPTION:
  33 #  If all processes associated with an degraded service exit then the 
  34 #  svc.startd should attempt to restart the service. the service has
  35 #  one process.
  36 #
  37 # end __stf_assertion__
  38 #
  39 
  40 . ${STF_TOOLS}/include/stf.kshlib
  41 . ${STF_SUITE}/include/gltest.kshlib
  42 . ${STF_SUITE}/include/svc.startd_config.kshlib
  43 . ${STF_SUITE}/tests/include/svc.startd_fileops.kshlib
  44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  45 
  46 typeset service_setup=0
  47 function cleanup {
  48         rm -f $svcadm_errfile $monitor_errfile
  49         common_cleanup
  50         return $?
  51 }
  52 
  53 trap cleanup 0 1 2 15
  54 
  55 readonly ME=$(whence -p ${0})
  56 readonly MYLOC=$(dirname ${ME})
  57 
  58 DATA=$MYLOC
  59 
  60 registration_template=$DATA/service_021.xml
  61 
  62 extract_assertion_info $ME
  63 
  64 # make sure that the svc.startd is running
  65 verify_daemon
  66 if [ $? -ne 0 ]; then
  67         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  68         print -- "  continue"
  69         exit $STF_UNRESOLVED
  70 fi
  71 
  72 # Make sure the environment is clean - the test service isn't running
  73 print -- "--INFO: Cleanup any old $test_FMRI state"
  74 service_cleanup $test_service
  75 rm -f $service_state
  76 if [ $? -ne 0 ]; then
  77         print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
  78         exit $STF_UNRESOLVED
  79 fi
  80 
  81 print -- "--INFO: generating monitor returncode file"
  82 echo "returncode $SVC_DEGRADED" >$monitor_errfile
  83 if [ $? -ne 0 ]; then
  84         print -- "--DIAG: $assertion: unable to write to $monitor_errfile"
  85         exit $STF_UNRESOLVED
  86 fi
  87 
  88 print -- "--INFO: generating manifest for importation into repository"
  89 manifest_generate $registration_template \
  90         TEST_SERVICE=$test_service \
  91         TEST_INSTANCE=$test_instance \
  92         SERVICE_APP=$service_app \
  93         LOGFILE=$service_log \
  94         STATEFILE=$service_state \
  95         MONITOR_FILE=$monitor_errfile \
  96         > $registration_file
  97 
  98 print -- "--INFO: Importing service into repository"
  99 manifest_purgemd5 $registration_file
 100 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 101 if [ $? -ne 0 ]; then
 102         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
 103         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 104         exit $STF_UNRESOLVED
 105 fi
 106 service_setup=1
 107 
 108 print -- "--INFO: enabling $test_FMRI"
 109 svcadm enable $test_FMRI
 110 if [ $? -ne 0 ]; then
 111         print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
 112         exit $STF_FAIL
 113 fi
 114 
 115 print -- "--INFO: waiting for execution of start method"
 116 service_wait_method $test_FMRI start
 117 if [ $? -ne 0 ]; then
 118         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
 119         exit $STF_UNRESOLVED
 120 fi
 121 
 122 print -- "--INFO: sending service to degraded state"
 123 svcadm mark degraded $test_FMRI
 124 if [ $? -ne 0 ]; then
 125         print -- "--DIAG: Could not send service $test_FMRI to degraded"
 126         exit $STF_FAIL
 127 fi
 128 
 129 print -- "--INFO: Validating service reaches degraded mode"
 130 service_wait_state $test_FMRI degraded
 131 if [ $? -ne 0 ]; then
 132         print -- "--DIAG: $assertion: Service $test_FMRI didn't"
 133         print -- "  transition to online mode"
 134         exit $STF_FAIL
 135 fi
 136 
 137 print -- "--INFO: make the one of the service processes exit"
 138 $service_app -s $test_service -i $test_instance \
 139         -m trigger -r "triggerchildrv 0 0"
 140 
 141 print -- "--INFO: Waiting for service's start method"
 142 service_wait_method $test_FMRI start
 143 if [ $? -ne 0 ]; then
 144         print -- "--DIAG: $assertion: didn't issue start method"
 145         exit $STF_FAIL
 146 fi
 147 
 148 print -- "--INFO: Waiting for service to reach degraded state"
 149 service_wait_state $test_FMRI degraded
 150 if [ $? -ne 0 ]; then
 151         print -- "--DIAG: $assertion: service $test_FMRI didn't"
 152         print -- "  come to degraded"
 153         exit $STF_FAIL
 154 fi
 155 
 156 print -- "--INFO: Cleaning up service"
 157 cleanup
 158 
 159 exit $STF_PASS