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_004
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm enable FMRI' where FMRI is a service instance that is
  43 #       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 FMRI
  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_004
  66 readonly svccfg_add_script=/var/tmp/svcadm_enable_004.$$.config
  67 readonly service_test=foo$$
  68 readonly instance_test=instance$$
  69 readonly fmri=svc:/$service_test:$instance_test
  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 $fmri 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 <$fmri> 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 echo "--INFO: [${assertion}]
 134         enable <$fmri> using svcadm"
 135 
 136 #Enable the service using svcadm
 137 /usr/sbin/svcadm enable $fmri >/dev/null 2>&1
 138 if [ $? -ne 0 ]; then
 139         echo "--DIAG: [$assertion]
 140         svcadm enable $fmri failed."
 141         print_result $RESULT
 142         exit $RESULT
 143 fi
 144 
 145 #Wait just for sometime, let the service STATE gets updated
 146 
 147 echo "--INFO: [${assertion}]
 148         Wait for sometime to state transition gets completed"
 149 
 150 service_wait_state $fmri online
 151 if [ $? -ne 0 ]; then
 152         echo "--DIAG: [$assertion]
 153         <$fmri> is not online"
 154         print_result $RESULT
 155         exit $RESULT
 156 fi
 157 
 158 echo "--INFO: [${assertion}]
 159         Verify that state = online"
 160 
 161 state=`svcprop -p restarter/state $fmri 2>/dev/null`
 162 ret=$?
 163 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 164         echo "--DIAG: [$assertion]
 165         EXPECTED: ret = 0; STATE= online
 166         ACTUAL: ret = $ret; STATE = $state"
 167         print_result $RESULT
 168         exit $RESULT
 169 fi
 170 
 171 echo "--INFO: [${assertion}]
 172         Again enable $fmri"
 173 
 174 #Enable the service using svcadm
 175 /usr/sbin/svcadm enable $fmri >/dev/null 2>&1
 176 if [ $? -ne 0 ]; then
 177         RESULT=$(update_result $STF_FAIL $RESULT)
 178         echo "--DIAG: [$assertion]
 179         svcadm enable $fmri failed."
 180         print_result $RESULT
 181         exit $RESULT
 182 fi
 183 
 184 echo "--INFO: [${assertion}]
 185         Verify that state is unchanged from online"
 186 
 187 state=`svcprop -p restarter/state $fmri 2>/dev/null`
 188 ret=$?
 189 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 190         RESULT=$(update_result $STF_FAIL $RESULT)
 191         echo "--DIAG: [$assertion]
 192         EXPECTED: ret = 0; STATE= online
 193         ACTUAL: ret = $ret; STATE = $state"
 194         print_result $RESULT
 195         exit $RESULT
 196 fi
 197 
 198 echo "--INFO: [${assertion}]
 199         Assertion proved"
 200 
 201 RESULT=$STF_PASS
 202 print_result $RESULT
 203 exit $RESULT