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