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_014
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm enable <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 enable mode.
  49 #       - Make sure svcadm for enable <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_enable_014
  65 readonly svccfg_add_script=/var/tmp/svcadm_enable_014.$$.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 echo "--INFO: [${assertion}]
 121         Now attempt to enable svcadm enable $service_test "
 122 
 123 #Enable the service using svcadm
 124 /usr/sbin/svcadm enable $service_test >/dev/null 2>&1
 125 if [ $? -ne 1 ]; then
 126         RESULT=$(update_result $STF_FAIL $RESULT)
 127         echo "--DIAG: [$assertion]
 128         svcadm enable $service_test should fail"
 129         print_result $RESULT
 130         exit $RESULT
 131 fi
 132 
 133 echo "--INFO: [${assertion}]
 134         Assertion proved"
 135 
 136 RESULT=$STF_PASS
 137 print_result $RESULT
 138 exit $RESULT