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_delprop_004
  32 #
  33 # DESCRIPTION:
  34 #       If the property name specified in the 'delprop pg/name' 
  35 #       subcommand does not exist in the selected entity then a 
  36 #       diagnostic message is sent to stderr and the subcommand 
  37 #       will exit with a status of 1.
  38 #
  39 # STRATEGY:
  40 #       Verify with the following conditions:
  41 #       #1: delete a property that was never defined
  42 #       #2: delete a property that was already deleted within the svccfg 
  43 #           sessions.
  44 #       #3: delete a property that was already deleted within another session.
  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 # Assertion ID
  57 readonly assertion=svccfg_delprop_004
  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 function cleanup {
  66 
  67         # Note that $TEST_SERVICE may or may not exist so don't check
  68         # results.  Just make sure the service is gone.
  69         service_delete $TEST_SERVICE > /dev/null 2>&1
  70 
  71         service_exists ${TEST_SERVICE}
  72         [[ $? -eq 0 ]] && {
  73                 echo "--DIAG: [${assertion}, cleanup]
  74                 service ${TEST_SERVICE} should not exist in
  75                 repository after being deleted, but does"
  76 
  77                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  78         }
  79 
  80         rm -f $OUTFILE $ERRFILE $CMDFILE
  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 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 
 100 cat << EOF > $CMDFILE
 101 add $TEST_SERVICE
 102 select $TEST_SERVICE
 103 addpg $TEST_PROPERTY framework
 104 EOF
 105 
 106 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 107 ret=$?
 108 [[ $ret -ne 0 ]] && {
 109         echo "--DIAG: [${assertion}, setup]
 110         svccfg expected to return 0, got $ret
 111         error output is $(cat $ERRFILE)"
 112 
 113         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 114         exit $RESULT
 115 }
 116 
 117 
 118 #
 119 # Test #1: delete a property that was never defined
 120 #
 121 
 122 echo "--INFO: Starting $assertion, test 1 (delete undefined property)"
 123 
 124 typeset -i TEST_RESULT=$STF_PASS
 125 
 126 # Call delprop with extra options
 127 
 128 cat << EOF > $CMDFILE
 129 select $TEST_SERVICE
 130 delprop $TEST_PROPERTY/foo
 131 EOF
 132 
 133 
 134 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 135 ret=$?
 136 
 137 # Verify that the return value is as expected
 138 [[ $ret -ne 1 ]] &&  {
 139         echo "--DIAG: [${assertion}, test 1]
 140         svccfg expected to return 1, got $ret"
 141 
 142         TEST_RESULT=$STF_FAIL
 143 }
 144 
 145 # Verify that nothing in stdout
 146 [[ -s $OUTFILE ]] &&  {
 147         echo "--DIAG: [${assertion}, test 1]
 148         did not expect stdout, but got:
 149         $(cat $OUTFILE)"
 150 
 151         TEST_RESULT=$STF_FAIL
 152 }
 153 
 154 # Verify that message in stderr - non-fatal error
 155 EXP_ERRMSG="svccfg \($CMDFILE, line 2\): No such property $TEST_PROPERTY/foo"
 156 if ! egrep -s "$EXP_ERRMSG" $ERRFILE
 157 then
 158         echo "--DIAG: [${assertion}, test 1]
 159         EXPECTED: \"$EXP_ERRMSG\"
 160         OBSERVED: \"$(cat $ERRFILE)\""
 161 
 162         TEST_RESULT=$STF_FAIL
 163 fi
 164 
 165 
 166 rm -f $OUTFILE $ERRFILE $CMDFILE
 167 
 168 print_result $TEST_RESULT
 169 RESULT=$(update_result $TEST_RESULT $RESULT)
 170 
 171 #
 172 # Test #2: delete a property that was already deleted within the 
 173 #       svccfg sessions.
 174 #
 175 
 176 echo "--INFO: Starting $assertion, test 2 (delete already deleted property"
 177 echo "          in same session"
 178 
 179 typeset -i TEST_RESULT=$STF_PASS
 180 
 181 cat << EOF > $CMDFILE
 182 select $TEST_SERVICE
 183 setprop $TEST_PROPERTY/foo = astring: "bar"
 184 EOF
 185 
 186 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 187 ret=$?
 188 [[ $ret -ne 0 ]] && {
 189         echo "--DIAG: [${assertion}, test 2]
 190         svccfg expected to return 0, got $ret
 191         error output is $(cat $ERRFILE)"
 192 
 193         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 194         exit $RESULT
 195 }
 196 
 197 cat << EOF > $CMDFILE
 198 select $TEST_SERVICE
 199 delprop $TEST_PROPERTY/foo 
 200 delprop $TEST_PROPERTY/foo
 201 EOF
 202 
 203 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 204 ret=$?
 205 
 206 # Verify that the return value is as expected
 207 [[ $ret -ne 1 ]] &&  {
 208         echo "--DIAG: [${assertion}, test 2]
 209         svccfg expected to return 1, got $ret"
 210 
 211         TEST_RESULT=$STF_FAIL
 212 }
 213 
 214 # Verify that nothing in stdout
 215 [[ -s $OUTFILE ]] &&  {
 216         echo "--DIAG: [${assertion}, test 2]
 217         did not expect stdout, but got:
 218         $(cat $OUTFILE)"
 219 
 220         TEST_RESULT=$STF_FAIL
 221 }
 222 
 223 # Verify that message in stderr - non-fatal error
 224 EXP_ERRMSG="svccfg \($CMDFILE, line 3\): No such property $TEST_PROPERTY/foo"
 225 if ! egrep -s "$EXP_ERRMSG" $ERRFILE
 226 then
 227         echo "--DIAG: [${assertion}, test 2]
 228         EXPECTED: \"$EXP_ERRMSG\"
 229         OBSERVED: \"$(cat $ERRFILE)\""
 230 
 231         TEST_RESULT=$STF_FAIL
 232 fi
 233 
 234 
 235 rm -f $OUTFILE $ERRFILE $CMDFILE
 236 
 237 print_result $TEST_RESULT
 238 RESULT=$(update_result $TEST_RESULT $RESULT)
 239 
 240 
 241 #
 242 # Test #3: delete a property that was already deleted within another session.
 243 #
 244 
 245 typeset -i TEST_RESULT=$STF_PASS
 246 
 247 echo "--INFO: Starting $assertion, test 3 (delete already deleted property"
 248 echo "          in different sessions"
 249 
 250 cat << EOF > $CMDFILE
 251 select $TEST_SERVICE
 252 setprop $TEST_PROPERTY/foo = astring: "bar"
 253 EOF
 254 
 255 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 256 ret=$?
 257 [[ $ret -ne 0 ]] && {
 258         echo "--DIAG: [${assertion}, test 3]
 259         svccfg expected to return 0, got $ret
 260         error output is $(cat $ERRFILE)"
 261 
 262         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 263         exit $RESULT
 264 }
 265 
 266 cat << EOF > $CMDFILE
 267 select $TEST_SERVICE
 268 delprop $TEST_PROPERTY/foo 
 269 EOF
 270 
 271 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 272 ret=$?
 273 
 274 # Verify that the return value is as expected
 275 [[ $ret -ne 0 ]] &&  {
 276         echo "--DIAG: [${assertion}, test 3]
 277         svccfg expected to return 0, got $ret
 278         error output is $(cat $ERRFILE)"
 279 
 280         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 281         exit $RESULT
 282 }
 283 
 284 cat << EOF > $CMDFILE
 285 select $TEST_SERVICE
 286 delprop $TEST_PROPERTY/foo 
 287 EOF
 288 
 289 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 290 ret=$?
 291 
 292 # Verify that the return value is as expected
 293 [[ $ret -ne 1 ]] &&  {
 294         echo "--DIAG: [${assertion}, test 3]
 295         svccfg expected to return 1, got $ret"
 296 
 297         TEST_RESULT=$STF_FAIL
 298 }
 299 
 300 
 301 
 302 # Verify that nothing in stdout
 303 [[ -s $OUTFILE ]] &&  {
 304         echo "--DIAG: [${assertion}, test 3]
 305         did not expect stdout, but got:
 306         $(cat $OUTFILE)"
 307 
 308         TEST_RESULT=$STF_FAIL
 309 }
 310 
 311 # Verify that message in stderr - non-fatal error
 312 EXP_ERRMSG="svccfg \($CMDFILE, line 2\): No such property $TEST_PROPERTY/foo"
 313 if ! egrep -s "$EXP_ERRMSG" $ERRFILE
 314 then
 315         echo "--DIAG: [${assertion}, test 3]
 316         EXPECTED: \"$EXP_ERRMSG\"
 317         OBSERVED: \"$(cat $ERRFILE)\""
 318 
 319         TEST_RESULT=$STF_FAIL
 320 fi
 321 
 322 
 323 rm -f $OUTFILE $ERRFILE $CMDFILE
 324 
 325 print_result $TEST_RESULT
 326 RESULT=$(update_result $TEST_RESULT $RESULT)
 327 
 328 exit $RESULT
 329 
 330 
 331