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 # 
  25 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  26 # Use is subject to license terms.
  27 #
  28 
  29 function cleanup {
  30         service_cleanup $test_service
  31         /usr/bin/rm -f $svccfg_add_script
  32 }
  33 
  34 ###############################################################################
  35 # start __stf_assertion__
  36 #
  37 # ASSERTION: svcadm_degraded_002
  38 #
  39 # DESCRIPTION:
  40 #       Calling 'svcadm -v mark degraded FMRI' where FMRI is a service 
  41 #       instance that is in the disabled state should fail with exit 1.
  42 # STRATEGY:
  43 #       - Create a service instance configuration.
  44 #       - Enable it using svcadm enable
  45 #       - Disable the service instance using svcadm disable.
  46 #       - Call svcadm mark degraded FMRI and make sure it exits 1.
  47 #       - Verify that output is null
  48 #       - Also verify it prints the message "Action degraded set for 
  49 #               $FMRI"
  50 #       - Verify state of "service instance" is unchanged from disable.
  51 #
  52 # COMMANDS: svcadm(1)
  53 #
  54 # end __stf_assertion__
  55 ################################################################################
  56 
  57 # First load up definitions of STF result variables like STF_PASS etc.
  58 . ${STF_TOOLS}/include/stf.kshlib
  59 
  60 # Load up definitions of shell functionality common to all smf sub-suites.
  61 . ${STF_SUITE}/include/gltest.kshlib
  62 . ${STF_SUITE}/include/svc.startd_config.kshlib
  63 
  64 # Define Variables
  65 readonly assertion=svcadm_degraded_002
  66 readonly ME=$(whence -p ${0})
  67 readonly MYLOC=$(dirname ${ME})
  68 readonly test_service="degraded_002$$"
  69 readonly test_instance="degraded_002$$"
  70 readonly test_fmri="svc:/$test_service:$test_instance"
  71 readonly svccfg_add_script=/var/tmp/degraded_002$$.cfg
  72 
  73 # Make sure we run as root
  74 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  75 then
  76         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  77         echo "--DIAG: [$assertion]
  78         This test must be run from root."
  79         print_result $RESULT
  80         exit $RESULT
  81 fi
  82 
  83 # Extract and print assertion information from this source script.
  84 extract_assertion_info $ME
  85 
  86 # Initialize test result to pass.
  87 typeset -i RESULT=${STF_UNRESOLVED}
  88 
  89 # Set a trap to execute the cleanup function
  90 trap cleanup 0 1 2 15
  91 
  92 # Exit code for individual commands.
  93 typeset -i tmp_rc=0
  94 
  95 # Execute environmental sanity checks.
  96 check_gl_env
  97 tmp_rc=$?
  98 if [[ $tmp_rc -ne 0 ]]
  99 then
 100         echo "--DIAG: [$assertion]
 101                 Invalid smf environment, quitting."
 102         print_result $RESULT
 103         exit $RESULT
 104 fi
 105 
 106 # Create the svccfg add script which will add entities to the
 107 # repository for this test case.
 108 
 109 echo "--INFO: [${assertion}]
 110         configure $test_service using svccfg"
 111 
 112 cat > $svccfg_add_script <<EOF
 113 add $test_service
 114 select $test_service
 115 add $test_instance
 116 EOF
 117 
 118 #
 119 # Add objects to repository
 120 echo "--INFO: [${assertion}]
 121         Adding entities <$test_service> to repository using svccfg"
 122 
 123 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 124 if [ $? -ne 0 ]; then
 125         echo "--DIAG: [$assertion]
 126         Adding entities using svccfg failed."
 127         print_result $RESULT
 128         exit $RESULT
 129 fi
 130 
 131 
 132 echo "--INFO: [${assertion}]
 133         Enable $test_fmri using svcadm enable"
 134 
 135 svcadm enable $test_fmri >/dev/null 2>&1
 136 ret=$?
 137 if [ $ret -ne 0 ]; then
 138         echo "--DIAG: [$assertion]
 139                 svcadm enable $test_service fails
 140         EXPECTED: ret = 0
 141         OBSERVED: ret = $ret"
 142         print_result $RESULT
 143         exit $RESULT
 144 fi
 145 
 146 #Wait just for sometime, let the service STATE gets updated
 147 
 148 echo "--INFO: [${assertion}]
 149         Wait for sometime to state transition gets completed"
 150 
 151 service_wait_state $test_fmri online
 152 if [ $? -ne 0 ]; then
 153         echo "--DIAG: [$assertion]
 154         <$test_fmri> is not online"
 155         print_result $RESULT
 156         exit $RESULT
 157 fi
 158 
 159 
 160 echo "--INFO: [${assertion}]
 161         Disable $test_fmri using svcadm disable"
 162 
 163 svcadm disable $test_fmri >/dev/null 2>&1
 164 ret=$?
 165 if [ $ret -ne 0 ]; then
 166         RESULT=$(update_result $STF_FAIL $RESULT)
 167         echo "--DIAG: [$assertion]
 168                 svcadm disable $test_fmri fails
 169         EXPECTED: ret = 0
 170         OBSERVED: ret = $ret"
 171         print_result $RESULT
 172         exit $RESULT
 173 fi
 174 
 175 #Wait just for sometime, let the service STATE gets updated
 176 
 177 echo "--INFO: [${assertion}]
 178         Wait for sometime to state transition gets completed"
 179 
 180 service_wait_state $test_fmri disabled
 181 if [ $? -ne 0 ]; then
 182         echo "--DIAG: [$assertion]
 183         <$test_fmri> is not disabled"
 184         print_result $RESULT
 185         exit $RESULT
 186 fi
 187 
 188 
 189 echo "--INFO: [${assertion}]
 190         Verify that service state is 'disabled'"
 191 
 192 state=`svcprop -p restarter/state $test_fmri 2>/dev/null`
 193 ret=$?
 194 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
 195         echo "--DIAG: [$assertion]
 196         EXPECTED: ret = 0; STATE= disabled
 197         OBSERVED: ret = $ret; STATE = $state"
 198         print_result $RESULT
 199         exit $RESULT
 200 fi
 201 
 202 output=`svcadm -v mark degraded $test_fmri 2>/dev/null`
 203 ret=$?
 204 if [[ $ret -ne 1 || ! -z $output ]]; then
 205         RESULT=$(update_result $STF_FAIL $RESULT)
 206         echo "--DIAG: [$assertion]
 207                 <svcadm mark degraded $test_fmri> should fail
 208         EXPECTED: ret = 1; output = <empty>
 209         OBSERVED: ret = $ret; output = $output"
 210         print_result $RESULT
 211         exit $RESULT
 212 fi
 213 
 214 echo "--INFO: [${assertion}]
 215         output = $output"
 216 
 217 echo "--INFO: [${assertion}]
 218         Verify that state = disabled"
 219 
 220 state=`svcprop -p restarter/state $test_fmri 2>/dev/null`
 221 ret=$?
 222 if [[ $ret -ne 0 || "$state" != "disabled" ]]; then
 223         RESULT=$(update_result $STF_FAIL $RESULT)
 224         echo "--DIAG: [$assertion]
 225         EXPECTED: ret = 0; STATE= disabled
 226         OBSERVED: ret = $ret; STATE = $state"
 227         print_result $RESULT
 228         exit $RESULT
 229 fi
 230 
 231 RESULT=$STF_PASS
 232 print_result $RESULT
 233 exit $RESULT