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: svcadm_disable_002
  32 #
  33 # DESCRIPTION:
  34 #       Calling  'svcadm -v disable FMRI' where FMRI is a service instance
  35 #       that is already in the disabled state will have no effect on the
  36 #       service. A message will be sent to stdout and the exit status will
  37 #       be 0.
  38 # STRATEGY:
  39 #       - Check for test setup.
  40 #       - Configure a service 'foo$$' using svccfg
  41 #       - Enable it using svcadm
  42 #       - Disable it using "svcadm disable service"
  43 #       - Using svcprop make sure 'foo$$' has STATE disabled
  44 #       - Again attempt to disable it using "svcadm -v disable service"
  45 #       - Make sure exit status is 0.
  46 #       - Also verify 'stdout message' saying "$service already disabled"
  47 #
  48 # COMMANDS: svcadm(1)
  49 #
  50 # end __stf_assertion__
  51 ################################################################################
  52 
  53 # First load up definitions of STF result variables like STF_PASS etc.
  54 . ${STF_TOOLS}/include/stf.kshlib
  55 
  56 # Load up definitions of shell functionality common to all smf sub-suites.
  57 . ${STF_SUITE}/include/gltest.kshlib
  58 
  59 # Define the cleanup function for this test
  60 function cleanup {
  61         service_cleanup $service_test
  62         /usr/bin/rm -f $svccfg_add_script
  63         print_result $RESULT
  64 }
  65 
  66 # Define Variables
  67 readonly assertion=svcadm_disable_002
  68 readonly svccfg_add_script=/var/tmp/svcadm_disable_002.$$.config
  69 readonly service_test=foo$$
  70 readonly instance_test=instance$$
  71 readonly target_fmri="svc:/${service_test}:${instance_test}"
  72 readonly ME=$(whence -p ${0})
  73 readonly MYLOC=$(dirname ${ME})
  74 
  75 # gltest.kshlib functions to extract and print assertion information
  76 # from this source script.
  77 extract_assertion_info $ME
  78 
  79 # Initialize test result to pass.
  80 typeset -i RESULT=${STF_UNRESOLVED}
  81 
  82 # Set a trap to execute the cleanup function when specified signals
  83 # are received.
  84 trap cleanup 0 1 2 15
  85 
  86 # Exit code for individual commands.
  87 typeset -i tmp_rc=0
  88 
  89 # Make sure we run as root
  90 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  91 then
  92         echo "--DIAG: [$assertion]
  93         This test must be run from root."
  94         exit $RESULT
  95 fi
  96 
  97 
  98 # Execute environmental sanity checks.
  99 check_gl_env
 100 tmp_rc=$?
 101 if [[ $tmp_rc -ne 0 ]]
 102 then
 103     echo "--DIAG: [$assertion]
 104         Invalid smf environment, quitting."
 105     exit $RESULT
 106 fi
 107 
 108 # Create the svccfg add script which will add entities to the
 109 # repository for this test case.
 110 
 111 echo "--INFO: [${assertion}]
 112         configure $service_test using svccfg"
 113 
 114 cat > $svccfg_add_script <<EOF
 115 add $service_test
 116 select $service_test
 117 add $instance_test
 118 EOF
 119 
 120 #Add objects to repository
 121 
 122 echo "--INFO: [${assertion}]
 123         Add entities to repository using svccfg
 124                 <$service_test>
 125                 <${service_test}:${instance_test}>"
 126 
 127 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 128 ret=$?
 129 if [ $ret -ne 0 ]; then
 130         echo "--DIAG: [$assertion]
 131         Adding entities using svccfg failed.
 132         EXPECTED: ret = 0
 133         OBSERVED: ret = $ret"
 134         exit $RESULT
 135 fi
 136 
 137 echo "--INFO: [${assertion}]
 138         enable <$service_test> using svcadm"
 139 
 140 # Enable the service using svcadm
 141 svcadm enable $service_test >/dev/null 2>&1
 142 ret=$?
 143 if [ $ret -ne 0 ]; then
 144         echo "--DIAG: [$assertion]
 145         svcadm enable $service_test failed.
 146         EXPECTED: ret = 0
 147         OBSERVED: ret = $ret"
 148         exit $RESULT
 149 fi
 150 
 151 # Wait until the service state transition is complete
 152 echo "--INFO: [${assertion}]
 153         Wait until state transition gets completed"
 154 
 155 service_wait_state $target_fmri online
 156 if [ $? -ne 0 ]; then
 157         echo "--DIAG: [$assertion]
 158         <$target_fmri> is not online"
 159         exit $RESULT
 160 fi
 161 
 162 echo "--INFO: [${assertion}]
 163         disable $service_test using svcadm"
 164 
 165 # Disable the service using svcadm
 166 svcadm disable $service_test >/dev/null 2>&1
 167 ret=$?
 168 if [ $ret -ne 0 ]; then
 169         echo "--DIAG: [$assertion]
 170         svcadm disable $service_test failed.
 171         EXPECTED: ret = 0
 172         OBSERVED: ret = $ret"
 173         exit $RESULT
 174 fi
 175 
 176 echo "--INFO: [${assertion}]
 177         Wait until state transition gets completed"
 178 
 179 service_wait_state $target_fmri disabled
 180 if [ $? -ne 0 ]; then
 181         state=`svcprop -p restarter/state $target_fmri 2>/dev/null`
 182         echo "--DIAG: [$assertion]
 183         EXPECTED: STATE= disabled
 184         OBSERVED: STATE = $state"
 185         exit $RESULT
 186 fi
 187 
 188 echo "--INFO: [${assertion}]
 189         VERIFY ASSERTION: attempt to disable again"
 190 
 191 output=`svcadm -v disable $service_test 2>/dev/null` 
 192 ret=$?
 193 exp_out="$target_fmri disabled."
 194 if [[ $ret -ne 0 || "$output" != "$exp_out" ]]; then
 195         RESULT=$(update_result $STF_FAIL $RESULT)
 196         echo "--DIAG: [$assertion]
 197         svcadm -v disable $service_test (already disabled) failed.
 198         EXPECTED: ret = 0; output: $exp_out
 199         OBSERVED: ret = $ret and output: = $output"
 200         exit $RESULT
 201 fi
 202 
 203 echo "--INFO: [${assertion}]
 204         Assertion proved"
 205 
 206 RESULT=$STF_PASS
 207 print_result $RESULT
 208 exit $RESULT
 209 
 210 #
 211 ### END
 212 #