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_001
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm enable <service>' where service is a service instance 
  43 #       that is already in the enabled state will have no effect on the service.
  44 #       The exit status is 0.
  45 # STRATEGY:
  46 #       - Check for test setup.
  47 #       - Configure a service 'foo$$' using svccfg
  48 #       - Enable it using svcadm
  49 #       - Make sure state is online.
  50 #       - Again Enable it using svcadm enable <service>
  51 #       - Make sure it exits 0, state unchanged from online.
  52 #
  53 # COMMANDS: svcadm(1)
  54 #
  55 # end __stf_assertion__
  56 ################################################################################
  57 
  58 # First load up definitions of STF result variables like STF_PASS etc.
  59 . ${STF_TOOLS}/include/stf.kshlib
  60 
  61 # Load up definitions of shell functionality common to all smf sub-suites.
  62 . ${STF_SUITE}/include/gltest.kshlib
  63 
  64 # Define Variables
  65 readonly assertion=svcadm_enable_001
  66 readonly svccfg_add_script=/var/tmp/svcadm_enable_001.$$.config
  67 readonly service_test=foo$$
  68 readonly instance_test=instance$$
  69 readonly ME=$(whence -p ${0})
  70 readonly MYLOC=$(dirname ${ME})
  71 
  72 # gltest.kshlib functions to extract and print assertion information
  73 # from this source script.
  74 extract_assertion_info $ME
  75 
  76 # Initialize test result to pass.
  77 typeset -i RESULT=${STF_UNRESOLVED}
  78 
  79 # Set a trap to execute the cleanup function when specified signals
  80 # are received.
  81 trap cleanup 0 1 2 15
  82 
  83 # Exit code for individual commands.
  84 typeset -i tmp_rc=0
  85 
  86 # Make sure we run as root
  87 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  88 then
  89         echo "--DIAG: [$assertion]
  90         This test must be run from root."
  91         print_result $RESULT
  92         exit $RESULT
  93 fi
  94 
  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     print_result $RESULT
 104     exit $RESULT
 105 fi
 106 
 107 # Create the svccfg add script which will add entities to the
 108 # repository for this test case.
 109 
 110 echo "--INFO: [${assertion}]
 111         configure $service_test using svccfg"
 112 
 113 cat > $svccfg_add_script <<EOF
 114 add $service_test
 115 select $service_test
 116 add $instance_test
 117 EOF
 118 
 119 #Add objects to repository
 120 
 121 echo "--INFO: [${assertion}]
 122         Adding entities <$service_test> to repository using svccfg"
 123 
 124 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 125 if [ $? -ne 0 ]; then
 126         echo "--DIAG: [$assertion]
 127         Adding entities using svccfg failed."
 128         print_result $RESULT
 129         exit $RESULT
 130 fi
 131 
 132 echo "--INFO: [${assertion}]
 133         enable <$service_test> using svcadm"
 134 
 135 #Enable the service using svcadm
 136 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 137 if [ $? -ne 0 ]; then
 138         echo "--DIAG: [$assertion]
 139         svcadm enable $service_test failed."
 140         print_result $RESULT
 141         exit $RESULT
 142 fi
 143 
 144 #Wait just for sometime, let the service STATE gets updated
 145 
 146 echo "--INFO: [${assertion}]
 147         Wait until state transition gets completed"
 148 
 149 service_wait_state $service_test:$instance_test online
 150 if [ $? -ne 0 ]; then
 151         echo "--DIAG: [$assertion]
 152         <$service_test> is not online"
 153         print_result $RESULT
 154         exit $RESULT
 155 fi
 156 
 157 echo "--INFO: [${assertion}]
 158         Again enable $service_test"
 159 
 160 #Enable the service using svcadm
 161 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 162 if [ $? -ne 0 ]; then
 163         RESULT=$(update_result $STF_FAIL $RESULT)
 164         echo "--DIAG: [$assertion]
 165         svcadm enable $service_test failed."
 166         print_result $RESULT
 167         exit $RESULT
 168 fi
 169 
 170 echo "--INFO: [${assertion}]
 171         Verify that state is unchanged from online"
 172 
 173 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
 174 ret=$?
 175 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 176         RESULT=$(update_result $STF_FAIL $RESULT)
 177         echo "--DIAG: [$assertion]
 178         EXPECTED: ret = 0; STATE= online
 179         ACTUAL: ret = $ret; STATE = $state"
 180         print_result $RESULT
 181         exit $RESULT
 182 fi
 183 
 184 
 185 echo "--INFO: [${assertion}]
 186         Assertion proved"
 187 
 188 RESULT=$STF_PASS
 189 print_result $RESULT
 190 exit $RESULT