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 #This function is to cleanup the leftovers by this test
  30 
  31 function cleanup {
  32         service_cleanup $service_test
  33         /usr/bin/rm -f $svccfg_add_script
  34 }
  35 
  36 ###############################################################################
  37 # start __stf_assertion__
  38 #
  39 # ASSERTION: svcadm_enable_005
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm -v enable FMRI' where FMRI is a service instance that
  43 #       is already in the enabled state will have no effect on the service.
  44 #       A message will be sent to stdout and the exit status is 0.
  45 #
  46 # STRATEGY:
  47 #       - Check for test setup.
  48 #       - Configure a service 'foo$$' using svccfg
  49 #       - Enable it using svcadm
  50 #       - Make sure state is online.
  51 #       - Again Enable it using svcadm -v enable <FMRI>
  52 #       - Make sure it exits 0, with verbose output message saying
  53 #               "service enabled".
  54 #
  55 # COMMANDS: svcadm(1)
  56 #
  57 # end __stf_assertion__
  58 ################################################################################
  59 
  60 # First load up definitions of STF result variables like STF_PASS etc.
  61 . ${STF_TOOLS}/include/stf.kshlib
  62 
  63 # Load up definitions of shell functionality common to all smf sub-suites.
  64 . ${STF_SUITE}/include/gltest.kshlib
  65 
  66 # Define Variables
  67 readonly assertion=svcadm_enable_005
  68 readonly svccfg_add_script=/var/tmp/svcadm_enable_005.$$.config
  69 readonly service_test=foo$$
  70 readonly instance_test=instance$$
  71 readonly 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         print_result $RESULT
  95         exit $RESULT
  96 fi
  97 
  98 
  99 # Execute environmental sanity checks.
 100 check_gl_env
 101 tmp_rc=$?
 102 if [[ $tmp_rc -ne 0 ]]
 103 then
 104     echo "--DIAG: [$assertion]
 105         Invalid smf environment, quitting."
 106     print_result $RESULT
 107     exit $RESULT
 108 fi
 109 
 110 # Create the svccfg add script which will add entities to the
 111 # repository for this test case.
 112 
 113 echo "--INFO: [${assertion}]
 114         configure $fmri using svccfg"
 115 
 116 cat > $svccfg_add_script <<EOF
 117 add $service_test
 118 select $service_test
 119 add $instance_test
 120 EOF
 121 
 122 #Add objects to repository
 123 
 124 echo "--INFO: [${assertion}]
 125         Adding entities <$fmri> to repository using svccfg"
 126 
 127 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 128 if [ $? -ne 0 ]; then
 129         echo "--DIAG: [$assertion]
 130         Adding entities using svccfg failed."
 131         print_result $RESULT
 132         exit $RESULT
 133 fi
 134 
 135 echo "--INFO: [${assertion}]
 136         enable <$fmri> using svcadm"
 137 
 138 #Enable the service using svcadm
 139 /usr/sbin/svcadm enable $fmri >/dev/null 2>&1
 140 if [ $? -ne 0 ]; then
 141         echo "--DIAG: [$assertion]
 142         svcadm enable $fmri failed."
 143         print_result $RESULT
 144         exit $RESULT
 145 fi
 146 
 147 #Wait just for sometime, let the service STATE gets updated
 148 
 149 echo "--INFO: [${assertion}]
 150         Wait for sometime to state transition gets completed"
 151 
 152 service_wait_state $fmri online
 153 if [ $? -ne 0 ]; then
 154         echo "--DIAG: [$assertion]
 155         <$fmri> is not online"
 156         print_result $RESULT
 157         exit $RESULT
 158 fi
 159 
 160 echo "--INFO: [${assertion}]
 161         Verify that state = online"
 162 
 163 state=`svcprop -p restarter/state $fmri 2>/dev/null`
 164 ret=$?
 165 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 166         echo "--DIAG: [$assertion]
 167         EXPECTED: ret = 0; STATE= online
 168         ACTUAL: ret = $ret; STATE = $state"
 169         print_result $RESULT
 170         exit $RESULT
 171 fi
 172 
 173 echo "--INFO: [${assertion}]
 174         Again enable $fmri using svcadm -v enable and verify output"
 175 
 176 #Enable the service using svcadm using -v option and verify the output message.
 177 output=`/usr/sbin/svcadm -v enable $fmri 2>/dev/null`
 178 if [[ $? -ne 0 || "$output" != "$fmri enabled." ]]; then
 179         RESULT=$(update_result $STF_FAIL $RESULT)
 180         echo "--DIAG: [$assertion]
 181         svcadm -v enable $fmri failed.
 182         EXPECTED: output = $fmri enabled.
 183         ACTUAL: output = $output"
 184         print_result $RESULT
 185         exit $RESULT
 186 fi
 187 
 188 echo "--INFO: [${assertion}]
 189         Verify that state is unchanged from online"
 190 
 191 state=`svcprop -p restarter/state $fmri 2>/dev/null`
 192 ret=$?
 193 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 194         RESULT=$(update_result $STF_FAIL $RESULT)
 195         echo "--DIAG: [$assertion]
 196         EXPECTED: ret = 0; STATE= online
 197         ACTUAL: ret = $ret; STATE = $state"
 198         print_result $RESULT
 199         exit $RESULT
 200 fi
 201 
 202 
 203 echo "--INFO: [${assertion}]
 204         Assertion proved"
 205 
 206 RESULT=$STF_PASS
 207 print_result $RESULT
 208 exit $RESULT