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_test1
  33         service_cleanup $service_test2
  34         /usr/bin/rm -f $svccfg_add_script1
  35         /usr/bin/rm -f $svccfg_add_script2
  36         /usr/bin/rm -f $expected_output
  37         /usr/bin/rm -f /var/tmp/$assertion.$$.actual
  38 }
  39 
  40 ###############################################################################
  41 # start __stf_assertion__
  42 #
  43 # ASSERTION: svcadm_enable_013
  44 #
  45 # DESCRIPTION:
  46 #       svcadm -v enable <FMRI list> should succeed, with verbose message
  47 #       action for all the fmri(s).
  48 # STRATEGY:
  49 #       - Check for test setup.
  50 #       - Configure a service 'foo$$1' using svccfg
  51 #       - configure another service foo$$2 using svccfg
  52 #       - Enable them using svcadm
  53 #       - Make sure their state is online
  54 #       - svcadm -v enable <fmrilist> and make sure it exits 0.
  55 #       - Verify that it displays verbose message for all the services.
  56 #       - Make sure state is online.
  57 #
  58 # COMMANDS: svcadm(1)
  59 #
  60 # end __stf_assertion__
  61 ################################################################################
  62 
  63 # First load up definitions of STF result variables like STF_PASS etc.
  64 . ${STF_TOOLS}/include/stf.kshlib
  65 
  66 # Load up definitions of shell functionality common to all smf sub-suites.
  67 . ${STF_SUITE}/include/gltest.kshlib
  68 
  69 # Define Variables
  70 readonly assertion=svcadm_enable_013
  71 readonly svccfg_add_script1=/var/tmp/svcadm_enable_013.$$.config1
  72 readonly svccfg_add_script2=/var/tmp/svcadm_enable_013.$$.config2
  73 readonly service_test1=foo$$1
  74 readonly service_test2=foo$$2
  75 readonly instance_test=instance$$
  76 readonly fmri1=svc:/$service_test1:$instance_test
  77 readonly fmri2=svc:/$service_test2:$instance_test
  78 readonly expected_output=/var/tmp/$assertion.$$.expected
  79 readonly ME=$(whence -p ${0})
  80 readonly MYLOC=$(dirname ${ME})
  81 
  82 # gltest.kshlib functions to extract and print assertion information
  83 # from this source script.
  84 extract_assertion_info $ME
  85 
  86 # Initialize test result to pass.
  87 typeset -i RESULT=${STF_UNRESOLVED}
  88 
  89 # Set a trap to execute the cleanup function when specified signals
  90 # are received.
  91 trap cleanup 0 1 2 15
  92 
  93 # Exit code for individual commands.
  94 typeset -i tmp_rc=0
  95 
  96 # Make sure we run as root
  97 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  98 then
  99         echo "--DIAG: [$assertion]
 100         This test must be run from root."
 101         print_result $RESULT
 102         exit $RESULT
 103 fi
 104 
 105 
 106 # Execute environmental sanity checks.
 107 check_gl_env
 108 tmp_rc=$?
 109 if [[ $tmp_rc -ne 0 ]]
 110 then
 111     echo "--DIAG: [$assertion]
 112         Invalid smf environment, quitting."
 113     print_result $RESULT
 114     exit $RESULT
 115 fi
 116 
 117 # Create the svccfg add script which will add entities to the
 118 # repository for this test case.
 119 
 120 echo "--INFO: [${assertion}]
 121         configure $service_test1 using svccfg"
 122 
 123 cat > $svccfg_add_script1 <<EOF
 124 add $service_test1
 125 select $service_test1
 126 add $instance_test
 127 EOF
 128 
 129 echo "--INFO: [${assertion}]
 130         configure $service_test2 using svccfg"
 131 
 132 cat > $svccfg_add_script2 <<EOF
 133 add $service_test2
 134 select $service_test2
 135 add $instance_test
 136 EOF
 137 
 138 #Add objects to repository
 139 
 140 echo "--INFO: [${assertion}]
 141         Adding entities <$service_test1> to repository using svccfg"
 142 
 143 /usr/sbin/svccfg -f $svccfg_add_script1 >/dev/null 2>&1
 144 if [ $? -ne 0 ]; then
 145         echo "--DIAG: [$assertion]
 146         Adding entities using svccfg failed."
 147         print_result $RESULT
 148         exit $RESULT
 149 fi
 150 #Add objects to repository
 151 
 152 echo "--INFO: [${assertion}]
 153         Adding entities <$service_test2> to repository using svccfg"
 154 
 155 /usr/sbin/svccfg -f $svccfg_add_script2 >/dev/null 2>&1
 156 if [ $? -ne 0 ]; then
 157         echo "--DIAG: [$assertion]
 158         Adding entities using svccfg failed."
 159         print_result $RESULT
 160 fi
 161 
 162 echo "--INFO: [${assertion}]
 163         enable services using svcadm enable fmrilist"
 164 
 165 #Enable the service using svcadm enable <fmrilist>?
 166 /usr/sbin/svcadm -v enable $fmri1 $fmri2 \
 167         > /var/tmp/$assertion.$$.actual 2>/dev/null
 168 if [ $? -ne 0 ]; then
 169         RESULT=$(update_result $STF_FAIL $RESULT)
 170         echo "--DIAG: [$assertion]
 171         svcadm enable $fmri1 $fmri2 should succeed with return 0"
 172         print_result $RESULT
 173         exit $RESULT
 174 fi
 175 
 176 cat > $expected_output <<EOF
 177 $fmri1 enabled.
 178 $fmri2 enabled.
 179 EOF
 180 
 181 diff -w /var/tmp/$assertion.$$.actual $expected_output >/dev/null 2>&1
 182 if [ $? -ne 0 ]; then
 183         RESULT=$(update_result $STF_FAIL $RESULT)
 184         echo "--DIAG: [$assertion]
 185         Expected: `cat /var/tmp/$expected_output`
 186         Actual: `cat /var/tmp/$assertion.$$.actual`"
 187         print_result $RESULT
 188         exit $RESULT
 189 fi
 190 
 191 service_wait_state $fmri1 online
 192 if [ $? -ne 0 ]; then
 193         RESULT=$(update_result $STF_FAIL $RESULT)
 194         echo "--DIAG: [$assertion]
 195         <$fmri1> is not online"
 196         print_result $RESULT
 197         exit $RESULT
 198 fi
 199 
 200 service_wait_state $fmri2 online
 201 if [ $? -ne 0 ]; then
 202         RESULT=$(update_result $STF_FAIL $RESULT)
 203         echo "--DIAG: [$assertion]
 204         <$fmri2> 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