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