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_002
  32 #
  33 # DESCRIPTION:
  34 #       The subcommand "select fmri" selects the entity whose absolute
  35 #       or relative fmri has been specified by the fmri parameter.  On
  36 #       success, no error is seen and the exit status is 0
  37 #
  38 # STRATEGY:
  39 #       No separate test case is required for this assertion; it will be
  40 #       tested by other test cases that use the "select" clause.
  41 #
  42 # end __stf_assertion__
  43 ###############################################################################
  44 
  45 
  46 # First STF library
  47 . ${STF_TOOLS}/include/stf.kshlib
  48 
  49 # Load GL library
  50 . ${STF_SUITE}/include/gltest.kshlib
  51 
  52 # Assertion ID
  53 readonly assertion=svccfg_select_002
  54 
  55 readonly ME=$(whence -p ${0})
  56 readonly MYLOC=$(dirname ${ME})
  57 
  58 # Initialize test result 
  59 typeset -i RESULT=$STF_PASS
  60 
  61 typeset -r  num_entities=10
  62 
  63 function cleanup {
  64         
  65         # Note that $TEST_SERVICE_FMRI may or may not exist so don't check
  66         # results.  Just make sure the service is gone.
  67         typeset i=1
  68         while [[ $i -le $num_entities ]]  
  69         do
  70                 service_delete ${TEST_SERVICE_FMRI}_$i > /dev/null 2>&1
  71 
  72                 service_exists ${TEST_SERVICE_FMRI}_$i
  73                 [[ $? -eq 0 ]] && {
  74                         echo "--DIAG: [${assertion}, cleanup] 
  75                         service ${TEST_SERVICE_FMRI} should not exist in
  76                         repository after being deleted, but does"
  77         
  78                         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  79                 }
  80                 (( i = i + 1 ))
  81         done
  82 
  83         rm -f $OUTFILE $ERRFILE $CMDFILE
  84         exit $RESULT
  85 }
  86 
  87 trap cleanup 0 1 2 15
  88 
  89 # make sure that the environment is sane - svc.configd is up and running
  90 check_gl_env
  91 [[ $? -ne 0 ]] && {
  92         print_err "$assertion: invalid test environment"
  93         exit $STF_UNRESOLVED
  94 }
  95 
  96 # extract and print assertion information from this source script.
  97 extract_assertion_info $ME
  98 
  99 typeset -i index=1
 100 # create the test services/instance for testing
 101 while [ $index -le $num_entities ]
 102 do
 103         SERVICE=${TEST_SERVICE}_${index}
 104 
 105         service_exists $SERVICE
 106         [[ $? -eq 0 ]] && {
 107                 echo "--DIAG: [${assertion}, setup]
 108                 service ${SERVICE} should not exist in
 109                 repository for test to run."
 110 
 111                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 112                 exit $RESULT
 113         }
 114 
 115         svccfg add $SERVICE > $OUTFILE 2>$ERRFILE
 116         [[ $? -ne 0 ]] && {
 117                 echo "--DIAG: [${assertion}, setup]
 118                 error adding service ${SERVICE}, can not continue test
 119                 error output is $(cat $ERRFILE)"
 120 
 121                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 122                 exit $RESULT
 123         }
 124 
 125         #  Create svccfg file that select an non-existent instance
 126         i=1
 127         while [ $i -le $num_entities ] 
 128         do
 129                 cat <<EOF >>$CMDFILE
 130                 select ${SERVICE}
 131                 add ${SERVICE}_${TEST_INSTANCE}_$i
 132 EOF
 133                 (( i = i + 1 ))
 134         done
 135 
 136         svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 137         ret=$?
 138 
 139         # Verify that the return value is as expected - fatal error
 140         [[ $ret -ne 0 ]] &&  {
 141                 echo "--DIAG: [${assertion}, setup]
 142                 svccfg expected to return 0, got $ret
 143                 error output is $(cat $ERRFILE)"
 144 
 145                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 146 
 147                 exit $RESULT
 148                 
 149         }
 150 
 151         (( index = index + 1 ))
 152 
 153         rm -f $OUTFILE $ERRFILE $CMDFILE
 154 done
 155 
 156 
 157 # 
 158 # Now execute the test
 159 #
 160 
 161 typeset -i index=1
 162 # create the test services/instance for testing
 163 while [ $index -le $num_entities ]
 164 do
 165 
 166         echo "--INFO: Starting $assertion, test $index"
 167         typeset -i TEST_RESULT=$STF_PASS
 168 
 169         ((nindex = (index % num_entities) + 1))
 170 
 171         SERVICE_FMRI=${TEST_SERVICE_FMRI}_$index        
 172         NSERVICE_FMRI=${TEST_SERVICE_FMRI}_${nindex}
 173         NSERVICE=${TEST_SERVICE}_${nindex}
 174         INSTANCE=${TEST_SERVICE}_${index}_${TEST_INSTANCE}_${index}
 175 
 176         #  Create svccfg file that select an non-existent instance
 177         cat <<EOF >$CMDFILE
 178         select ${SERVICE_FMRI}
 179         select ${NSERVICE_FMRI}
 180         list ${NSERVICE}*
 181         select ${SERVICE_FMRI}:${INSTANCE}
 182         list 
 183         end
 184 EOF
 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 0 ]] &&  {
 191                 echo "--DIAG: [${assertion}, test $index]
 192                 svccfg select expected to return 0, got $ret"
 193 
 194                 TEST_RESULT=$STF_FAIL
 195         }
 196 
 197         # Verify that nothing in stderr - non-fatal error
 198         [[ -s $ERRFILE ]] &&  {
 199                 echo "--DIAG: [${assertion}, test $index]
 200                 stderr not expected, but got $(cat $ERRFILE)"
 201 
 202                 TEST_RESULT=$STF_FAIL
 203         }
 204 
 205         # Verify the output of the file 
 206         num_lines=$(egrep -c ":properties" $OUTFILE)
 207         [[ $num_lines -ne 2 ]] && {
 208                 echo "--DIAG: [${assertion}, test $index]
 209                 expected 2 \":properties\" lines"
 210 
 211                 TEST_RESULT=$STF_FAIL
 212         }
 213 
 214         typeset i=1
 215         while [ $i -le $num_entities ] 
 216         do
 217                 num_lines=$(egrep -c "^${NSERVICE}_${TEST_INSTANCE}_${i}$" $OUTFILE)
 218                 [[ $num_lines -ne 1 ]] && {
 219                         echo "--DIAG: [${assertion}, test $index]
 220         expected list to show ${NSERVICE}_${TEST_INSTANCE}_$i but did not"
 221                         
 222                         TEST_RESULT=$STF_FAIL
 223                 }
 224                 (( i = i + 1 ))
 225         done
 226 
 227         num_lines=$(wc -l $OUTFILE | awk '{print $1}')
 228 
 229         (( total_lines = num_entities + 2 ))
 230 
 231         [[ $num_lines -ne $total_lines ]]  && {
 232                 echo "--DIAG: [${assertion}, test $index]
 233         expected $total_lines, lines but got $num_lines"
 234 
 235                 TEST_RESULT=$STF_FAIL
 236         }
 237         [[ $TEST_RESULT -eq $STF_FAIL ]]  && {
 238                 echo "--DIAG: Here is the output:
 239                 $(cat $OUTFILE)"
 240         }
 241                 
 242         (( index = index + 1 ))
 243 
 244         rm -f $OUTFILE $ERRFILE $CMDFILE
 245 
 246         print_result $TEST_RESULT
 247 
 248         RESULT=$(update_result $TEST_RESULT $RESULT)
 249 done
 250 
 251 exit $RESULT
 252 
 253