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_012
  32 # DESCRIPTION:
  33 #  A service with multiple dependencies in an "exclude_all" grouping
  34 #  set in the service's definition. If any of the dependencies 
  35 #  fail then the service will be transitioned into the offline state.
  36 #  Services: a, b, c; c specifies exclude_all of (a, b)
  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/svc.startd/include/svc.startd_common.kshlib
  45 
  46 typeset service_setup=0
  47 function cleanup {
  48         common_cleanup
  49         rm -f $service_state1 $service_state2 $service_state3
  50 }
  51 
  52 function disable_wait {
  53         typeset service="$1"
  54         echo "--INFO: Disabling service $service"
  55         svcadm disable $service
  56         if [ $? -ne 0 ]; then
  57                 echo "--DIAG: $assertion: Service $service did not "
  58                 echo "  disable"
  59                 exit $STF_FAIL
  60         fi
  61 
  62         echo "--INFO: Waiting for $service to enter disabled"
  63         service_wait_state $service disabled
  64         if [ $? -ne 0 ]; then
  65                 echo "--DIAG: $assertion: Service $service did not get disabled
  66         Current state: '$(svcprop -p restarter/state $service)'"
  67                 exit $STF_FAIL
  68         fi
  69 }
  70 
  71 function wait_online {
  72         typeset service="$1"
  73         
  74         echo "--INFO: Waiting for $service to come online"
  75         service_wait_state $service online
  76         if [ $? -ne 0 ]; then
  77                 echo "--DIAG: $assertion: Service $service did not go online
  78         Current state: '$(svcprop -p restarter/state $service)'"
  79                 exit $STF_FAIL
  80         fi
  81 }
  82 
  83 function enable_wait {
  84         typeset service="$1"
  85         echo "--INFO: Enable service $service"
  86         svcadm enable $service
  87         if [ $? -ne 0 ]; then
  88                 echo "--DIAG: $assertion: Service $service did not "
  89                 echo "  enable"
  90                 exit $STF_FAIL
  91         fi
  92 
  93         wait_online $service
  94 }
  95 
  96 function wait_offline {
  97         typeset service="$1"
  98         echo "--INFO: Wait for $service to go offline"
  99         service_wait_state $service offline
 100         if [ $? -ne 0 ]; then
 101                 echo "--DIAG: $assertion: Service $service didn't go offline
 102         Current state: '$(svcprop -p restarter/state $service)'"
 103                 exit $STF_FAIL
 104         fi
 105 }
 106 
 107 trap cleanup 0 1 2 15
 108 
 109 readonly ME=$(whence -p ${0})
 110 readonly MYLOC=$(dirname ${ME})
 111 
 112 DATA=$MYLOC
 113 
 114 readonly registration_template=$DATA/service_012.xml
 115 
 116 extract_assertion_info $ME
 117 
 118 # make sure that the svc.startd is running
 119 verify_daemon
 120 if [ $? -ne 0 ]; then
 121         echo "--DIAG: $assertion: svc.startd is not executing. Cannot "
 122         echo "  continue"
 123         exit $STF_UNRESOLVED
 124 fi
 125 
 126 # Make sure the environment is clean - the test service isn't running
 127 echo "--INFO: Cleanup any old $test_service state"
 128 service_cleanup $test_service
 129 if [ $? -ne 0 ]; then
 130         echo "--DIAG: $assertion: cleanup of a previous instance failed"
 131         exit $STF_UNRESOLVED
 132 fi
 133 
 134 echo "--INFO: generating manifest for importation into repository"
 135 manifest_generate $registration_template \
 136         TEST_SERVICE=$test_service \
 137         TEST_INSTANCE1=$test_instance1 \
 138         TEST_INSTANCE2=$test_instance2 \
 139         TEST_INSTANCE3=$test_instance3 \
 140         SERVICE_APP=$service_app \
 141         LOGFILE=$service_log \
 142         STATEFILE1=$service_state1 \
 143         STATEFILE2=$service_state2 \
 144         STATEFILE3=$service_state3 \
 145         > $registration_file
 146 
 147 echo "--INFO: Importing service into repository"
 148 manifest_purgemd5 $registration_file
 149 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 150 
 151 if [ $? -ne 0 ]; then
 152         echo "--DIAG: $assertion: Unable to import the services $test_FMRI1"
 153         echo "  $test_FMRI2 and $test_FMRI3 error messages from svccfg: "
 154         echo "  \"$(cat $svccfg_errfile)\""
 155         exit $STF_UNRESOLVED
 156 fi
 157 service_setup=1
 158 
 159 echo "--INFO: Wait for $test_FMRI3 to go offline"
 160 service_wait_state $test_FMRI3 offline
 161 if [ $? -ne 0 ]; then
 162         echo "--DIAG: $assertion: Service $test_FMRI3 did not go offline
 163         State of services:"
 164         svcs -l $test_service\*
 165         exit $STF_FAIL
 166 fi
 167 
 168 disable_wait $test_FMRI1
 169 
 170 echo "--INFO: Wait for $test_FMRI3 to come online - it should not"
 171 service_wait_state $test_FMRI3 online
 172 if [ $? -eq 0 ]; then
 173         echo "--DIAG: $assertion: Service $test_FMRI3 came online"
 174         exit $STF_FAIL
 175 fi
 176 
 177 disable_wait $test_FMRI2
 178 
 179 wait_online $test_FMRI3
 180 
 181 enable_wait $test_FMRI1
 182 
 183 wait_offline $test_FMRI3
 184 
 185 disable_wait $test_FMRI1
 186 
 187 wait_online $test_FMRI3
 188 
 189 enable_wait $test_FMRI2
 190 
 191 wait_offline $test_FMRI3
 192 
 193 disable_wait $test_FMRI2
 194 
 195 wait_online $test_FMRI3
 196 
 197 echo "--INFO: Cleaning up service"
 198 cleanup
 199 
 200 exit $STF_PASS