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_009
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'apply' subcommand with a valid service profile that
  35 #       contains services that are unknown will ignore the service (i.e.
  36 #       the service will not be added to the repository).
  37 #
  38 # STRATEGY:
  39 #       - Create a test profile with an unknown test service
  40 #       - Apply the profile 
  41 #       - Verify that the repository does not know about the service
  42 #
  43 #       
  44 # end __stf_assertion__
  45 ###############################################################################
  46 
  47 
  48 ###############################################################################
  49 # start __stf_assertion__
  50 #
  51 # ASSERTION: svccfg_apply_010
  52 #
  53 # DESCRIPTION:
  54 #       Calling the 'apply' subcommand with a valid service profile that
  55 #       contains services that are unknown to the repostory will ??
  56 #
  57 # STRATEGY:
  58 #       - Create a test profile with the test service disabled (enabled=false)
  59 #       - Apply the profile 
  60 #       - Create and import the test service, with enabled=true
  61 #
  62 # NOTE: It isn't clear what the behavior of the test should do.  A bug will
  63 #       be filed.
  64 #       
  65 # end __stf_assertion__
  66 ###############################################################################
  67 
  68 
  69 # First STF library
  70 . ${STF_TOOLS}/include/stf.kshlib
  71 
  72 # Load GL library
  73 . ${STF_SUITE}/include/gltest.kshlib
  74 
  75 # Load svc.startd library for manifest_generate
  76 . ${STF_SUITE}/include/svc.startd_config.kshlib
  77 
  78 readonly ME=$(whence -p ${0})
  79 readonly MYLOC=$(dirname ${ME})
  80 
  81 # Initialize test result 
  82 typeset -i RESULT=$STF_PASS
  83 
  84 
  85 function cleanup {
  86         
  87         # Note that $TEST_SERVICE may or may not exist so don't check
  88         # results.  Just make sure the service is gone.
  89 
  90         manifest_purgemd5 $manifest_file
  91 
  92         service_cleanup ${TEST_SERVICE}
  93 
  94         service_exists ${TEST_SERVICE}
  95         [[ $? -eq 0 ]] && {
  96                 echo "--DIAG: [${assertion}, cleanup]
  97                 service ${TEST_SERVICE} should not exist in 
  98                 repository after being deleted, but does"
  99 
 100                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 101         }
 102 
 103         rm -f $OUTFILE $ERRFILE $LOGFILE $STATEFILE $manifest_file $profile_file
 104 
 105         exit $RESULT
 106 }
 107 
 108 trap cleanup 0 1 2 15
 109 
 110 # make sure that the environment is sane - svc.configd  is up and running
 111 check_gl_env
 112 [[ $? -ne 0 ]] && {
 113         echo "--DIAG: 
 114                 Invalid test environment - svc.configd  not available"
 115 
 116         RESULT=$STF_UNRESOLVED
 117         exit $RESULT
 118 }
 119 
 120 extract_assertion_info $ME
 121 
 122 # 
 123 # Test 9: Apply a non-existent service
 124 #
 125 
 126 assertion=svccfg_apply_009
 127 
 128 echo "--INFO: Starting $assertion, apply non-existent service"
 129 
 130 typeset -i TEST_RESULT=$STF_PASS
 131 
 132 # extract and print assertion information from this source script.
 133 
 134 # Before starting make sure that the test service doesn't already exist.
 135 # If it does then consider it a fatal error.
 136 
 137 service_exists $TEST_SERVICE
 138 ret=$?
 139 [[ $ret -eq 0 ]] && {
 140         echo "--DIAG: [${assertion}]
 141         service $TEST_SERVICE should not exist in
 142         repository but does"
 143 
 144         svccfg list > /tmp/out
 145 
 146         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 147         exit $RESULT
 148 }
 149 
 150 # Make sure that no instances of the test service are running.  This
 151 # is to ensure that the subsequent pgrep used to verify the assertion
 152 # does not falsely fail.
 153 #
 154 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 155 ret=$?
 156 [[ $ret -eq 0 ]] && {
 157         echo "--DIAG: [${assertion}]
 158         an instance of $(basename $SERVICE_APP) is running but should not be
 159         to ensure correct validation of this test"
 160 
 161         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 162         exit $RESULT
 163 }
 164 
 165 
 166 
 167 # 
 168 # Test 10:  Import the "non-existent" service that was applied.
 169 #
 170 
 171 assertion=svccfg_apply_010
 172 
 173 echo "--INFO: Starting $assertion, import service"
 174 
 175 typeset -i TEST_RESULT=$STF_PASS
 176 
 177 
 178 readonly profile_template=$MYLOC/apply_001_profile.xml
 179 readonly profile_file=/tmp/apply_001_profile.xml
 180 
 181 manifest_generate $profile_template \
 182         TEST_SERVICE=$TEST_SERVICE \
 183         TEST_INSTANCE=$TEST_INSTANCE  | sed 's/ENABLE_VALUE/false/' >$profile_file
 184 
 185 svccfg apply $profile_file > $OUTFILE 2>$ERRFILE
 186 ret=$?
 187 [[ $ret -ne 0 ]] &&  {
 188         echo "--DIAG: [${assertion}]
 189         svccfg apply expected to return 0, got $ret"
 190 
 191         TEST_RESULT=$STF_FAIL
 192 }
 193 
 194 # Verify that nothing in stdout - this is a non-fatal error
 195 [[ -s $OUTFILE ]] &&  {
 196         echo "--DIAG: [${assertion}]
 197         stdout not expected, but got $(cat $OUTFILE)"
 198 
 199         TEST_RESULT=$STF_FAIL
 200 }
 201 
 202 # Verify that nothing in stderr - this is a non-fatal error
 203 [[ -s $ERRFILE ]] &&  {
 204         echo "--DIAG: [${assertion}]
 205         stderr not expected, but got $(cat $ERRFILE)"
 206 
 207         TEST_RESULT=$STF_FAIL
 208 }
 209 
 210 service_exists $TEST_SERVICE
 211 ret=$?
 212 [[ $ret -eq 0 ]] && {
 213         echo "--DIAG: [${assertion}]
 214         service $TEST_SERVICE should not exist in
 215         repository but does"
 216 
 217         TEST_RESULT=$STF_FAIL
 218 }
 219 
 220 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 221 ret=$?
 222 [[ $ret -eq 0 ]] && {
 223         echo "--DIAG: [${assertion}]
 224         app $(basename $SERVICE_APP) is running but should not be"
 225 
 226         TEST_RESULT=$STF_FAIL
 227 }
 228 
 229 rm -f $ERRFILE $OUTFILE
 230 
 231 print_result $TEST_RESULT
 232 RESULT=$(update_result $TEST_RESULT $RESULT)
 233 
 234 [[ $RESULT != $STF_PASS ]] && exit $RESULT
 235 
 236 #
 237 # Test #10: Add the non-existent service that was just imported
 238 #
 239 
 240 
 241 echo "--INFO: Starting $assertion, test 10 (add service)"
 242 typeset -i TEST_RESULT=$STF_PASS
 243 
 244 readonly manifest_template=$MYLOC/apply_001_manifest.xml
 245 readonly manifest_file=/tmp/apply_001_manifest.xml
 246 
 247 readonly LOGFILE=/tmp/log.$$
 248 readonly STATEFILE=/tmp/state.$$
 249 
 250 manifest_generate $manifest_template \
 251         TEST_SERVICE=$TEST_SERVICE \
 252         TEST_INSTANCE=$TEST_INSTANCE \
 253         SERVICE_APP=$SERVICE_APP  \
 254         LOGFILE=$LOGFILE \
 255         STATEFILE=$STATEFILE | sed 's/ENABLE_VALUE/true/' >$manifest_file
 256 
 257 manifest_purgemd5 $manifest_file
 258 
 259 svccfg  import $manifest_file > $OUTFILE 2>$ERRFILE
 260 ret=$?
 261 [[ $ret -ne 0 ]] &&  {
 262         echo "--DIAG: [${assertion}]
 263         svccfg import failed unexpectedly
 264         error output is $(cat $ERRFILE)"
 265 
 266         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 267         exit $RESULT
 268 }
 269 
 270 # Verify that nothing in stdout - this is a non-fatal error
 271 [[ -s $OUTFILE ]] &&  {
 272         echo "--DIAG: [${assertion}]
 273         stdout not expected, but got $(cat $OUTFILE)"
 274 
 275         TEST_RESULT=$STF_FAIL
 276 }
 277 
 278 # Verify that nothing in stderr - this is a non-fatal error
 279 [[ -s $ERRFILE ]] &&  {
 280         echo "--DIAG: [${assertion}]
 281         stderr not expected, but got $(cat $ERRFILE)"
 282 
 283         TEST_RESULT=$STF_FAIL
 284 }
 285 
 286 service_exists $TEST_SERVICE
 287 ret=$?
 288 [[ $ret -ne 0 ]] && {
 289         echo "--DIAG: [${assertion}]
 290         service $TEST_SERVICE should exist in repository 
 291         but does not"
 292 
 293         TEST_RESULT=$STF_FAIL
 294 }
 295 
 296 service_wait_state $TEST_SERVICE:$TEST_INSTANCE online 
 297 ret=$?
 298 [[ $ret -ne 0 ]] && {
 299         echo "--DIAG: [${assertion}]
 300         $TEST_SERVICE:$TEST_INSTANCE did not transition to online as expected" 
 301 
 302         TEST_RESULT=$STF_FAIL
 303 }
 304 
 305 
 306 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 307 ret=$?
 308 [[ $ret -ne 0 ]] && {
 309         echo "--DIAG: [${assertion}]
 310         app $(basename $SERVICE_APP) is not running but should be"
 311 
 312         TEST_RESULT=$STF_FAIL
 313 }
 314 
 315 print_result $TEST_RESULT
 316 RESULT=$(update_result $TEST_RESULT $RESULT)
 317 
 318 exit $RESULT