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