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