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_005
  32 #
  33 # DESCRIPTION:
  34 #       The 'delprop' subcommand expects one argument.  Passing zero or
  35 #       more than one argument to 'delprop' will result in a diagnostic
  36 #       message sent to stderr and the subcommand exiting with a status
  37 #       of 1.
  38 #
  39 # end __stf_assertion__
  40 ###############################################################################
  41 
  42 
  43 # First STF library
  44 . ${STF_TOOLS}/include/stf.kshlib
  45 
  46 # Load GL library
  47 . ${STF_SUITE}/include/gltest.kshlib
  48 
  49 # Assertion ID
  50 readonly assertion=svccfg_delprop_005
  51 
  52 readonly ME=$(whence -p ${0})
  53 readonly MYLOC=$(dirname ${ME})
  54 
  55 # Initialize test result 
  56 typeset -i RESULT=$STF_PASS
  57 
  58 function cleanup {
  59 
  60         # Note that $TEST_SERVICE may or may not exist so don't check
  61         # results.  Just make sure the service is gone.
  62         service_delete $TEST_SERVICE > /dev/null 2>&1
  63 
  64         service_exists ${TEST_SERVICE}
  65         [[ $? -eq 0 ]] && {
  66                 echo "--DIAG: [${assertion}, cleanup]
  67                 service ${TEST_SERVICE} should not exist in
  68                 repository after being deleted, but does"
  69 
  70                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  71         }
  72 
  73         rm -f $OUTFILE $ERRFILE $CMDFILE
  74         exit $RESULT 
  75 } 
  76 
  77 trap cleanup 0 1 2 15
  78 
  79 # make sure that the environment is sane - svc.configd is up and running
  80 check_gl_env
  81 [[ $? -ne 0 ]] && {
  82         echo "--DIAG:
  83         Invalid test environment - svc.configd not available"
  84 
  85         RESULT=$STF_UNRESOLVED 
  86         exit $RESULT
  87 }
  88 
  89 # extract and print assertion information from this source script.
  90 extract_assertion_info $ME
  91 
  92 cat << EOF > $CMDFILE
  93 add $TEST_SERVICE
  94 select $TEST_SERVICE
  95 addpg $TEST_PROPERTY framework
  96 setprop $TEST_PROPERTY/foo = astring: "foo_bar"
  97 EOF
  98 
  99 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 100 ret=$?
 101 [[ $ret -ne 0 ]] && {
 102         echo "--DIAG: [${assertion}, setup]
 103         svccfg expected to return 0, got $ret
 104         error output is $(cat $ERRFILE)"
 105 
 106         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 107         exit $RESULT
 108 }
 109 
 110 
 111 # Call delprop with extra options
 112 
 113 cat << EOF > $CMDFILE
 114 select $TEST_SERVICE
 115 delprop $TEST_PROPERTY/foo extraoption_1 extraoption_2 extraoption_3
 116 EOF
 117 
 118 
 119 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 120 ret=$?
 121 
 122 # Verify that the return value is as expected
 123 [[ $ret -ne 1 ]] &&  {
 124         echo "--DIAG: [${assertion}]
 125         svccfg expected to return 1, got $ret"
 126 
 127         RESULT=$STF_FAIL
 128 }
 129 
 130 # Verify that nothing in stdout
 131 [[ -s $OUTFILE ]] &&  {
 132         echo "--DIAG: [${assertion}]
 133         did not expect stdout, but got:
 134         $(cat $OUTFILE)"
 135 
 136         RESULT=$STF_FAIL
 137 }
 138 
 139 # Verify that message in stderr - non-fatal error
 140 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
 141 then
 142         echo "--DIAG: [${assertion}]
 143         Expected error message \"$SYNTAX_ERRMSG\"
 144         but got \"$(cat $ERRFILE)\""
 145 
 146         RESULT=$STF_FAIL
 147 fi
 148 
 149 # Verify that the property is still in the repository
 150 svcprop -p $TEST_PROPERTY $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 151 ret=$?
 152 
 153 # Verify that the return value is as expected
 154 [[ $ret -ne 0 ]] &&  {
 155         echo "--DIAG: [${assertion}]
 156         svcprop encountered an unexpected error:
 157         $(cat $ERRFILE)"
 158 
 159         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 160         exit $RESULT
 161 }
 162 
 163 [[ -s $ERRFILE ]] &&  {
 164         echo "--DIAG: [${assertion}]
 165         error message unexpected returned from svcprop:
 166         $(cat $ERRFILE)"
 167 
 168         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 169         exit $RESULT
 170 }
 171 
 172 
 173 [[ ! -s $OUTFILE ]] &&  {
 174         echo "--DIAG: [${assertion}]
 175         property $TEST_PROPERTY expected in repository but
 176         svcprop not reporting it."
 177 
 178         RESULT=$STF_FAIL
 179 }
 180 
 181 if ! egrep -s "$TEST_PROPERTY" $OUTFILE
 182 then
 183         echo "--DIAG: [${assertion}]
 184         Expected output to display $TEST_PROPERTY information but got:
 185         $(cat $OUTFILE)"
 186 
 187         RESULT=$STF_FAIL
 188 fi
 189 
 190 rm -f $OUTFILE $ERRFILE $CMDFILE
 191 
 192 
 193 exit $RESULT
 194 
 195 
 196 
 197