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 ###############################################################################
  30 # start __stf_assertion__
  31 #
  32 # ASSERTION: svcadm_maintenance_001
  33 #
  34 # DESCRIPTION:
  35 #       Calling 'svcadm mark maintenance FMRI' where FMRI is a service 
  36 #       instance that is in the disabled state should get transit to
  37 #       state maintenance.
  38 # STRATEGY:
  39 #       - Create a service instance configuration.
  40 #       - Enable it using svcadm enable
  41 #       - Disable the service instance using svcadm disable.
  42 #       - Call svcadm mark maintenance FMRI and make sure it exits 0.
  43 #       - Verify state of "service instance" is unchanged from disable.
  44 #
  45 # COMMANDS: svcadm(1)
  46 #
  47 # end __stf_assertion__
  48 ################################################################################
  49 
  50 # First load up definitions of STF result variables like STF_PASS etc.
  51 . ${STF_TOOLS}/include/stf.kshlib
  52 
  53 # Load up definitions of shell functionality common to all smf sub-suites.
  54 . ${STF_SUITE}/include/gltest.kshlib
  55 . ${STF_SUITE}/include/svc.startd_config.kshlib
  56 
  57 # Define the cleanup function for this test.
  58 function cleanup {
  59         service_cleanup $test_service
  60         /usr/bin/rm -f $svccfg_add_script
  61 }
  62 
  63 # Define Variables
  64 readonly assertion=svcadm_maintenance_001
  65 readonly ME=$(whence -p ${0})
  66 readonly MYLOC=$(dirname ${ME})
  67 readonly test_service="maintenance_001$$"
  68 readonly test_instance="maintenance_001$$"
  69 readonly svccfg_add_script=/var/tmp/maintenance_001$$.cfg
  70 readonly test_fmri="svc:/$test_service:$test_instance"
  71 
  72 # Make sure we run as root
  73 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  74 then
  75         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  76         echo "--DIAG: [$assertion]
  77         This test must be run from root."
  78         print_result $RESULT
  79         exit $RESULT
  80 fi
  81 
  82 # Extract and print assertion information from this source script.
  83 extract_assertion_info $ME
  84 
  85 # Initialize test result to pass.
  86 typeset -i RESULT=${STF_UNRESOLVED}
  87 
  88 # Set a trap to execute the cleanup function
  89 trap cleanup 0 1 2 15
  90 
  91 # Exit code for individual commands.
  92 typeset -i tmp_rc=0
  93 
  94 # Execute environmental sanity checks.
  95 check_gl_env
  96 tmp_rc=$?
  97 if [[ $tmp_rc -ne 0 ]]
  98 then
  99         echo "--DIAG: [$assertion]
 100         Invalid smf environment, quitting."
 101         print_result $RESULT
 102         exit $RESULT
 103 fi
 104 
 105 # Create the svccfg add script which will add entities to the
 106 # repository for this test case.
 107 
 108 echo "--INFO: [${assertion}]
 109         configure test service $test_service using svccfg"
 110 
 111 cat > $svccfg_add_script <<EOF
 112 add $test_service
 113 select $test_service
 114 add $test_instance
 115 EOF
 116 
 117 #Add objects to repository
 118 
 119 echo "--INFO: [${assertion}]
 120         Adding entities <$test_service> to repository using svccfg"
 121 
 122 /usr/sbin/svccfg -f $svccfg_add_script >/dev/null 2>&1
 123 if [ $? -ne 0 ]; then
 124         echo "--DIAG: [$assertion]
 125         Adding entities using svccfg failed."
 126         print_result $RESULT
 127         exit $RESULT
 128 fi
 129 
 130 
 131 echo "--INFO: [${assertion}]
 132         Enable $test_fmri using svcadm enable"
 133 
 134 svcadm enable $test_fmri >/dev/null 2>&1
 135 ret=$?
 136 if [ $ret -ne 0 ]; then
 137         echo "--DIAG: [$assertion]
 138                 svcadm enable $test_fmri fails
 139         EXPECTED: ret = 0
 140         OBSERVED: ret = $ret"
 141         print_result $RESULT
 142         exit $RESULT
 143 fi
 144 
 145 # Wait until the service state is updated
 146 target_state="online"
 147 
 148 echo "--INFO: [${assertion}]
 149         Wait until state transition to $target_state is completed"
 150 
 151 service_wait_state $test_fmri $target_state
 152 if [ $? -ne 0 ]; then
 153         echo "--DIAG: [$assertion]
 154         EXPECTED: <$test_fmri>: $target_state
 155         OBSERVED: <$test_fmri>: `svcprop -p restarter/state $test_fmri`"
 156         print_result $RESULT
 157         exit $RESULT
 158 fi
 159 
 160 
 161 echo "--INFO: [${assertion}]
 162         Disable $test_fmri using svcadm disable"
 163 
 164 svcadm disable $test_fmri >/dev/null 2>&1
 165 ret=$?
 166 if [ $ret -ne 0 ]; then
 167         echo "--DIAG: [$assertion]
 168                 svcadm disable $test_fmri fails
 169         EXPECTED: ret = 0
 170         OBSERVED: ret = $ret"
 171         print_result $RESULT
 172         exit $RESULT
 173 fi
 174 
 175 # Wait until the service STATE gets updated
 176 
 177 target_state="disabled"
 178 
 179 echo "--INFO: [${assertion}]
 180         Wait until transition to state $target_state is completed"
 181 
 182 service_wait_state $test_fmri $target_state
 183 if [ $? -ne 0 ]; then
 184         echo "--DIAG: [$assertion]
 185         EXPECTED: <$test_fmri>: $target_state
 186         OBSERVED: <$test_fmri>: `svcprop -p restarter/state $test_fmri`"
 187         print_result $RESULT
 188         exit $RESULT
 189 fi
 190 
 191 # Mark $test_fmri as in maintenance state
 192 echo "--INFO: [${assertion}]
 193         Mark $test_fmri as in maintenance state"
 194 svcadm mark maintenance $test_fmri >/dev/null 2>&1
 195 ret=$?
 196 if [ $ret -ne 0 ]; then
 197         RESULT=$(update_result $STF_FAIL $RESULT)
 198         echo "--DIAG: [$assertion]
 199                 svcadm mark maintenance $test_fmri fails
 200         EXPECTED: ret = 0
 201         OBSERVED: ret = $ret"
 202         print_result $RESULT
 203         exit $RESULT
 204 fi
 205 
 206 echo "--INFO: [${assertion}]
 207         Verify that state = maintenance"
 208 
 209 state=`svcprop -p restarter/state $test_fmri 2>/dev/null`
 210 ret=$?
 211 if [[ $ret -ne 0 || "$state" != "maintenance" ]]; then
 212         RESULT=$(update_result $STF_FAIL $RESULT)
 213         echo "--DIAG: [$assertion]
 214         EXPECTED: ret = 0; STATE= maintenance
 215         ACTUAL: ret = $ret; STATE = $state"
 216         print_result $RESULT
 217         exit $RESULT
 218 fi
 219 
 220 RESULT=$STF_PASS
 221 print_result $RESULT
 222 exit $RESULT
 223 
 224 #
 225 ### END
 226 #