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_001
  40 #
  41 # DESCRIPTION:
  42 #       svcadm <clear> FMRI, where FMRI is a service instance which
  43 #       is currently in online STATE should fail with exit 1
  44 #
  45 # STRATEGY:
  46 #       - Check for test setup.
  47 #       - Configure a service 'foo$$' using svccfg
  48 #       - Enable it using svcadm
  49 #       - Call svcadm <clear> <FMRI>
  50 #       - Verify that above step fails with exit 1
  51 #       - Also make sure STATE doesn't change 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_clear_001
  66 readonly svccfg_add_script=/var/tmp/svcadm_clear_001.$$.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 $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 echo "--INFO: [${assertion}]
 134         enable <$service_test> using svcadm"
 135 
 136 # Enable the service using svcadm
 137 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 138 if [ $? -ne 0 ]; then
 139         echo "--DIAG: [$assertion]
 140         svcadm enable $service_test failed."
 141         print_result $RESULT
 142         exit $RESULT
 143 fi
 144 
 145 # Wait until state transition is complete
 146 echo "--INFO: [${assertion}]
 147         Wait until state transition gets completed"
 148 service_wait_state $service_test:$instance_test online
 149 if [ $? -ne 0 ]; then
 150         echo "--DIAG: [$assertion]
 151         <$service_test> is not online"
 152         print_result $RESULT
 153         exit $RESULT
 154 fi
 155 
 156 echo "--INFO: [${assertion}]
 157         Verify that state = online"
 158 
 159 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
 160 ret=$?
 161 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 162         RESULT=$(update_result $STF_FAIL $RESULT)
 163         echo "--DIAG: [$assertion]
 164         EXPECTED: ret = 0; STATE= online
 165         ACTUAL: ret = $ret; STATE = $state"
 166         print_result $RESULT
 167         exit $RESULT
 168 fi
 169 
 170 echo "--INFO: [${assertion}]
 171         Clear <$fmri> using svcadm"
 172 
 173 # Invoke clear on the service
 174 /usr/sbin/svcadm clear $fmri >/dev/null 2>&1
 175 if [ $? -ne 1 ]; then
 176         echo "--DIAG: [$assertion]
 177         svcadm clear $service_test should fail with exit 1"
 178         print_result $RESULT
 179         exit $RESULT
 180 fi
 181 
 182 echo "--INFO: [${assertion}]
 183         Verify that state is unchanged from online"
 184 
 185 state=`svcprop -p restarter/state $service_test:$instance_test 2>/dev/null`
 186 ret=$?
 187 if [[ $ret -ne 0 || "$state" != "online" ]]; then
 188         RESULT=$(update_result $STF_FAIL $RESULT)
 189         echo "--DIAG: [$assertion]
 190         EXPECTED: ret = 0; STATE= online
 191         ACTUAL: ret = $ret; STATE = $state"
 192         print_result $RESULT
 193         exit $RESULT
 194 fi
 195 
 196 
 197 echo "--INFO: [${assertion}]
 198         Assertion proved"
 199 RESULT=$STF_PASS
 200 print_result $RESULT
 201 exit $RESULT