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_select_004
  32 #
  33 # DESCRIPTION:
  34 #       If the (valid) FMRI specified in the subcommand "select FMRI"
  35 #       refers to an object that does not exist in the repository,
  36 #       the diagnostic message "Not found." is sent to stderr.  The
  37 #       command exit status will be 1.
  38 #
  39 # STRATEGY:
  40 #
  41 # end __stf_assertion__
  42 ###############################################################################
  43 
  44 
  45 # First STF library
  46 . ${STF_TOOLS}/include/stf.kshlib
  47 
  48 # Load GL library
  49 . ${STF_SUITE}/include/gltest.kshlib
  50 
  51 # Assertion ID
  52 readonly assertion=svccfg_select_004
  53 
  54 readonly ME=$(whence -p ${0})
  55 readonly MYLOC=$(dirname ${ME})
  56 
  57 # Initialize test result 
  58 typeset -i RESULT=$STF_PASS
  59 
  60 function cleanup {
  61         
  62         # Note that $TEST_SERVICE_FMRI may or may not exist so don't check
  63         # results.  Just make sure the service is gone.
  64         service_delete $TEST_SERVICE_FMRI > /dev/null 2>&1
  65 
  66         service_exists ${TEST_SERVICE_FMRI}
  67         [[ $? -eq 0 ]] && {
  68                 echo "--DIAG: [${assertion}, cleanup]
  69                 service ${TEST_SERVICE_FMRI} should not exist in
  70                 repository after being deleted, but does"
  71 
  72                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  73         }
  74         rm -f $OUTFILE $ERRFILE $CMDFILE
  75         exit $RESULT
  76 }
  77 
  78 trap cleanup 0 1 2 15
  79 
  80 # make sure that the environment is sane - svc.configd is up and running
  81 check_gl_env
  82 [[ $? -ne 0 ]] && {
  83         print_err "$assertion: invalid test environment"
  84         exit $STF_UNRESOLVED
  85 }
  86 
  87 # extract and print assertion information from this source script.
  88 extract_assertion_info $ME
  89 
  90 
  91 # 
  92 # Test #1: Non-existent service
  93 #
  94 echo "--INFO: Starting $assertion, test 1 (select non-existent service)"
  95 
  96 typeset -i TEST_RESULT=$STF_PASS
  97 
  98 service_exists ${TEST_SERVICE_FMRI}
  99 [[ $? -eq 0 ]] && {
 100         echo "--DIAG: [${assertion}, test 1]
 101         service ${TEST_SERVICE} should not exist in
 102         repository for test to run."
 103 
 104         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 105         exit $RESULT
 106 }
 107 
 108 svccfg select ${TEST_SERVICE_FMRI} > $OUTFILE 2>$ERRFILE
 109 ret=$?
 110 
 111 # Verify that the return value is as expected - non-fatal error
 112 [[ $ret -ne 1 ]] &&  {
 113         echo "--DIAG: [${assertion}, test 1]
 114         svccfg expected to return 0, got $ret"
 115 
 116         TEST_RESULT=$STF_FAIL
 117 }
 118 
 119 # Verify that nothing in stdout - non-fatal error
 120 [[ -s $OUTFILE ]] &&  {
 121         echo "--DIAG: [${assertion}, test 1]
 122         stdout not expected, but got $(cat $OUTFILE)"
 123 
 124         TEST_RESULT=$STF_FAIL
 125 }
 126 
 127 NO_MATCH="doesn't match any instances or services"
 128 EMSG="svccfg: Pattern '$TEST_SERVICE_FMRI' $NO_MATCH"
 129 
 130 # Verify message to stderr - non-fatal error
 131 if ! egrep -s "$EMSG" $ERRFILE
 132 then
 133         echo "--DIAG: [${assertion}, test 1]
 134         Expected error message \"$EMSG\"
 135         but got \"$(cat $ERRFILE)\""
 136 
 137         TEST_RESULT=$STF_FAIL
 138 fi
 139 
 140 rm -f $ERRFILE $OUTFILE 
 141 
 142 print_result $TEST_RESULT
 143 RESULT=$(update_result $TEST_RESULT $RESULT)
 144 
 145 #
 146 # Test #2: Non-existent instance
 147 #
 148 
 149 echo "--INFO: Starting $assertion, test 2 (select non-existent instance)"
 150 
 151 typeset -i TEST_RESULT=$STF_PASS
 152 
 153 #
 154 # Add the service.  If this fails consider it a fatal error
 155 #
 156 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 157 ret=$?
 158 [[ $ret -ne 0 ]] && {
 159         echo "--DIAG: [${assertion}]
 160         error adding service $TEST_SERVICE needed for test
 161         error output is $(cat $ERRFILE)"
 162 
 163         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 164         exit $RESULT
 165 }
 166 
 167 # Make sure the service is there
 168 service_exists $TEST_SERVICE_FMRI
 169 [[ $? -ne 0 ]] && {
 170         echo "--DIAG: [${assertion}, test 2]
 171         service $TEST_SERVICE_FMRI  should exist in
 172         repository after being added, but does not"
 173 
 174         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 175         exit $RESULT
 176 }
 177 
 178 #  Create svccfg file that select an non-existent instance
 179 cat <<EOF >$CMDFILE
 180 select ${TEST_SERVICE_FMRI}
 181 select ${TEST_INSTANCE}
 182 end
 183 EOF
 184 
 185 
 186 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 187 ret=$?
 188 
 189 # Verify that the return value is as expected - non-fatal error
 190 [[ $ret -ne 1 ]] &&  {
 191         echo "--DIAG: [${assertion}, test 2]
 192         svccfg expected to return 0, got $ret"
 193 
 194         TEST_RESULT=$STF_FAIL
 195 }
 196 
 197 # Verify that nothing in stdout - non-fatal error
 198 [[ -s $OUTFILE ]] &&  {
 199         echo "--DIAG: [${assertion}, test 2]
 200         stdout not expected, but got $(cat $OUTFILE)"
 201 
 202         TEST_RESULT=$STF_FAIL
 203 }
 204 
 205 NO_MATCH="doesn't match any instances or services"
 206 EMSG="svccfg ($CMDFILE, line 2): Pattern '$TEST_INSTANCE' $NO_MATCH"
 207 
 208 # Verify message to stderr - non-fatal error
 209 if ! grep -sl "$EMSG" $ERRFILE >/dev/null 2>&1
 210 then
 211         echo "--DIAG: [${assertion}, test 1]
 212         Expected error message:
 213 $EMSG
 214         but got:
 215 $(cat $ERRFILE)"
 216 
 217         TEST_RESULT=$STF_FAIL
 218 fi
 219 
 220 rm -f $ERRFILE $OUTFILE $CMDFILE
 221 
 222 print_result $TEST_RESULT
 223 RESULT=$(update_result $TEST_RESULT $RESULT)
 224 
 225 exit $RESULT