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_005
  32 #
  33 # DESCRIPTION:
  34 #       If an invalid type 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 a pg of an invalid type to a service
  41 #       2) add a pg of an an invalid type 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 
  58 readonly ME=$(whence -p ${0})
  59 readonly MYLOC=$(dirname ${ME})
  60 
  61 # Initialize test result 
  62 typeset -i RESULT=$STF_PASS
  63 
  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 
  82         exit $RESULT
  83 }
  84 
  85 trap cleanup 0 1 2 15
  86 
  87 # make sure that the environment is sane - svc.configd is up and running
  88 check_gl_env
  89 [[ $? -ne 0 ]] && {
  90         echo "--DIAG: 
  91         Invalid test environment - svc.configd not available"
  92 
  93         RESULT=$STF_UNRESOLVED
  94         exit $RESULT
  95 }
  96 
  97 # extract and print assertion information from this source script.
  98 extract_assertion_info $ME
  99 
 100 assertion=svccfg_addpg_005
 101 
 102 # 
 103 # Test #1: Add a property group to a service
 104 #
 105 
 106 echo "--INFO: Starting $assertion, test 1 (add an invalid pg to a service)"
 107 
 108 typeset -i TEST_RESULT=$STF_PASS
 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 repository but does"
 116 
 117         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 118         exit $RESULT
 119 }
 120 
 121 
 122 #
 123 # Add the service.  If this fails consider it a fatal error
 124 #
 125 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 126 ret=$?
 127 [[ $ret -ne 0 ]] && {
 128         echo "--DIAG: [${assertion}]
 129         error adding service $TEST_SERVICE needed for test
 130         error output is $(cat $ERRFILE)"
 131 
 132         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 133         exit $RESULT
 134 }
 135 
 136 # Make sure the service is there
 137 service_exists $TEST_SERVICE
 138 [[ $? -ne 0 ]] && {
 139         echo "--DIAG: [${assertion}, test 1]
 140         service $TEST_SERVICE should exist in
 141         repository after being added, but does not"
 142 
 143         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 144         exit $RESULT
 145 }
 146 
 147 
 148 #
 149 # Add an invalid  property group to the service
 150 #
 151 cat <<EOF>$CMDFILE
 152 select ${TEST_SERVICE}
 153 addpg ${TEST_PROPERTY} ${INVALID_NAME} 
 154 EOF
 155 
 156 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 157 ret=$?
 158 
 159 # Verify that the return value is as expected - non-fatal error
 160 [[ $ret -ne 1 ]] &&  {
 161         echo "--DIAG: [${assertion}, test 1]
 162         svccfg add expected to return 0, got $ret"
 163 
 164         TEST_RESULT=$STF_FAIL
 165 }
 166 
 167 # Verify that nothing in stdout - non-fatal error
 168 [[ -s $OUTFILE ]] &&  {
 169         echo "--DIAG: [${assertion}, test 1]
 170         stdout not expected, but got $(cat $OUTFILE)"
 171 
 172         TEST_RESULT=$STF_FAIL
 173 }
 174 
 175 # Verify message to stderr - non-fatal error
 176 if ! egrep -s "$INVALID_ERRMSG" $ERRFILE
 177 then
 178         echo "--DIAG: [${assertion}, test 1]
 179         Expected error message \"$INVALID_ERRMSG\"
 180         but got \"$(cat $ERRFILE)\""
 181 
 182         TEST_RESULT=$STF_FAIL
 183 fi
 184 
 185 
 186 #
 187 # Check that the property group does not exist - fatal error
 188 #
 189 svcprop -p $INVALID_NAME $TEST_SERVICE_FMRI > /dev/null 2>&1
 190 ret=$?
 191 [[ $ret -eq 0 ]] &&  {
 192         echo "--DIAG: [${assertion}, test 1]
 193         property group $INVALID_NAME does not exist"
 194 
 195         TEST_RESULT=$STF_FAIL
 196 }
 197 
 198 
 199 rm -f $ERRFILE $OUTFILE $CMDFILE
 200 
 201 print_result $TEST_RESULT
 202 RESULT=$(update_result $TEST_RESULT $RESULT)
 203 
 204 # 
 205 # Test #2: Add a invalid property group to a service instance
 206 #
 207 
 208 echo "--INFO: Starting $assertion, test 2 (add an invalid pg to an instance)"
 209 
 210 typeset -i TEST_RESULT=$STF_PASS
 211 
 212 # 
 213 # Create the instance - if this fails it's a fatal error
 214 #
 215 cat <<EOF >$CMDFILE
 216 select ${TEST_SERVICE}
 217 add ${TEST_INSTANCE}
 218 EOF
 219 
 220 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 221 ret=$?
 222 
 223 [[ $ret -ne 0 ]] && {
 224         echo "--DIAG: [${assertion}, test 2]
 225         svccfg add expected to return 0, got $ret
 226         error output is $(cat $ERRFILE)"
 227         
 228         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 229         exit $RESULT
 230 }
 231                                        
 232 #
 233 # Add an invalid property group to the service instance
 234 #
 235 cat <<EOF>$CMDFILE
 236 select ${TEST_SERVICE}
 237 select ${TEST_INSTANCE}
 238 addpg ${TEST_PROPERTY} ${INVALID_NAME} 
 239 EOF
 240 
 241 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 242 ret=$?
 243 
 244 # Verify that the return value is as expected - non-fatal error
 245 [[ $ret -ne 1 ]] &&  {
 246         echo "--DIAG: [${assertion}, test 2]
 247         svccfg add expected to return 1, got $ret"
 248 
 249         TEST_RESULT=$STF_FAIL
 250 }
 251 
 252 # Verify that nothing in stdout - non-fatal error
 253 [[ -s $OUTFILE ]] &&  {
 254         echo "--DIAG: [${assertion}, test 2]
 255         stdout not expected, but got $(cat $OUTFILE)"
 256 
 257         TEST_RESULT=$STF_FAIL
 258 }
 259 
 260 # Verify that message in stderr - non-fatal error
 261 if ! egrep -s "$INVALID_ERRMSG" $ERRFILE
 262 then
 263         echo "--DIAG: [${assertion}, test 1]
 264         Expected error message \"$INVALID_ERRMSG\"
 265         but got \"$(cat $ERRFILE)\""
 266 
 267         TEST_RESULT=$STF_FAIL
 268 fi
 269 
 270 #
 271 # Check that the property group does not exist - fatal error
 272 #
 273 svcprop -p $INVALID_NAME $TEST_SERVICE > /dev/null 2>&1
 274 ret=$?
 275 [[ $ret -eq 0 ]] &&  {
 276         echo "--DIAG: [${assertion}, test 2]
 277         property group $INVALID_NAME does not exist"
 278 
 279         TEST_RESULT=$STF_FAIL
 280 }
 281 
 282 
 283 rm -f $ERRFILE $OUTFILE $CMDFILE
 284 
 285 print_result $TEST_RESULT
 286 RESULT=$(update_result $TEST_RESULT $RESULT)
 287 
 288 exit $RESULT