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_045
  32 # DESCRIPTION:
  33 #  A service with a single dependency of optional_all will transition to
  34 #  online state even if the optional_all dependency is in the offline state.
  35 #
  36 # end __stf_assertion__
  37 #
  38 
  39 . ${STF_TOOLS}/include/stf.kshlib
  40 . ${STF_SUITE}/include/gltest.kshlib
  41 . ${STF_SUITE}/include/svc.startd_config.kshlib
  42 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  43 
  44 typeset service_setup=0
  45 function cleanup {
  46         common_cleanup
  47         rm -f $service_state1 $service_state2 $service_state3
  48 }
  49 
  50 trap cleanup 0 1 2 15
  51 
  52 readonly ME=$(whence -p ${0})
  53 readonly MYLOC=$(dirname ${ME})
  54 
  55 DATA=$MYLOC
  56 
  57 readonly registration_template=$DATA/service_045.xml
  58 
  59 extract_assertion_info $ME
  60 
  61 # make sure that the svc.startd is running
  62 verify_daemon
  63 if [ $? -ne 0 ]; then
  64         echo "--DIAG: $assertion: svc.startd is not executing. Cannot "
  65         echo "  continue"
  66         exit $STF_UNRESOLVED
  67 fi
  68 
  69 # Make sure the environment is clean - the test service isn't running
  70 echo "--INFO: Cleanup any old $test_service state"
  71 service_cleanup $test_service
  72 if [ $? -ne 0 ]; then
  73         echo "--DIAG: $assertion: cleanup of a previous instance failed"
  74         exit $STF_UNRESOLVED
  75 fi
  76 
  77 echo "--INFO: generating manifest for importation into repository"
  78 manifest_generate $registration_template \
  79         TEST_SERVICE=$test_service \
  80         TEST_INSTANCE1=$test_instance1 \
  81         TEST_INSTANCE2=$test_instance2 \
  82         TEST_INSTANCE3=$test_instance3 \
  83         SERVICE_APP=$service_app \
  84         LOGFILE=$service_log \
  85         STATEFILE1=$service_state1 \
  86         STATEFILE2=$service_state2 \
  87         STATEFILE3=$service_state3 \
  88         > $registration_file
  89 
  90 echo "--INFO: Importing service into repository"
  91 manifest_purgemd5 $registration_file
  92 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  93 
  94 if [ $? -ne 0 ]; then
  95         echo "--DIAG: $assertion: Unable to import $test_service."
  96         echo "  Error messages from svccfg: "
  97         echo "  \"$(cat $svccfg_errfile)\""
  98         exit $STF_UNRESOLVED
  99 fi
 100 service_setup=1
 101 
 102 echo "--INFO: List service dependencies"
 103 for svc in $test_FMRI1 $test_FMRI2 $test_FMRI3; do
 104         svcs -l $svc | grep ^[fd]
 105         echo " "
 106 done
 107 
 108 echo "--INFO: Verifying $test_FMRI1 transitions to online state"
 109 service_wait_state $test_FMRI1 online
 110 if [ $? -ne 0 ]; then
 111         echo "--DIAG: $assertion: Service $test_FMRI1 is not online
 112         Current state: $(svcprop -p restarter/state $test_FMRI1)"
 113         exit $STF_FAIL
 114 fi
 115 
 116 typeset -i rc=0
 117 echo "--INFO: [ Phase 1 ] Enable $test_FMRI3.
 118         This should transition $test_FMRI2 to online state"
 119 svcadm enable $test_FMRI3
 120 rc=$?
 121 if [ $rc -ne 0 ]; then
 122         echo "--DIAG: $assertion: svcadm enable $test_FMRI3 failed
 123         EXPECTED: return 0
 124         OBSERVED: return $rc"
 125         exit $STF_UNRESOLVED
 126 fi
 127 
 128 echo "--INFO: Verify $test_FMRI2 is online"
 129 service_wait_state $test_FMRI2 online
 130 if [ $? -ne 0 ]; then
 131         echo "--DIAG: $assertion: Service $test_FMRI2 is not online
 132         Current state: $(svcprop -p restarter/state $test_FMRI2)"
 133         exit $STF_UNRESOLVED
 134 fi
 135 
 136 echo "--INFO: Verify $test_FMRI1 is still online"
 137 service_wait_state $test_FMRI1 online
 138 if [ $? -ne 0 ]; then
 139         echo "--DIAG: $assertion: Service $test_FMRI1 is not online
 140         Current state: $(svcprop -p restarter/state $test_FMRI1)"
 141         exit $STF_FAIL
 142 fi
 143 
 144 echo "--INFO: [ Phase 2 ] disable $test_FMRI3.
 145         This should transition $test_FMRI2 to offline state"
 146 svcadm disable $test_FMRI3
 147 rc=$?
 148 if [ $rc -ne 0 ]; then
 149         echo "--DIAG: $assertion: svcadm disable $test_FMRI3 -- failed
 150         EXPECTED: return 0
 151         OBSERVED: return $rc"
 152         exit $STF_UNRESOLVED
 153 fi
 154 
 155 echo "--INFO: Verify $test_FMRI2 is offline"
 156 service_wait_state $test_FMRI2 offline
 157 if [ $? -ne 0 ]; then
 158         echo "--DIAG: $assertion: Service $test_FMRI2 is not offline
 159         Current state: $(svcprop -p restarter/state $test_FMRI2)"
 160         exit $STF_UNRESOLVED
 161 fi
 162 
 163 echo "--INFO: Verify $test_FMRI1 is still online"
 164 service_wait_state $test_FMRI1 online
 165 if [ $? -ne 0 ]; then
 166         echo "--DIAG: $assertion: Service $test_FMRI1 is not online
 167         Current state: $(svcprop -p restarter/state $test_FMRI1)"
 168         exit $STF_FAIL
 169 fi
 170 
 171 echo "--INFO: [ Phase 3 ] disable $test_FMRI2.
 172         $test_FMRI1 should stay online"
 173 svcadm disable $test_FMRI2
 174 rc=$?
 175 if [ $rc -ne 0 ]; then
 176         echo "--DIAG: $assertion: svcadm disable $test_FMRI2 -- failed
 177         EXPECTED: return 0
 178         OBSERVED: return $rc"
 179         exit $STF_UNRESOLVED
 180 fi
 181 
 182 echo "--INFO: Verify $test_FMRI1 is online"
 183 service_wait_state $test_FMRI1 online
 184 if [ $? -ne 0 ]; then
 185         echo "--DIAG: $assertion: Service $test_FMRI1 is not online
 186         Current state: $(svcprop -p restarter/state $test_FMRI1)"
 187         exit $STF_FAIL
 188 fi
 189 
 190 echo "--INFO: Cleaning up services"
 191 cleanup
 192 
 193 exit $STF_PASS