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_002
  32 #
  33 # DESCRIPTION:
  34 #       Calling 'svcadm -v refresh FMRI' over FMRI currently in enabled state
  35 #       should not stop (or) start the service(s)/process(es) associated
  36 #       with those services.
  37 #
  38 # STRATEGY:
  39 #       - Create a service bundle for a test instance with a start method that
  40 #         executes another process containing an infinite loop.
  41 #       - Import the xml using svccfg import <.xml>
  42 #       - Verify that the test instance was enabled on import.
  43 #       - Call svcadm -v refresh <FMRI>.
  44 #       - Verify svcadm exited with 0.
  45 #       - Also verify the infinite process keeps running, and is not restarted.
  46 #
  47 # COMMANDS: svcadm(1)
  48 #
  49 # end __stf_assertion__
  50 ################################################################################
  51 
  52 # First load up definitions of STF result variables like STF_PASS etc.
  53 . ${STF_TOOLS}/include/stf.kshlib
  54 
  55 # Load up definitions of shell functionality common to all smf sub-suites.
  56 . ${STF_SUITE}/include/gltest.kshlib
  57 . ${STF_SUITE}/include/svc.startd_config.kshlib
  58 
  59 # Load up the common utility functions for tests in this directory
  60 . ${STF_SUITE}/${STF_EXEC}/functions.kshlib
  61 
  62 # Define the cleanup function for this test
  63 function cleanup {
  64         cleanup_leftovers $refresh_test_service $registration_file \
  65                 /var/tmp/$refresh_test_process /var/tmp/testfoo.$$
  66         print_result $RESULT
  67 }
  68 
  69 # Define Variables
  70 readonly assertion=svcadm_refresh_002
  71 readonly ME=$(whence -p ${0})
  72 readonly MYLOC=$(dirname ${ME})
  73 readonly registration_template=${STF_SUITE}/tests/svcadm/refresh/template.xml
  74 readonly registration_file=/var/tmp/svcadm_refresh_002.$$.xml
  75 readonly refresh_test_service="refresh_002$$"
  76 readonly refresh_test_instance="refresh_002$$"
  77 readonly start_method=refresh_002.$$
  78 readonly start_file=/var/tmp/svcadm_${start_method}.startfile
  79 readonly refresh_test_process=testfoo_002
  80 readonly refresh_test_fmri="svc:/$refresh_test_service:$refresh_test_instance"
  81 typeset -i pid=0
  82 
  83 # Make sure we run as root
  84 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  85 then
  86         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  87         echo "--DIAG: [$assertion]
  88         This test must be run from root."
  89         exit $RESULT
  90 fi
  91 
  92 # Extract and print the assertion info from this source script.
  93 extract_assertion_info $ME
  94 
  95 # Initialize test result to pass.
  96 typeset -i RESULT=${STF_UNRESOLVED}
  97 
  98 # Set a trap to execute the cleanup function
  99 trap cleanup 0 1 2 15
 100 
 101 # Exit code for individual commands.
 102 typeset -i tmp_rc=0
 103 
 104 # Execute environmental sanity checks.
 105 check_gl_env
 106 tmp_rc=$?
 107 if [[ $tmp_rc -ne 0 ]]
 108 then
 109         echo "--DIAG: [$assertion]
 110         Invalid smf environment, quitting."
 111         print_result $RESULT
 112         exit $RESULT
 113 fi
 114 
 115 echo "--INFO: [$assertion]
 116         Verify that registration template $registration_template exists"
 117 
 118 if [ ! -s $registration_template ]; then
 119         echo "--DIAG: [$assertion]
 120         $registration_template not found"
 121         print_result $RESULT
 122         exit $RESULT
 123 fi
 124 
 125 echo "--INFO: [$assertion]
 126         Create test start method: /var/tmp/$start_method"
 127 
 128 cat > /var/tmp/$start_method <<-EOF
 129 #!/bin/ksh -p
 130 /bin/cp /dev/null $start_file >/dev/null 2>&1
 131 cat > /var/tmp/$refresh_test_process <<-EOT
 132 #!/bin/ksh -p
 133 while :; do echo "1" > /dev/null; done
 134 exit 0
 135 EOT
 136 chmod +x /var/tmp/$refresh_test_process
 137 /var/tmp/$refresh_test_process &
 138 exit 0
 139 EOF
 140 
 141 echo "--INFO: [$assertion]
 142         chmod 755 /var/tmp/$start_method"
 143 
 144 chmod 755 /var/tmp/$start_method
 145 if [ $? -ne 0 ]; then
 146         echo "--DIAG: [$assertion]
 147         chmod 755 /var/tmp/$refresh_test_process failed"
 148         print_result $RESULT
 149         exit $RESULT
 150 fi
 151 
 152 echo "--INFO: [$assertion]
 153         Generate .xml required for this test"
 154 
 155 manifest_generate $registration_template \
 156         TEST_SERVICE=$refresh_test_service \
 157         TEST_INSTANCE=$refresh_test_instance \
 158         START_NAME=/var/tmp/$start_method \
 159         STOP_NAME=":kill" \
 160         SERVICE_APP=$service_app \
 161         STATEFILE=$service_state > $registration_file
 162 
 163 echo "--INFO: [$assertion]
 164         Verify registration template was created and size > 0 bytes"
 165 
 166 if [ ! -s $registration_file ]; then
 167         echo "--DIAG: [$assertion]
 168         $registration_file does not exist or has size = 0 bytes"
 169         print_result $RESULT
 170         exit $RESULT
 171 fi
 172 
 173 echo "--INFO: [$assertion]
 174         Import the service to repository using svccfg import"
 175 
 176 svccfg import $registration_file > $svccfg_errfile 2>&1
 177 if [ $? -ne 0 ]; then
 178         echo "--DIAG: [$assertion]
 179         Unable to import the service $refresh_test_fmri
 180         error messages from svccfg: \"$(cat $svccfg_errfile)\""
 181         print_result $RESULT
 182         exit $RESULT
 183 fi
 184 
 185 echo "--INFO: [$assertion]
 186         Imported FMRI is: $refresh_test_fmri"
 187 
 188 # Import should automatically enable the service
 189 echo "--INFO: [$assertion]
 190         Wait until $start_process is triggered"
 191 
 192 wait_process_start 2>/dev/null
 193 if [ $? -ne 0 ]; then
 194         echo "--DIAG: [$assertion]
 195         $start_process was not triggered upon import"
 196         print_result $RESULT
 197         exit $RESULT
 198 fi
 199 
 200 pid=`pgrep -f ${refresh_test_process}`
 201 if [[ $? -ne 0 || -z $pid ]]; then
 202         echo "--DIAG: [$assertion]
 203         Could not determine pid of $start_method"
 204         print_result $RESULT
 205         exit $RESULT
 206 fi
 207 
 208 echo "--INFO: [$assertion]
 209         svcs -p <FMRI> and make sure $pid is printed"
 210 output="`svcs -p $refresh_test_fmri | grep $pid | \
 211         awk '{ print $2 }' 2>/dev/null`"
 212 if [[ $? -ne 0 || "$output" != "$pid" ]]; then
 213         echo "--DIAG: [$assertion]
 214         svcs -p $refresh_test_fmri | grep $pid | awk '{ print \$2 }' failed
 215         EXPECTED: output = $pid
 216         OBSERVED: output = $output"
 217         print_result $RESULT
 218         exit $RESULT
 219 fi
 220 
 221 #
 222 # VERIFY ASSERTION
 223 #
 224 echo "--INFO: [${assertion}]
 225         refresh <$refresh_test_fmri> using svcadm"
 226 
 227 output=`svcadm -v refresh $refresh_test_fmri 2>/dev/null`
 228 ret=$?
 229 exp_out="Action refresh set for $refresh_test_fmri."
 230 if [[ $ret -ne 0 || "$output" != "$exp_out" ]]; then
 231         RESULT=$(update_result $STF_FAIL $RESULT)
 232         echo "--DIAG: [$assertion]
 233                 svcadm -v refresh $refresh_test_fmri fails
 234         EXPECTED: ret = 0; output = $exp_out
 235         OBSERVED: ret = $ret; output = $output"
 236         exit $RESULT
 237 fi
 238 
 239 echo "--INFO: [${assertion}]
 240         output = $output"
 241 
 242 echo "--INFO: [${assertion}]
 243         Make sure process is still running; Verify $pid is unchanged"
 244 
 245 svcs -p $refresh_test_fmri | grep $pid >/dev/null 2>&1
 246 if [ $? -ne 0 ]; then
 247         RESULT=$(update_result $STF_FAIL $RESULT)
 248         echo "--DIAG: [$assertion]
 249         EXPECTED: process with pid $pid exists on system
 250         OBSERVED: no process with pid $pid is running"
 251         exit $RESULT
 252 fi
 253 
 254 RESULT=$STF_PASS
 255 print_result $RESULT
 256 exit $RESULT
 257 
 258 #
 259 ### END
 260 #