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_list_001
  32 #
  33 # DESCRIPTION:
  34 #       The 'list' subcommand lists all children of the current 
  35 #       selection.  If the current selection is an entity the 
  36 #       output also contains ":properties".
  37 #
  38 # STRATEGY:
  39 #       Test the following cases:
  40 #       - test at scope level
  41 #       - test at service level
  42 #       - test at instance level
  43 #       
  44 #       Note: to verify the assertion (at the scope level) we don't
  45 #       do before/after comparison of the repository listing.  This
  46 #       is because the repository may change, for whatever reason,
  47 #       while the test is running and before/after comparison would
  48 #       not be accurate.  We can't control what is going on in the
  49 #       repository outside of this test.
  50 #
  51 # end __stf_assertion__
  52 ###############################################################################
  53 
  54 # First STF library
  55 . ${STF_TOOLS}/include/stf.kshlib
  56 
  57 # Load GL library
  58 . ${STF_SUITE}/include/gltest.kshlib
  59 
  60 readonly ME=$(whence -p ${0})
  61 readonly MYLOC=$(dirname ${ME})
  62 
  63 
  64 # Initialize test result 
  65 typeset -i RESULT=$STF_PASS
  66 
  67 # The number of service and service/instance entries that will be
  68 # used in this test.  This number can be modified.
  69 typeset -r num_entities=10
  70 
  71 
  72 function cleanup {
  73         # Note that $TEST_SERVICE may or may not exist so don't check
  74         # results.  Just make sure the service is gone.
  75         typeset -i index=1
  76         while [ $index -le $num_entities ]
  77         do
  78                 service_delete ${TEST_SERVICE}_${index}
  79                 service_exists ${TEST_SERVICE}_${index}
  80                 [[ $? -eq 0 ]] && {
  81                         echo "--DIAG: [${assertion}, cleanup]
  82                         service ${TEST_SERVICE} should not exist in 
  83                         repository after being deleted, but does"
  84 
  85                         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  86                 }
  87                 (( index = index + 1 ))
  88         done
  89 
  90         rm -f $OUTFILE $ERRFILE $CMDFILE
  91 
  92         exit $RESULT
  93 }
  94 
  95 trap cleanup 0 1 2 15
  96 
  97 # make sure that the environment is sane - svc.configd is up and running
  98 check_gl_env
  99 [[ $? -ne 0 ]] && {
 100         echo "--DIAG: 
 101         Invalid test environment - svc.configd is not available"
 102 
 103         RESULT=$STF_UNRESOLVED 
 104         exit $RESULT
 105 }
 106 
 107 # extract and print assertion information from this source script.
 108 extract_assertion_info $ME
 109 
 110 assertion=svccfg_list_001
 111 
 112 #
 113 # Setup - create $num_entities services and $num_entities service/instance
 114 #
 115 typeset -i index=1
 116 while [ $index -le $num_entities ]
 117 do
 118         SERVICE=${TEST_SERVICE}_${index}
 119 
 120         svccfg add $SERVICE > /dev/null 2>&1
 121 
 122         service_exists $SERVICE
 123         [[ $? -ne 0 ]] && {
 124                 echo "--DIAG: [${assertion}, setup]
 125                 EXPECTED: service ${SERVICE} exists
 126                 OBSERVED: service ${SERVICE} does not exist"
 127 
 128                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 129                 exit $RESULT
 130         }
 131         typeset -i i=1
 132         while [ $i -le $num_entities ]
 133         do
 134                 cat <<EOF >> $CMDFILE
 135                 select ${SERVICE}
 136                 add ${SERVICE}_${TEST_INSTANCE}_$i
 137 EOF
 138 
 139                 (( i = i + 1 ))
 140         done
 141         svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 142         ret=$?
 143 
 144         # Verify that the return value is as expected - fatal error
 145         [[ $ret -ne 0 ]] &&  {
 146                 echo "--DIAG: [${assertion}, setup]
 147                 EXPECTED: svccfg returned 0
 148                 OBSERVED: svccfg returned $ret,
 149                 error output is $(cat $ERRFILE)"
 150 
 151                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 152                 exit $RESULT
 153         }
 154 
 155         (( index = index + 1 ))
 156 
 157         rm -f $ERRFILE $OUTFILE $CMDFILE
 158 done
 159 
 160         
 161 # 
 162 # Test #1: verify list at the scope level
 163 #
 164 
 165 echo "--INFO: Verify list at the scope level"
 166 
 167 typeset -i TEST_RESULT=$STF_PASS
 168 
 169 svccfg list > $OUTFILE 2>$ERRFILE
 170 ret=$?
 171 [[ $ret -ne 0 ]] &&  {
 172         echo "--DIAG: [${assertion}, test 1]
 173         svccfg expected to return 0, got $ret"
 174 
 175         TEST_RESULT=$STF_FAIL 
 176 }
 177 
 178 # Check that something is in stdout - we can't check the output
 179 # because there is no reliable way of knowing what else is in the 
 180 # repository.
 181 [[ ! -s $OUTFILE ]] &&  {
 182         echo "--DIAG: [${assertion}, test 1]
 183         stdout expected, but got nothing"
 184 
 185         TEST_RESULT=$STF_FAIL
 186 }
 187 
 188 # Verify that nothing in stderr - non-fatal error
 189 [[ -s $ERRFILE ]] &&  {
 190         echo "--DIAG: [${assertion}, test 1]
 191         stdout not expected, but got $(cat $OUTFILE)"
 192 
 193         TEST_RESULT=$STF_FAIL
 194 }
 195 
 196 # Verify that :properties not showing up at scope level.  
 197 if  egrep -s "^:properties$" $OUTFILE
 198 then
 199         echo "--DIAG: [${assertion}, test 1]
 200         did not expect :properties at scope level"
 201 
 202         TEST_RESULT=$STF_FAIL
 203 fi
 204 
 205 # Verify that service that were setup are showing up . . .
 206 typeset -i lines
 207 index=1
 208 while [ $index -le $num_entities ]
 209 do
 210         SERVICE=${TEST_SERVICE}_${index}
 211         lines=$(egrep -c "^${SERVICE}$" $OUTFILE)
 212         [[ $lines -ne 1 ]]  &&  {
 213                 echo "--DIAG: [${assertion}, test 1]
 214                 expected list subcommand to show $SERVICE, but did not"
 215 
 216                 TEST_RESULT=$STF_FAIL
 217         }
 218 
 219         ((index = index + 1 ))
 220 done
 221 
 222 rm -f $ERRFILE $OUTFILE  $CMDFILE
 223 
 224 print_result $TEST_RESULT
 225 RESULT=$(update_result $TEST_RESULT $RESULT)
 226 
 227  
 228 # Test #2: verify list at the service level
 229 #
 230 
 231 echo "--INFO: Verify list at the service level"
 232 
 233 typeset -i TEST_RESULT=$STF_PASS
 234 
 235 # Pick any test service
 236 SERVICE=${TEST_SERVICE}_1
 237 
 238 cat  << EOF > $CMDFILE
 239 select ${SERVICE}
 240 list
 241 EOF
 242 
 243 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 244 ret=$?
 245 [[ $ret -ne 0 ]] &&  {
 246         echo "--DIAG: [${assertion}]
 247         svccfg expected to return 0, got $ret
 248         error output is $(cat $ERRFILE)"
 249 
 250         TEST_RESULT=$STF_FAIL
 251 }
 252 
 253 
 254 #
 255 # Make sure that the instances in the service are showing up
 256 #
 257 index=1
 258 while [ $index -le $num_entities ]
 259 do
 260         pattern=${SERVICE}_${TEST_INSTANCE}_$index
 261         lines=$(egrep -c "^$pattern$" $OUTFILE)
 262         [[ $lines -ne 1 ]]  &&  {
 263                 echo "--DIAG: [${assertion}, test 2]
 264                 expected list subcommand to show $pattern, but did not"
 265 
 266                 TEST_RESULT=$STF_FAIL
 267         }
 268 
 269         ((index = index + 1 ))
 270 done
 271 
 272 # Make sure that :properties shows up
 273 if  ! egrep -s "^:properties$" $OUTFILE > /dev/null 2>&1
 274 then
 275         echo "--DIAG: [${assertion}, test 2]
 276         expected :properties at service level but did not get"
 277 
 278         TEST_RESULT=$STF_FAIL
 279 fi
 280 
 281 rm -f $ERRFILE $OUTFILE $CMDFILE
 282 
 283 print_result $TEST_RESULT
 284 RESULT=$(update_result $TEST_RESULT $RESULT)
 285 
 286 # 
 287 # Test #3: verify list at the instance level
 288 #
 289 
 290 
 291 echo "--INFO: Verify list at the instance level"
 292 
 293 typeset -i TEST_RESULT=$STF_PASS
 294 
 295 # Pick any test service & instance
 296 SERVICE=${TEST_SERVICE}_1
 297 INSTANCE=${TEST_INSTANCE}_1
 298 
 299 cat  << EOF > $CMDFILE
 300 select ${SERVICE}
 301 select ${SERVICE}_${INSTANCE}
 302 list
 303 EOF
 304 
 305 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 306 ret=$?
 307 [[ $ret -ne 0 ]] &&  {
 308         echo "--DIAG: [${assertion}]
 309         svccfg expected to return 0, got $ret
 310         error output is $(cat $ERRFILE)"
 311 
 312         TEST_RESULT=$STF_FAIL
 313 }
 314 
 315 # Make sure that there is only one entry - ":properties"
 316 
 317 lines=$(wc -l $OUTFILE | awk '{print $1}')
 318 [[ $lines -ne 1 ]] &&  {
 319         echo "--DIAG: [${assertion}, test 3]
 320         expected only :properties entry, but got $(cat $OUTFILE)"
 321 
 322         TEST_RESULT=$STF_FAIL
 323 }
 324 
 325 if  ! egrep -s "^:properties$" $OUTFILE > /dev/null 2>&1
 326 then
 327         echo "--DIAG: [${assertion}, test 3]
 328         expected :properties at service level but did not get"
 329 
 330         TEST_RESULT=$STF_FAIL
 331 fi
 332 
 333 
 334 rm -f $ERRFILE $OUTFILE $CMDFILE
 335 
 336 print_result $TEST_RESULT
 337 RESULT=$(update_result $TEST_RESULT $RESULT)
 338 
 339 exit $RESULT
 340