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_008
  32 #
  33 # DESCRIPTION:
  34 #       The entity name passed to the select command is first treated
  35 #       as a relative name to the current selection.  If this can not
  36 #       be satisfied it will be treated as an absolute name.
  37 #
  38 # STRATEGY:
  39 #       Create a instance name which is the same as a service name,
  40 #       say foo. Test the following conditions:
  41 #       - Call 'select foo' from the command line.  Should select
  42 #         the service foo.
  43 #       - Call 'select foo' with the current selection being the service
  44 #         in which the foo instance is defined.  The selection should
  45 #         be the foo instance.
  46 #       - Call 'select foo' from within "foo" instance.  Should 
  47 #         select the foo service.
  48 #
  49 # end __stf_assertion__
  50 ###############################################################################
  51 
  52 # First STF library
  53 . ${STF_TOOLS}/include/stf.kshlib
  54 
  55 # Load GL library
  56 . ${STF_SUITE}/include/gltest.kshlib
  57 
  58 
  59 readonly ME=$(whence -p ${0})
  60 readonly MYLOC=$(dirname ${ME})
  61 
  62 # Initialize test result 
  63 typeset -i RESULT=$STF_PASS
  64 
  65 
  66 typeset COMMON_NAME=foo_$$
  67 typeset OTHER_NAME=dummy
  68 set -A TEST_SERVICE_ARRAY ${TEST_SERVICE} ${COMMON_NAME}
  69 set -A TEST_INSTANCE_ARRAY ${COMMON_NAME} ${OTHER_NAME}
  70 
  71 function cleanup {
  72         
  73         for index in 0 1
  74         do
  75                 TEST_SERVICE=${TEST_SERVICE_ARRAY[$index]}
  76 
  77                 # Note that $TEST_SERVICE may or may not exist so don't check
  78                 # results.  Just make sure the service is gone.
  79                 service_delete $TEST_SERVICE> /dev/null 2>&1
  80 
  81                 service_exists svc://${TEST_SERVICE}
  82                 [[ $? -eq 0 ]] && {
  83                         echo "--DIAG: [${assertion}, cleanup]
  84                 service ${TEST_SERVICE} should not exist in 
  85                 repository after being deleted, but does"
  86 
  87                         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  88                 }
  89         done
  90 
  91         rm -f $OUTFILE $ERRFILE $CMDFILE
  92 
  93         exit $RESULT
  94 }
  95 
  96 trap cleanup 0 1 2 15
  97 
  98 # make sure that the environment is sane - svc.configd is up and running
  99 check_gl_env
 100 [[ $? -ne 0 ]] && {
 101         echo "--DIAG: 
 102         Invalid test environment -svc.configd not available"
 103 
 104         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 105         exit $RESULT
 106 }
 107 
 108 # extract and print assertion information from this source script.
 109 extract_assertion_info $ME
 110 
 111 assertion=svccfg_select_008
 112 
 113 #
 114 # Setup: setup two test services (one called 'foo') and one instance
 115 #       of the first test service (called 'foo').
 116 #
 117 
 118 for index in 0 1
 119 do
 120         TEST_SERVICE=${TEST_SERVICE_ARRAY[$index]}
 121         TEST_INSTANCE=${TEST_INSTANCE_ARRAY[$index]}
 122 
 123         service_exists svc://$TEST_SERVICE
 124         [[ $? -eq 0 ]] && {
 125                 echo "--DIAG: [${assertion}, setup]
 126                 service ${TEST_SERVICE} should not exist in
 127                 repository for test to run."
 128 
 129                 svccfg list
 130                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 131                 exit $RESULT
 132         }
 133 
 134         cat <<EOF>$CMDFILE
 135         add ${TEST_SERVICE}
 136         select ${TEST_SERVICE}
 137         add ${TEST_INSTANCE}
 138         end
 139 EOF
 140 
 141         svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 142         ret=$?
 143         [[ $ret -ne 0 ]] && {
 144                 echo "--DIAG: [${assertion}, setup] 
 145                 error adding service ${TEST_SERVICE} and service
 146                 instance ${TEST_INSTANCE}, can not continue test
 147                 error output is $(cat $ERRFILE)"
 148 
 149                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 150                 exit $RESULT
 151         }
 152 done
 153 
 154 # 
 155 # Test #1: Calling 'foo' from comand line
 156 #
 157 
 158 echo "--INFO: Starting $assertion, calling \"common\" service"
 159 
 160 typeset -i TEST_RESULT=$STF_PASS
 161 
 162 cat <<EOF>$CMDFILE
 163 select ${COMMON_NAME}
 164 list
 165 end
 166 EOF
 167 
 168 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 169 ret=$?
 170 
 171 # Verify that the return value is as expected - non-fatal error
 172 [[ $ret -ne 0 ]] &&  {
 173         echo "--DIAG: [${assertion}, test 1]
 174         svccfg list expected to return 0, got $ret"
 175 
 176         TEST_RESULT=$STF_FAIL
 177 }
 178 
 179 # Verify that nothing in stderr - non-fatal error
 180 [[ -s $ERRFILE ]] &&  {
 181         echo "--DIAG: [${assertion}, test 1]
 182         stderr not expected, but got $(cat $ERRFILE)"
 183 
 184         TEST_RESULT=$STF_FAIL
 185 }
 186 
 187 
 188 # Need to verify that the stdout is correct
 189 if ! egrep -s ${OTHER_NAME} $OUTFILE
 190 then
 191         echo "--DIAG: [${assertion}, test 1]
 192         Expected ${OTHER_NAME} to be part of output
 193         but got \"$(cat $OUTFILE)\""
 194 
 195         TEST_RESULT=$STF_FAIL
 196 fi
 197 
 198 
 199 rm -f $OUTFILE $ERRFILE $CMDFILE
 200 print_result $TEST_RESULT
 201 RESULT=$(update_result $TEST_RESULT $RESULT)
 202 
 203 # 
 204 # Test #2: Calling 'foo' instance
 205 #
 206 
 207 echo "--INFO: Starting $assertion, calling \"common\" instance"
 208 
 209 typeset -i TEST_RESULT=$STF_PASS
 210 
 211 cat <<EOF >$CMDFILE
 212 select ${TEST_SERVICE_ARRAY[0]}
 213 select ${COMMON_NAME}
 214 list
 215 end
 216 EOF
 217 
 218 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 219 ret=$?
 220 
 221 # Verify that the return value is as expected - non-fatal error
 222 [[ $ret -ne 0 ]] &&  {
 223         echo "--DIAG: [${assertion}, test 2]
 224         svccfg list expected to return 0, got $ret"
 225 
 226         TEST_RESULT=$STF_FAIL
 227 }
 228 
 229 # Verify that nothing in stdout - non-fatal error
 230 [[ -s $ERRFILE ]] &&  {
 231         echo "--DIAG: [${assertion}, test 2]
 232         stderr not expected, but got $(cat $ERRFILE)"
 233 
 234         TEST_RESULT=$STF_FAIL
 235 }
 236 
 237 
 238 # Need to verify that the stdout is correct
 239 if  egrep -s ${OTHER_NAME} $OUTFILE
 240 then
 241         echo "--DIAG: [${assertion}, test 2]
 242         Did not expect ${OTHER_NAME} to be part of output
 243         but got \"$(cat $OUTFILE)\""
 244 
 245         TEST_RESULT=$STF_FAIL
 246 fi
 247 
 248 
 249 rm -f $OUTFILE $ERRFILE $CMDFILE
 250 print_result $TEST_RESULT
 251 RESULT=$(update_result $TEST_RESULT $RESULT)
 252 
 253 
 254 # 
 255 # Test #3: Calling 'foo' service from 'foo' instance
 256 #
 257 
 258 echo "--INFO: Starting $assertion, calling \"common\" service (again)"
 259 
 260 typeset -i TEST_RESULT=$STF_PASS
 261 
 262 cat <<EOF >$CMDFILE
 263 select ${TEST_SERVICE_ARRAY[0]}
 264 select ${COMMON_NAME}
 265 select ${TEST_SERVICE_ARRAY[1]}
 266 list
 267 end
 268 EOF
 269 
 270 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 271 ret=$?
 272 # Verify that the return value is as expected - non-fatal error
 273 [[ $ret -ne 0 ]] &&  {
 274         echo "--DIAG: [${assertion}, test 3]
 275         svccfg select expected to return 0, got $ret"
 276 
 277         TEST_RESULT=$STF_FAIL
 278 }
 279 
 280 # Verify that nothing in stdout - non-fatal error
 281 [[ -s $ERRFILE ]] &&  {
 282         echo "--DIAG: [${assertion}, test 3]
 283         stderr not expected, but got $(cat $ERRFILE)"
 284 
 285         TEST_RESULT=$STF_FAIL
 286 }
 287 
 288 
 289 # Need to verify that the stdout is correct
 290 if  ! egrep -s ${OTHER_NAME} $OUTFILE
 291 then
 292         echo "--DIAG: [${assertion}, test 3]
 293         Expected ${OTHER_NAME} to be part of output
 294         but got \"$(cat $OUTFILE)\""
 295 
 296         TEST_RESULT=$STF_FAIL
 297 fi
 298 
 299 
 300 rm -f $OUTFILE $ERRFILE $CMDFILE
 301 print_result $TEST_RESULT
 302 RESULT=$(update_result $TEST_RESULT $RESULT)
 303