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_clear_003
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm clear <service>, where service
  43 #       has multiple instances  should fail and exit 1.
  44 # STRATEGY:
  45 #       - Check for test setup.
  46 #       - Configure a service 'foo$$' using svccfg
  47 #       - Attempt to put multiple instances to the service.
  48 #       - Now attempt to put them in clear mode.
  49 #       - Make sure svcadm for clear <service> fails  with
  50 #               exit 1 saying   instance specification should be needed.
  51 #
  52 # COMMANDS: svcadm(1)
  53 #
  54 # end __stf_assertion__
  55 ################################################################################
  56 
  57 # First load up definitions of STF result variables like STF_PASS etc.
  58 . ${STF_TOOLS}/include/stf.kshlib
  59 
  60 # Load up definitions of shell functionality common to all smf sub-suites.
  61 . ${STF_SUITE}/include/gltest.kshlib
  62 
  63 # Define Variables
  64 readonly assertion=svcadm_clear_003
  65 readonly svccfg_add_script=/var/tmp/svcadm_clear_003.$$.config
  66 readonly service_test=foo$$
  67 readonly instance_test=instance$$
  68 readonly instance_test1=instance1$$
  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 add $instance_test1
 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 echo "--INFO: [${assertion}]
 134         enable <$service_test:$instance_test> using svcadm"
 135 
 136 # Enable the service using svcadm
 137 /usr/sbin/svcadm enable $service_test:$instance_test >/dev/null 2>&1
 138 if [ $? -ne 0 ]; then
 139         echo "--DIAG: [$assertion]
 140         svcadm enable $service_test:$instance_test failed."
 141         print_result $RESULT
 142         exit $RESULT
 143 fi
 144 
 145 echo "--INFO: [${assertion}]
 146         enable <$service_test:$instance_test1> using svcadm"
 147 
 148 # Enable the service using svcadm
 149 /usr/sbin/svcadm enable $service_test:$instance_test1 >/dev/null 2>&1
 150 if [ $? -ne 0 ]; then
 151         echo "--DIAG: [$assertion]
 152         svcadm enable $service_test:$instance_test1 failed."
 153         print_result $RESULT
 154         exit $RESULT
 155 fi
 156 
 157 # Wait until state transition is complete
 158 
 159 echo "--INFO: [${assertion}]
 160         Wait until state transition gets completed"
 161 
 162 service_wait_state $service_test:$instance_test online
 163 if [ $? -ne 0 ]; then
 164         echo "--DIAG: [$assertion]
 165         <$service_test:$instance_test> is not online"
 166         print_result $RESULT
 167         exit $RESULT
 168 fi
 169 
 170 service_wait_state $service_test:$instance_test1 online
 171 if [ $? -ne 0 ]; then
 172         echo "--DIAG: [$assertion]
 173         <$service_test:$instance_test1> is not online"
 174         print_result $RESULT
 175         exit $RESULT
 176 fi
 177 
 178 echo "--INFO: [${assertion}]
 179         Now attempt to clear "
 180 
 181 # Invoke clear on the service
 182 /usr/sbin/svcadm clear $service_test >/dev/null 2>&1
 183 if [ $? -ne 1 ]; then
 184         RESULT=$(update_result $STF_FAIL $RESULT)
 185         echo "--DIAG: [$assertion]
 186         svcadm clear $service_test should fail"
 187         print_result $RESULT
 188         exit $RESULT
 189 fi
 190 
 191 echo "--INFO: [${assertion}]
 192         Assertion proved"
 193 RESULT=$STF_PASS
 194 print_result $RESULT
 195 exit $RESULT