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_047
  32 # DESCRIPTION:
  33 #  A service with a dependency of optional_all will stay online even if
  34 #  that dependency is enabled, but in maintenance 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_047.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         SERVICE_APP=$service_app \
  83         LOGFILE=$service_log \
  84         STATEFILE1=$service_state1 \
  85         STATEFILE2=$service_state2 \
  86         > $registration_file
  87 
  88 echo "--INFO: Importing service into repository"
  89 manifest_purgemd5 $registration_file
  90 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  91 
  92 if [ $? -ne 0 ]; then
  93         echo "--DIAG: $assertion: Unable to import $test_service."
  94         echo "  Error messages from svccfg: "
  95         echo "  \"$(cat $svccfg_errfile)\""
  96         exit $STF_UNRESOLVED
  97 fi
  98 service_setup=1
  99 
 100 print -- "--INFO: List service dependencies"
 101 for svc in $test_FMRI1 $test_FMRI2; do
 102         svcs -l $svc | grep ^[fd]
 103         print " "
 104 done
 105 
 106 echo "--INFO: Ensuring $test_FMRI1 comes online"
 107 service_wait_state $test_FMRI1 online
 108 if [ $? -ne 0 ]; then
 109         echo "--DIAG: $assertion: Service $test_FMRI1 didn't come online"
 110         exit $STF_UNRESOLVED
 111 fi
 112 
 113 echo "--INFO: Transition dependency $test_FMRI2 to maintenance"
 114 svcadm mark maintenance $test_FMRI2
 115 if [ $? -ne 0 ]; then
 116         echo "--DIAG: $assertion: service $test_FMRI2 could not be set to"
 117         echo "  maintenance mode."
 118         exit $STF_UNRESOLVED
 119 fi
 120 service_wait_state $test_FMRI2 maintenance
 121 if [ $? -ne 0 ]; then
 122         echo "--DIAG: $assertion: Service $test_FMRI2 wasn't in maintenance"
 123         exit $STF_UNRESOLVED
 124 fi
 125 
 126 
 127 
 128 echo "--INFO: Checking that $test_FMRI1 is still online"
 129 service_wait_state $test_FMRI1 online
 130 if [ $? -ne 0 ]; then
 131         echo "--DIAG: $assertion: Service $test_FMRI1 is not online"
 132         echo "  It is in '$(svcprop -p restarter/state $test_FMRI1)' state,"
 133         echo "  $test_FMRI2 is in '$(svcprop -p restarter/state $test_FMRI2)'
 134         state."
 135         exit $STF_FAIL
 136 fi
 137 
 138 echo "--INFO: Clear maintenance state of $test_FMRI2"
 139 svcadm clear $test_FMRI2
 140 if [ $? -ne 0 ]; then
 141         echo "--DIAG: $assertion: could not clear maintenance of $test_FMRI2"
 142         echo "  It is in '$(svcprop -p restarter/state $test_FMRI2)' state,"
 143         exit $STF_UNRESOLVED
 144 fi
 145 
 146 echo "--INFO: wait for $test_FMRI2 to come online"
 147 service_wait_state $test_FMRI2 online
 148 if [ $? -ne 0 ]; then
 149         echo "--DIAG: $assertion: Service $test_FMRI2 didn't come online"
 150         exit $STF_UNRESOLVED
 151 fi
 152 
 153 service_wait_state $test_FMRI1 online
 154 if [ $? -ne 0 ]; then
 155         echo "--DIAG: $assertion: Service $test_FMRI1 didn't stay online"
 156         echo "  It is in '$(svcprop -p restarter/state $test_FMRI1)' state"
 157         exit $STF_FAIL
 158 fi
 159 
 160 echo "--INFO: Cleaning up service"
 161 cleanup
 162 
 163 exit $STF_PASS