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_delegate_004
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm delegate <invalid restarter> <online service>' where 
  43 #       service is a service instance that isalready in the enabled state 
  44 #       should fail and exit 1.
  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 #       - Call svcadm delegate <invalid restarter> <online service>
  51 #       - Verify above step exits 1.
  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_delegate_004
  66 readonly svccfg_add_script=/var/tmp/svcadm_delegate_004.$$.config
  67 readonly service_test=foo$$
  68 readonly instance_test=instance$$
  69 readonly invalid_restarter="svc:/invalid_fmri"
  70 readonly valid_fmri="svc:/$service_test:$instance_test"
  71 readonly ME=$(whence -p ${0})
  72 readonly MYLOC=$(dirname ${ME})
  73 
  74 # gltest.kshlib functions to extract and print assertion information
  75 # from this source script.
  76 extract_assertion_info $ME
  77 
  78 # Initialize test result to pass.
  79 typeset -i RESULT=${STF_PASS}
  80 
  81 # Set a trap to execute the cleanup function when specified signals
  82 # are received.
  83 trap cleanup 0 1 2 15
  84 
  85 # Exit code for individual commands.
  86 typeset -i tmp_rc=0
  87 
  88 # Make sure we run as root
  89 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  90 then
  91         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  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     RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 105     echo "--DIAG: [$assertion]
 106         Invalid smf environment, quitting."
 107     print_result $RESULT
 108     exit $RESULT
 109 fi
 110 
 111 # Create the svccfg add script which will add entities to the
 112 # repository for this test case.
 113 
 114 echo "--INFO: [${assertion}]
 115         configure $service_test using svccfg"
 116 
 117 cat > $svccfg_add_script <<EOF
 118 add $service_test
 119 select $service_test
 120 add $instance_test
 121 EOF
 122 
 123 #Add objects to repository
 124 
 125 echo "--INFO: [${assertion}]
 126         Adding entities <$service_test> to repository using svccfg"
 127 
 128 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 129 if [ $? -ne 0 ]; then
 130         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 131         echo "--DIAG: [$assertion]
 132         Adding entities using svccfg failed."
 133         print_result $RESULT
 134         exit $RESULT
 135 fi
 136 
 137 echo "--INFO: [${assertion}]
 138         enable <$service_test> using svcadm"
 139 
 140 #Enable the service using svcadm
 141 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 142 if [ $? -ne 0 ]; then
 143         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 144         echo "--DIAG: [$assertion]
 145         svcadm enable $service_test failed."
 146         print_result $RESULT
 147         exit $RESULT
 148 fi
 149 
 150 #Wait just for sometime, until the service STATE gets updated
 151 
 152 echo "--INFO: [${assertion}]
 153         Wait until state transition is complete"
 154 
 155 service_wait_state $valid_fmri online
 156 if [ $? -ne 0 ]; then
 157         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 158         echo "--DIAG: [$assertion]
 159         <$service_test> is not online"
 160         print_result $RESULT
 161         exit $RESULT
 162 fi
 163 
 164 echo "--INFO: [${assertion}]
 165         Verify that state = online"
 166 
 167 state=`svcprop -p restarter/state $valid_fmri 2>/dev/null`
 168 ret=$?
 169 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 170         RESULT=$(update_result $STF_FAIL $RESULT)
 171         echo "--DIAG: [$assertion]
 172         EXPECTED: ret = 0; STATE= online
 173         ACTUAL: ret = $ret; STATE = $state"
 174         print_result $RESULT
 175         exit $RESULT
 176 fi
 177 
 178 echo "--INFO: [${assertion}]
 179         svcadm delegate <invalid-restarter> <valid-fmri>"
 180 
 181 /usr/sbin/svcadm delegate $invalid_restarter $valid_fmri >/dev/null 2>&1
 182 ret=$?
 183 if [ $ret -ne 2 ]; then
 184         RESULT=$(update_result $STF_FAIL $RESULT)
 185         echo "--DIAG: [$assertion]
 186         svcadm delegate $invalid_restarter $valid_fmri should fail and exit 1
 187         But it returned : $ret"
 188         print_result $RESULT
 189         exit $RESULT
 190 fi
 191 
 192 echo "--INFO: [${assertion}]
 193         Assertion proved"
 194 
 195 
 196 print_result $RESULT
 197 exit $RESULT