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_003
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm enable FMRI' where FMRI is a service instance that is
  43 #       disabled state will result in the service being started and
  44 #       transitioned into the enabled state.  The exit status shall be 0.
  45 # STRATEGY:
  46 #       - Check for test setup.
  47 #       - Configure a service 'foo$$' using svccfg
  48 #       - Disable it using svcadm
  49 #       - Make sure state is disabled.
  50 #       - Now enable the service using svcadm enable
  51 #       - Verify that exit status of above step is 0.
  52 #       - Also verify that state is transitioned to online.
  53 #
  54 # COMMANDS: svcadm(1)
  55 #
  56 # end __stf_assertion__
  57 ################################################################################
  58 
  59 # First load up definitions of STF result variables like STF_PASS etc.
  60 . ${STF_TOOLS}/include/stf.kshlib
  61 
  62 # Load up definitions of shell functionality common to all smf sub-suites.
  63 . ${STF_SUITE}/include/gltest.kshlib
  64 
  65 # Define Variables
  66 readonly assertion=svcadm_enable_003
  67 readonly svccfg_add_script=/var/tmp/svcadm_enable_003.$$.config
  68 readonly service_test=foo$$
  69 readonly instance_test=instance$$
  70 readonly ME=$(whence -p ${0})
  71 readonly MYLOC=$(dirname ${ME})
  72 
  73 # gltest.kshlib functions to extract and print assertion information
  74 # from this source script.
  75 extract_assertion_info $ME
  76 
  77 # Initialize test result to pass.
  78 typeset -i RESULT=${STF_UNRESOLVED}
  79 
  80 # Set a trap to execute the cleanup function when specified signals
  81 # are received.
  82 trap cleanup 0 1 2 15
  83 
  84 # Exit code for individual commands.
  85 typeset -i tmp_rc=0
  86 
  87 # Make sure we run as root
  88 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  89 then
  90         echo "--DIAG: [$assertion]
  91         This test must be run from root."
  92         print_result $RESULT
  93         exit $RESULT
  94 fi
  95 
  96 
  97 # Execute environmental sanity checks.
  98 check_gl_env
  99 tmp_rc=$?
 100 if [[ $tmp_rc -ne 0 ]]
 101 then
 102     echo "--DIAG: [$assertion]
 103         Invalid smf environment, quitting."
 104     print_result $RESULT
 105     exit $RESULT
 106 fi
 107 
 108 # Create the svccfg add script which will add entities to the
 109 # repository for this test case.
 110 
 111 echo "--INFO: [${assertion}]
 112         configure $service_test using svccfg"
 113 
 114 cat > $svccfg_add_script <<EOF
 115 add $service_test
 116 select $service_test
 117 add $instance_test
 118 EOF
 119 
 120 #Add objects to repository
 121 
 122 echo "--INFO: [${assertion}]
 123         Adding entities <$service_test> to repository using svccfg"
 124 
 125 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 126 if [ $? -ne 0 ]; then
 127         echo "--DIAG: [$assertion]
 128         Adding entities using svccfg failed."
 129         print_result $RESULT
 130         exit $RESULT
 131 fi
 132 
 133 
 134 echo "--INFO: [${assertion}]
 135         enable <$service_test> using svcadm"
 136 
 137 #Enable the service using svcadm
 138 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 139 if [ $? -ne 0 ]; then
 140         echo "--DIAG: [$assertion]
 141         svcadm enable $service_test failed."
 142         print_result $RESULT
 143         exit $RESULT
 144 fi
 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 
 158 echo "--INFO: [${assertion}]
 159         disable $service_test using svcadm"
 160 
 161 #Disable the service using svcadm
 162 /usr/sbin/svcadm disable $service_test >/dev/null 2>&1
 163 ret=$?
 164 if [ $ret -ne 0 ]; then
 165         echo "--DIAG: [$assertion]
 166         svcadm disable $service_test failed.
 167         EXPECTED: ret = 0
 168         ACTUAL: ret = $ret"
 169         print_result $RESULT
 170         exit $RESULT
 171 fi
 172 
 173 echo "--INFO: [${assertion}]
 174         Wait until state transition gets completed"
 175 
 176 service_wait_state $service_test:$instance_test disabled
 177 if [ $? -ne 0 ]; then
 178         echo "--DIAG: [$assertion]
 179         <$service_test> is not disabled"
 180         print_result $RESULT
 181         exit $RESULT
 182 fi
 183 
 184 echo "--INFO: [${assertion}]
 185         enable <$service_test> using svcadm"
 186 
 187 #Enable the service using svcadm
 188 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 189 if [ $? -ne 0 ]; then
 190         RESULT=$(update_result $STF_FAIL $RESULT)
 191         echo "--DIAG: [$assertion]
 192         svcadm enable $service_test failed."
 193         print_result $RESULT
 194         exit $RESULT
 195 fi
 196 
 197 echo "--INFO: [${assertion}]
 198         Wait until state transition gets completed"
 199 
 200 service_wait_state $service_test:$instance_test online
 201 if [ $? -ne 0 ]; then
 202         RESULT=$(update_result $STF_FAIL $RESULT)
 203         echo "--DIAG: [$assertion]
 204         <$service_test> is not online"
 205         print_result $RESULT
 206         exit $RESULT
 207 fi
 208 
 209 echo "--INFO: [${assertion}]
 210         Assertion proved"
 211 
 212 RESULT=$STF_PASS
 213 print_result $RESULT
 214 exit $RESULT