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_046
  32 # DESCRIPTION:
  33 #  Pair of dependent services.
  34 #  service_A has multiple dependencies on other services. It will stay
  35 #  online if any of its optional_all dependent services are offline.
  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/svc.startd/include/svc.startd_common.kshlib
  44 
  45 typeset service_setup=0
  46 function cleanup {
  47         common_cleanup
  48         rm -f $service_state1 $service_state2 $service_state3 $service_state4 \
  49                 $service_state5
  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 readonly registration_template=$DATA/service_046.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 # Make sure the environment is clean - the test service isn't running
  72 print -- "--INFO: Cleanup any old $test_service state"
  73 service_cleanup $test_service
  74 if [ $? -ne 0 ]; then
  75         print -- "--DIAG: $assertion: cleanup of a previous instance failed"
  76         exit $STF_UNRESOLVED
  77 fi
  78 
  79 print -- "--INFO: generating manifest for importation into repository"
  80 manifest_generate $registration_template \
  81         TEST_SERVICE=$test_service \
  82         TEST_INSTANCE1=$test_instance1 \
  83         TEST_INSTANCE2=$test_instance2 \
  84         TEST_INSTANCE3=$test_instance3 \
  85         TEST_INSTANCE4=$test_instance4 \
  86         TEST_INSTANCE5=$test_instance5 \
  87         SERVICE_APP=$service_app \
  88         LOGFILE=$service_log \
  89         STATEFILE1=$service_state1 \
  90         STATEFILE2=$service_state2 \
  91         STATEFILE3=$service_state3 \
  92         STATEFILE4=$service_state4 \
  93         STATEFILE5=$service_state5 \
  94         > $registration_file
  95 
  96 print -- "--INFO: Importing service into repository"
  97 manifest_purgemd5 $registration_file
  98 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  99 
 100 if [ $? -ne 0 ]; then
 101         echo "--DIAG: $assertion: Unable to import the service $test_service"
 102         echo "  and $test_FMRI2 error messages from svccfg: "
 103         echo "  \"$(cat $svccfg_errfile)\""
 104         exit $STF_UNRESOLVED
 105 fi
 106 service_setup=1
 107 
 108 print -- "--INFO: List service dependencies"
 109 for svc in $test_FMRI1 $test_FMRI2 $test_FMRI3; do
 110         svcs -l $svc | grep ^[fd]
 111         print " "
 112 done
 113 
 114 # phase 1 ... all dependents disabled
 115 print -- "--INFO: [Phase 1] Wait for $test_FMRI1 to come online"
 116 service_wait_state $test_FMRI1 online
 117 if [ $? -ne 0 ]; then
 118         print -- "--DIAG: $assertion: Service $test_FMRI1 dodn't come online"
 119         exit $STF_FAIL
 120 fi
 121 
 122 thresh=0
 123 
 124 # phase 2 ... enable one of the dependencies, should stay offline
 125 print -- "--INFO: [ Phase 2 ] Enable $test_FMRI2 (currently offline)"
 126 print "  $test_FMRI2 should stay offline, $test_FMRI1 should stay online"
 127 print " "
 128 
 129 print -- "--INFO: enabling $test_FMRI2, should stay offline"
 130 svcadm enable $test_FMRI2
 131 if [ $? -ne 0 ]; then
 132         echo "--DIAG: Could not enable $test_FMRI2"
 133         exit $STF_UNRESOLVED
 134 fi
 135 
 136 service_wait_state $test_FMRI2 offline
 137 if [ $? -ne 0 ]; then
 138         echo "--DIAG: Service $test_FMRI2 did not enter the offline state."
 139         echo "  it is in '$(svcprop -p restarter/state $test_FMRI2)' state"
 140         exit $STF_INRESOLVED
 141 fi
 142 
 143 service_wait_state $test_FMRI1 online
 144 if [ $? -ne 0 ]; then
 145         echo "--DIAG: $assertion: $test_FMRI1 did not stay offline"
 146         echo "  it is in the '$(svcprop -p restarter/state $test_FMRI1)' state"
 147         exit $STF_FAIL
 148 fi
 149 
 150 # enable dependency of $test_FMRI2, it should cause test_FMRI{1,2} to be online
 151 echo "--INFO: [ Phase 3 ] online the required dependency of ($test_FMRI2)"
 152 echo "--INFO: enable $test_FMRI4.
 153         $test_FMRI2 should go online and $test_FMRI1 should stay online."
 154 svcadm enable $test_FMRI4
 155 if [ $? -ne 0 ]; then
 156         echo "--DIAG: $assertion: $test_FMRI4 did not enable."
 157         exit $STF_UNRESOLVED
 158 fi
 159 
 160 service_wait_state $test_FMRI4 online
 161 if [ $? -ne 0 ]; then
 162         echo "--DIAG: $assertion: $test_FMRI4 did not go online."
 163         echo "  it's in '$(svcprop -p restarter/state $test_FMRI4)' state."
 164         exit $STF_UNRESOLVED
 165 fi
 166 
 167 service_wait_state $test_FMRI2 online
 168 if [ $? -ne 0 ]; then
 169         echo "--DIAG: $assertion: $test_FMRI2 did not go online."
 170         echo "  it's in '$(svcprop -p restarter/state $test_FMRI2)' state."
 171         exit $STF_UNRESOLVED
 172 fi
 173 
 174 service_wait_state $test_FMRI1 online
 175 if [ $? -ne 0 ]; then
 176         echo "--DIAG: $assertion: $test_FMRI1 did not stay online."
 177         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 178         exit $STF_FAIL
 179 fi
 180 
 181 echo "--INFO: [ Phase 4 ] enable dependency $test_FMRI3
 182         $test_FMRI1 should stay online"
 183 
 184 echo "--INFO: Enabling $test_FMRI3"
 185 svcadm enable $test_FMRI3
 186 if [ $? -ne 0 ]; then
 187         echo "--DIAG: $assertion: $test_FMRI3 would not enable."
 188         exit $STF_UNRESOLVED
 189 fi
 190 
 191 service_wait_state $test_FMRI3 offline
 192 if [ $? -ne 0 ]; then
 193         echo "--DIAG: $assertion: $test_FMRI3 is not offline."
 194         echo "  it's in '$(svcprop -p restarter/state $test_FMRI3)' state."
 195         exit $STF_UNRESOLVED
 196 fi
 197 service_wait_state $test_FMRI1 online
 198 if [ $? -ne 0 ]; then
 199         echo "--DIAG: $assertion: $test_FMRI1 is not online."
 200         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 201         exit $STF_FAIL
 202 fi
 203 
 204 echo "--INFO: [ Phase 5 ] Enable $test_FMRI5.
 205         $test_FMRI3 should go online; $test_FMRI1 should stay online."
 206 svcadm enable $test_FMRI5
 207 if [ $? -ne 0 ]; then
 208         echo "--DIAG: $assertion: $test_FMRI5 would not enable"
 209         exit $STF_UNRESOLVED
 210 fi
 211 
 212 service_wait_state $test_FMRI3 online
 213 if [ $? -ne 0 ]; then
 214         echo "--DIAG: $assertion: $test_FMRI3 is not online."
 215         echo "  it's in '$(svcprop -p restarter/state $test_FMRI3)' state."
 216         exit $STF_UNRESOLVED
 217 fi
 218 
 219 service_wait_state $test_FMRI1 online
 220 if [ $? -ne 0 ]; then
 221         echo "--DIAG: $assertion: $test_FMRI1 is not online."
 222         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 223         exit $STF_FAIL
 224 fi
 225 
 226 # redisable a dependency of one of the services (this should cause an offline)
 227 echo "--INFO: [ Phase 6 ] Disable $test_FMRI4.
 228         $test_FMRI2 should go offline, $test_FMRI1 should stay online"
 229 svcadm disable $test_FMRI4
 230 if [ $? -ne 0 ]; then
 231         echo "--DIAG: $assertion: could not disable $test_FMRI4"
 232         exit $STF_UNRESOLVED
 233 fi
 234 
 235 service_wait_state $test_FMRI2 offline
 236 if [ $? -ne 0 ]; then
 237         echo "--DIAG: $assertion: $test_FMRI2 is not offline."
 238         echo "  it's in '$(svcprop -p restarter/state $test_FMRI2)' state."
 239         exit $STF_UNRESOLVED
 240 fi
 241 
 242 service_wait_state $test_FMRI1 online
 243 if [ $? -ne 0 ]; then
 244         echo "--DIAG: $assertion: $test_FMRI1 is not online."
 245         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 246         exit $STF_FAIL
 247 fi
 248 
 249 # disable $test_FMRI2 ... this should restart $test_FMRI1
 250 echo "--INFO: [ Phase 7 ] Disable $test_FMRI2.
 251         $test_FMRI1 should stay online"
 252 svcadm disable $test_FMRI2
 253 if [ $? -ne 0 ]; then
 254         echo "--DIAG: $assertion: $test_FMRI2 would not disable"
 255         exit $STF_UNRESOLVED
 256 fi
 257 
 258 service_wait_state $test_FMRI1 online
 259 if [ $? -ne 0 ]; then
 260         echo "--DIAG: $assertion: $test_FMRI1 did not stay online"
 261         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 262         exit $STF_FAIL
 263 fi
 264 
 265 # Disable dependency of $test_FMRI3 - this will offline $test_FMRI1
 266 echo "--INFO: [ Phase 8 ] disable $test_FMRI5.
 267         $test_FMRI3 should go offline, $test_FMRI1 should stay offline."
 268 svcadm disable $test_FMRI5
 269 if [ $? -ne 0 ]; then
 270         echo "--DIAG: $assertion: could not disable $test_FMRI5"
 271         exit $STF_UNRESOLVED
 272 fi
 273 
 274 service_wait_state $test_FMRI3 offline
 275 if [ $? -ne 0 ]; then
 276         echo "--DIAG: $assertion: $test_FMRI3 is not offline."
 277         echo "  it's in '$(svcprop -p restarter/state $test_FMRI3)' state."
 278         exit $STF_UNRESOLVED
 279 fi
 280 
 281 service_wait_state $test_FMRI1 online
 282 if [ $? -ne 0 ]; then
 283         echo "--DIAG: $assertion: $test_FMRI1 is not online."
 284         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 285         exit $STF_FAIL
 286 fi
 287 
 288 echo "--INFO: [ Phase 9 ] Disable $test_FMRI3. $test_FMRI1 should stay online"
 289 svcadm disable $test_FMRI3
 290 if [ $? -ne 0 ]; then
 291         echo "--DIAG: $assertion: $test_FMRI3 would not disable"
 292         exit $STF_UNRESOLVED
 293 fi
 294 
 295 service_wait_state $test_FMRI1 online
 296 if [ $? -ne 0 ]; then
 297         echo "--DIAG: $assertion: $test_FMRI1 is not online"
 298         echo "  it's in '$(svcprop -p restarter/state $test_FMRI1)' state."
 299         exit $STF_FAIL
 300 fi
 301 
 302 print -- "--INFO: Cleaning up service"
 303 cleanup
 304 
 305 exit $STF_PASS