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_004
  32 #
  33 # DESCRIPTION:
  34 #       Calling the "apply file" subcommand where the file contains a
  35 #       service bundle will result in a diagnostic message being sent
  36 #       to stderr and the command exiting with an exit status of 1.
  37 #
  38 # STRATEGY:
  39 # end __stf_assertion__
  40 ###############################################################################
  41 
  42 
  43 # First STF library
  44 . ${STF_TOOLS}/include/stf.kshlib
  45 
  46 # Load GL library
  47 . ${STF_SUITE}/include/gltest.kshlib
  48 
  49 # Load svc.startd library for manifest_generate
  50 . ${STF_SUITE}/include/svc.startd_config.kshlib
  51 
  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 
  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_004
  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 # Leverage manifest template from apply_001 test
 134 readonly manifest_template=$MYLOC/apply_001_manifest.xml
 135 readonly manifest_file=/tmp/apply_004_manifest.xml
 136 
 137 readonly LOGFILE=/tmp/log.$$
 138 readonly STATEFILE=/tmp/state.$$
 139 
 140 manifest_generate $manifest_template \
 141         TEST_SERVICE=$TEST_SERVICE \
 142         TEST_INSTANCE=$TEST_INSTANCE \
 143         SERVICE_APP=$SERVICE_APP  \
 144         LOGFILE=$LOGFILE \
 145         STATEFILE=$STATEFILE | sed 's/ENABLE_VALUE/true/' >$manifest_file
 146 
 147 manifest_purgemd5 $manifest_file
 148 
 149 svccfg apply $manifest_file> $OUTFILE 2>$ERRFILE
 150 ret=$?
 151 [[ $ret -ne 1 ]] &&  {
 152         echo "--DIAG: [${assertion}]
 153         svccfg apply expected to return 1, got $ret"
 154 
 155         RESULT=$STF_FAIL
 156 }
 157 
 158 # Verify that nothing in stdout - this is a non-fatal error
 159 [[ -s $OUTFILE ]] &&  {
 160         echo "--DIAG: [${assertion}]
 161         stdout not expected, but got $(cat $OUTFILE)"
 162 
 163         RESULT=$STF_FAIL
 164 }
 165 
 166 
 167 # Verify that nothing in stderr - this is a non-fatal error
 168 if ! egrep -s "$NOT_PROFILE_ERRMSG" $ERRFILE
 169 then
 170         echo "--DIAG: [${assertion}]
 171         Expected error message \"$NOT_PROFILE_ERRMSG\"
 172         but got \"$(cat $ERRFILE)\""
 173 
 174         RESULT=$STF_FAIL
 175 fi
 176 
 177 
 178 service_exists $TEST_SERVICE
 179 ret=$?
 180 [[ $ret -eq 0 ]] && {
 181         echo "--DIAG: [${assertion}]
 182         service $TEST_SERVICE should not exist in
 183         repository but does"
 184 
 185         RESULT=$STF_FAIL
 186 }
 187 
 188 # Make sure that no instances of the test service are running.  This
 189 # is to ensure that the subsequent pgrep used to verify the assertion
 190 # does not falsely fail.
 191 #
 192 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 193 ret=$?
 194 [[ $ret -eq 0 ]] && {
 195         echo "--DIAG: [${assertion}]
 196         an instance of $(basename $SERVICE_APP) is running but should not be
 197         to ensure correct validation of this test"
 198 
 199         RESULT=$STF_FAIL
 200 }
 201 
 202 
 203 exit $RESULT