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_maintenance_005
  40 #
  41 # DESCRIPTION:
  42 #       Calling 'svcadm mark maintenance <service>, where service
  43 #       has multiple instances  should pass and exit 0.
  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 maintenance mode.
  49 #       - Make sure svcadm for maintenance <service> passes with
  50 #               exit 0.
  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_maintenance_005
  65 readonly svccfg_add_script=/var/tmp/svcadm_maintenance_005.$$.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 # Local 'return code' variable
 108 typeset -i rc=0
 109 
 110 # Create the svccfg add script which will add entities to the
 111 # repository for this test case.
 112 
 113 echo "--INFO: [${assertion}]
 114         configure $service_test using svccfg"
 115 
 116 cat > $svccfg_add_script <<EOF
 117 add $service_test
 118 select $service_test
 119 add $instance_test
 120 add $instance_test1
 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 rc=$?
 130 if [ $rc -ne 0 ]; then
 131         echo "--DIAG: [$assertion]
 132         Adding entities using svccfg failed.
 133         EXPECTED: svccfg exit status = 0
 134         RETURNED: svccfg exit status = $rc"
 135         print_result $RESULT
 136         exit $RESULT
 137 fi
 138 
 139 echo "--INFO: [${assertion}]
 140         enable <$service_test:$instance_test> using svcadm"
 141 
 142 #Enable the service using svcadm
 143 /usr/sbin/svcadm enable $service_test:$instance_test >/dev/null 2>&1
 144 rc=$?
 145 if [ $rc -ne 0 ]; then
 146         echo "--DIAG: [$assertion]
 147         svcadm enable $service_test:$instance_test failed.
 148         EXPECTED: exit status 0
 149         RETURNED: exit status $rc"
 150         print_result $RESULT
 151         exit $RESULT
 152 fi
 153 
 154 echo "--INFO: [${assertion}]
 155         enable <$service_test:$instance_test1> using svcadm"
 156 
 157 #Enable the service using svcadm
 158 /usr/sbin/svcadm enable $service_test:$instance_test1 >/dev/null 2>&1
 159 rc=$?
 160 if [ $rc -ne 0 ]; then
 161         echo "--DIAG: [$assertion]
 162         svcadm enable $service_test:$instance_test1 failed.
 163         EXPECTED: exit status 0
 164         RETURNED: exit status $rc"
 165         print_result $RESULT
 166         exit $RESULT
 167 fi
 168 
 169 #Wait just for sometime, let the service STATE gets updated
 170 
 171 echo "--INFO: [${assertion}]
 172         Wait for sometime to state transition gets completed"
 173 
 174 service_wait_state $service_test:$instance_test online
 175 rc=$?
 176 if [ $rc -ne 0 ]; then
 177         echo "--DIAG: [$assertion]
 178         <$service_test:$instance_test> is not online"
 179         print_result $RESULT
 180         exit $RESULT
 181 fi
 182 
 183 service_wait_state $service_test:$instance_test1 online
 184 rc=$?
 185 if [ $rc -ne 0 ]; then
 186         echo "--DIAG: [$assertion]
 187         <$service_test:$instance_test1> is not online"
 188         print_result $RESULT
 189         exit $RESULT
 190 fi
 191 
 192 echo "--INFO: [${assertion}]
 193         Now attempt to mark maintenance "
 194 
 195 #Enable the service using svcadm
 196 /usr/sbin/svcadm mark maintenance $service_test >/dev/null 2>&1
 197 rc=$?
 198 if [ $rc -ne 0 ]; then
 199         RESULT=$(update_result $STF_FAIL $RESULT)
 200         echo "--DIAG: [$assertion]
 201         svcadm mark maintenance $service_test should pass
 202         EXPECTED: exit status 0
 203         RETURNED: exit status $rc"
 204         print_result $RESULT
 205         exit $RESULT
 206 fi
 207 
 208 echo "--INFO: [${assertion}]
 209         Assertion proved"
 210 
 211 RESULT=$STF_RESULT
 212 print_result $RESULT
 213 exit $RESULT