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