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 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 ###############################################################################
  29 # start __stf_assertion__
  30 #
  31 # ASSERTION: svccfg_apply_002
  32 #
  33 # DESCRIPTION:
  34 #       Calling the "apply file" subcommand where the file contains a
  35 #       valid service profile will result in the service instances
  36 #       specified within the file being disabled, if the services are
  37 #       specified to be disabled.  If no errors have occurred during
  38 #       processing, there is nothing seen on stderr and the
  39 #       command exist status is 0.
  40 #
  41 # STRATEGY:
  42 #       This test uses a service that is existing in the repository.  
  43 #       - Create and import a test service, with enabled=true
  44 #          (at this point the service is up and running)
  45 #       - Create a test profile with the test service enabled (enabled=true)
  46 #       - Apply the profile 
  47 #          (this should have no impact on the state of the services)
  48 #       - Update the profile such that enable is not true (enabled=false)
  49 #       - Apply the profile 
  50 #          (this should disable the service)
  51 #
  52 # NOTE:  Results in UNRESOLVED due to 1000566
  53 #       
  54 # end __stf_assertion__
  55 ###############################################################################
  56 
  57 
  58 # First STF library
  59 . ${STF_TOOLS}/include/stf.kshlib
  60 
  61 # Load GL library
  62 . ${STF_SUITE}/include/gltest.kshlib
  63 
  64 # Load svc.startd library for manifest_generate
  65 . ${STF_SUITE}/include/svc.startd_config.kshlib
  66 
  67 
  68 readonly ME=$(whence -p ${0})
  69 readonly MYLOC=$(dirname ${ME})
  70 
  71 # Initialize test result 
  72 typeset -i RESULT=$STF_PASS
  73 
  74 function cleanup {
  75         
  76         # Note that $TEST_SERVICE may or may not exist so don't check
  77         # results.  Just make sure the service is gone.
  78 
  79         manifest_purgemd5 $manifest_file
  80 
  81         service_cleanup ${TEST_SERVICE}
  82 
  83         service_exists ${TEST_SERVICE}
  84         [[ $? -eq 0 ]] && {
  85                 echo "--DIAG: [${assertion}, cleanup]
  86                 service ${TEST_SERVICE} should not exist in 
  87                 repository after being deleted, but does"
  88 
  89                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  90         }
  91 
  92         rm -f $OUTFILE $ERRFILE $LOGFILE $STATEFILE $manifest_file $profile_file
  93 
  94         exit $RESULT
  95 }
  96 
  97 trap cleanup 0 1 2 15
  98 
  99 # make sure that the environment is sane - svc.configd  is up and running
 100 check_gl_env
 101 [[ $? -ne 0 ]] && {
 102         echo "--DIAG: 
 103                 Invalid test environment - svc.configd  not available"
 104 
 105         RESULT=$STF_UNRESOLVED
 106         exit $RESULT
 107 }
 108 
 109 assertion=svccfg_apply_002
 110 
 111 # extract and print assertion information from this source script.
 112 extract_assertion_info $ME
 113 
 114 # Before starting make sure that the test service doesn't already exist.
 115 # If it does then consider it a fatal error.
 116 #
 117 service_exists $TEST_SERVICE
 118 ret=$?
 119 [[ $ret -eq 0 ]] && {
 120         echo "--DIAG: [${assertion}]
 121         service $TEST_SERVICE should not exist in
 122         repository but does"
 123 
 124         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 125         exit $RESULT
 126 }
 127 
 128 # Make sure that no instances of the test service are running.  This
 129 # is to ensure that the subsequent pgrep used to verify the assertion
 130 # does not falsely fail.
 131 #
 132 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 133 ret=$?
 134 [[ $ret -eq 0 ]] && {
 135         echo "--DIAG: [${assertion}]
 136         an instance of $(basename $SERVICE_APP) is running but should not be
 137         to ensure correct validation of this test"
 138 
 139         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 140         exit $RESULT
 141 }
 142 
 143 
 144 # # Start assertion testing
 145 #
 146 
 147 readonly manifest_template=$MYLOC/apply_001_manifest.xml
 148 readonly manifest_file=/tmp/apply_001_manifest.xml
 149 
 150 readonly LOGFILE=/tmp/log.$$
 151 readonly STATEFILE=/tmp/state.$$
 152 
 153 manifest_generate $manifest_template \
 154         TEST_SERVICE=$TEST_SERVICE \
 155         TEST_INSTANCE=$TEST_INSTANCE \
 156         SERVICE_APP=$SERVICE_APP  \
 157         LOGFILE=$LOGFILE \
 158         STATEFILE=$STATEFILE | sed 's/ENABLE_VALUE/false/' >$manifest_file
 159 
 160 manifest_purgemd5 $manifest_file
 161 
 162 svccfg  import $manifest_file > $OUTFILE 2>$ERRFILE
 163 ret=$?
 164 [[ $ret -ne 0 ]] &&  {
 165         echo "--DIAG: [${assertion}]
 166         svccfg import failed unexpectedly
 167         error output is $(cat $ERRFILE)"
 168 
 169         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 170         exit $RESULT
 171 }
 172 
 173 service_wait_state $TEST_SERVICE:$TEST_INSTANCE disabled  
 174 ret=$?
 175 [[ $ret -ne 0 ]] && {
 176         echo "--DIAG: [${assertion}]
 177         $TEST_SERVICE:$TEST_INSTANCE did not transition to disabled as expected" 
 178         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 179         exit $RESULT
 180 }
 181 
 182 
 183 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 184 ret=$?
 185 [[ $ret -eq 0 ]] && {
 186         echo "--DIAG: [${assertion}]
 187         app $(basename $SERVICE_APP) is running but should not be"
 188 
 189         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 190         exit $RESULT
 191 }
 192 
 193 readonly profile_template=$MYLOC/apply_001_profile.xml
 194 readonly profile_file=/tmp/apply_001_profile.xml
 195 
 196 manifest_generate $profile_template \
 197         TEST_SERVICE=$TEST_SERVICE \
 198         TEST_INSTANCE=$TEST_INSTANCE  | sed 's/ENABLE_VALUE/true/' >$profile_file
 199 
 200 svccfg apply $profile_file > $OUTFILE 2>$ERRFILE
 201 ret=$?
 202 [[ $ret -ne 0 ]] &&  {
 203         echo "--DIAG: [${assertion}]
 204         svccfg apply expected to return 0, got $ret"
 205 
 206         RESULT=$STF_FAIL
 207 }
 208 
 209 
 210 # Verify that nothing in stdout - this is a non-fatal error
 211 [[ -s $OUTFILE ]] &&  {
 212         echo "--DIAG: [${assertion}]
 213         stdout not expected, but got $(cat $OUTFILE)"
 214 
 215         RESULT=$STF_FAIL
 216 }
 217 
 218 # Verify that nothing in stderr - this is a non-fatal error
 219 [[ -s $ERRFILE ]] &&  {
 220         echo "--DIAG: [${assertion}]
 221         stderr not expected, but got $(cat $ERRFILE)"
 222 
 223         RESULT=$STF_FAIL
 224 }
 225 
 226 
 227 service_wait_state $TEST_SERVICE:$TEST_INSTANCE online 
 228 ret=$?
 229 [[ $ret -ne 0 ]] && {
 230         echo "--DIAG: [${assertion}]
 231         $TEST_SERVICE:$TEST_INSTANCE did not transition to online as expected" 
 232         RESULT=$STF_FAIL
 233 }
 234 
 235 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 236 ret=$?
 237 [[ $ret -ne 0 ]] && {
 238         echo "--DIAG: [${assertion}]
 239         app $(basename $SERVICE_APP) is not running but should be"
 240 
 241         RESULT=$STF_FAIL
 242 }
 243 
 244 
 245 exit $RESULT