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: depends_042
  32 # DESCRIPTION:
  33 #  Pair of dependent services.
  34 #  If an online service, service_A, has a dependency on another service,
  35 #  service_B The dependency is of type reset_on="error".
  36 #   service_B encounters an error and is transitioned
  37 #  into maintenance mode, then service_A is transitioned offline.
  38 #  Once service_B transitions to online then service_A will transition 
  39 #  to online as well.
  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         common_cleanup
  52         rm -f $service_state1 $service_state2
  53 }
  54 
  55 trap cleanup 0 1 2 15
  56 
  57 readonly ME=$(whence -p ${0})
  58 readonly MYLOC=$(dirname ${ME})
  59 
  60 DATA=$MYLOC
  61 
  62 readonly registration_template=$DATA/service_042.xml
  63 
  64 extract_assertion_info $ME
  65 
  66 # make sure that the svc.startd is running
  67 verify_daemon
  68 if [ $? -ne 0 ]; then
  69         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  70         print -- "  continue"
  71         exit $STF_UNRESOLVED
  72 fi
  73 
  74 # Make sure the environment is clean - the test service isn't running
  75 print -- "--INFO: Cleanup any old $test_FMRI1, $test_FMRI2 state"
  76 service_cleanup $test_service
  77 if [ $? -ne 0 ]; then
  78         print -- "--DIAG: $assertion: cleanup of a previous instance failed"
  79         exit $STF_UNRESOLVED
  80 fi
  81 
  82 print -- "--INFO: generating manifest for importation into repository"
  83 manifest_generate $registration_template \
  84         TEST_SERVICE=$test_service \
  85         TEST_INSTANCE1=$test_instance1 \
  86         TEST_INSTANCE2=$test_instance2 \
  87         SERVICE_APP=$service_app \
  88         LOGFILE=$service_log \
  89         STATEFILE1=$service_state1 \
  90         STATEFILE2=$service_state2 > $registration_file
  91 
  92 print -- "--INFO: Importing service into repository"
  93 manifest_purgemd5 $registration_file
  94 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  95 
  96 if [ $? -ne 0 ]; then
  97         print -- "--DIAG: $assertion: Unable to import the services $test_FMRI1"
  98         print -- "  and $test_FMRI2 error messages from svccfg: "
  99         print -- "  \"$(cat $svccfg_errfile)\""
 100         exit $STF_UNRESOLVED
 101 fi
 102 service_setup=1
 103 
 104 print -- "--INFO: Wait for $test_FMRI2 to come online"
 105 service_wait_state $test_FMRI2 online
 106 if [ $? -ne 0 ]; then
 107         print -- "--DIAG: $assertion: Service $test_FMRI2 didn't come online
 108         Current state: $(svcprop -p restarter/state $test_FMRI2)"
 109         exit $STF_UNRESOLVED
 110 fi
 111 
 112 thresh=0
 113 
 114 print -- "--INFO: Waiting for $test_FMRI1 to come online"
 115 service_wait_state $test_FMRI1 online
 116 if [ $? -ne 0 ]; then
 117         print -- "--DIAG: $assertion: $test_FMRI1 did not come online
 118         Current state: $(svcprop -p restarter/state $test_FMRI1)"
 119         exit $STF_UNRESOLVED
 120 fi
 121 
 122 typeset NFAIL=10
 123 print -- "--INFO: Make start method of $test_FMRI1 repeatedly fail $NFAIL times"
 124 while [ $thresh -le $NFAIL ]; do
 125         # failures are triggered by asking the start method to coredump,
 126         # as well as by killing the service methods externally
 127         service_app -s $test_service -i $test_instance1 -m blip \
 128                 -r triggerservicesegv
 129         for m in start stop; do
 130                 for proc in `echo $(svcs -Hp $test_instance1 | \
 131                         awk '/service_app/ { print $2 }' 2>/dev/null)`; do
 132                         kill -9 $proc 2>/dev/null
 133                 done
 134         done
 135         thresh=$((thresh + 1))
 136 done
 137 
 138 echo "--INFO: Wait for service to enter maintenance mode"
 139 service_wait_state $test_FMRI1 maintenance
 140 if [ $? -ne 0 ]; then
 141         echo "--DIAG: $assertion: Service $test_FMRI1 didn't enter "
 142         echo "  maintenance mode
 143         Current state: $(svcprop -p restarter/state $test_FMRI1)"
 144         exit $STF_UNRESOLVED
 145 fi
 146 
 147 echo "--INFO: Checking that $test_FMRI2 goes offline"
 148 service_wait_state $test_FMRI2 offline
 149 if [ $? -ne 0 ]; then
 150         echo "--DIAG: $assertion: Service $test_FMRI2 didn't go offline
 151         Current state: $(svcprop -p restarter/state $test_FMRI2)"
 152         exit $STF_FAIL
 153 fi
 154 
 155 print -- "--INFO: Cleaning up service"
 156 cleanup
 157 
 158 exit $STF_PASS