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