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_002
  32 #
  33 # DESCRIPTION:
  34 #       The 'addpg name type [flags]' subcommand adds a property 
  35 #       group of name 'name' and type 'type' to the currently 
  36 #       selected entity.  If the flags argument is "P" then 
  37 #       the SCF_PG_FLAG_NONPERSISTENT flag is set.  If the flags 
  38 #       argument is "p" then the SCF_PG_FLAG_NONPERSISTENT flag is 
  39 #       cleared.
  40 #
  41 # STRATEGY:
  42 #       This assertion has two subtests:
  43 #       1) add a property group to a service with the P flag
  44 #       2) add a property group to a service with the p flag (this 
  45 #          should be the same as not adding a flag)
  46 #       3) add a property group to a instance with the P flag
  47 #       4) add a property group to a instance with the p flag (this 
  48 #          should be the same as not adding a flag)
  49 #
  50 #       Both of these subtests is performed from a svccfg command
  51 #       file.
  52 #
  53 # end __stf_assertion__
  54 ###############################################################################
  55 
  56 # First STF library
  57 . ${STF_TOOLS}/include/stf.kshlib
  58 
  59 # Load GL library
  60 . ${STF_SUITE}/include/gltest.kshlib
  61 
  62 
  63 readonly ME=$(whence -p ${0})
  64 readonly MYLOC=$(dirname ${ME})
  65 
  66 # Initialize test result 
  67 typeset -i RESULT=$STF_PASS
  68 
  69 
  70 function cleanup {
  71         
  72         # Note that $TEST_SERVICE may or may not exist so don't check
  73         # results.  Just make sure the service is gone.
  74         service_delete $TEST_SERVICE > /dev/null 2>&1
  75 
  76         service_exists ${TEST_SERVICE}
  77         [[ $? -eq 0 ]] && {
  78                 echo "--DIAG: [${assertion}, cleanup]
  79                 service ${TEST_SERVICE} should not exist in 
  80                 repository after being deleted, but does"
  81 
  82                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  83         }
  84 
  85         rm -f $OUTFILE $ERRFILE $CMDFILE
  86 
  87         exit $RESULT
  88 }
  89 
  90 trap cleanup 0 1 2 15
  91 
  92 # make sure that the environment is sane - svc.configd is up and running
  93 check_gl_env
  94 [[ $? -ne 0 ]] && {
  95         echo "--DIAG: 
  96         Invalid test environment - svc.configd not available"
  97 
  98         RESULT=$STF_UNRESOLVED
  99         exit $RESULT
 100 }
 101 
 102 # extract and print assertion information from this source script.
 103 extract_assertion_info $ME
 104 
 105 assertion=svccfg_addpg_002
 106 
 107 typeset -i test_id=1
 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 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 
 137 # 
 138 # Test #1, #2: Add a pg to a service with a P and p flag
 139 #
 140 
 141 for pgflag in P p
 142 do
 143 
 144         typeset -i TEST_RESULT=$STF_PASS
 145 
 146         echo "--INFO: Starting $assertion, test $test_id ($pgflag flag)" 
 147         ((test_id = test_id + 1))
 148 
 149         THIS_PROPERTY=${TEST_PROPERTY}_$pgflag
 150 
 151         #
 152         # Add a property group to the service
 153         #
 154         cat << EOF >$CMDFILE
 155         select ${TEST_SERVICE}
 156         addpg ${THIS_PROPERTY} astring $pgflag
 157 EOF
 158 
 159         svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 160         ret=$?
 161 
 162         # Verify that the return value is as expected - non-fatal error
 163         [[ $ret -ne 0 ]] &&  {
 164                 echo "--DIAG: [${assertion}, test $test_id]
 165                 svccfg expected to return 0, got $ret
 166                 error output is $(cat $ERRFILE)"
 167 
 168                 TEST_RESULT=$STF_FAIL
 169         }
 170 
 171         # Verify that nothing in stdout - non-fatal error
 172         [[ -s $OUTFILE ]] &&  {
 173                 echo "--DIAG: [${assertion}, test $test_id]
 174                 stdout not expected, but got $(cat $OUTFILE)"
 175 
 176                 TEST_RESULT=$STF_FAIL
 177         }
 178 
 179         # Verify that nothing in stderr - non-fatal error
 180         [[ -s $ERRFILE ]] &&  {
 181                 echo "--DIAG: [${assertion}, test $test_id]
 182                 stderr not expected, but got $(cat $ERRFILE)"
 183 
 184                 TEST_RESULT=$STF_FAIL
 185         }
 186 
 187         #
 188         # Check that the property group exists - fatal error
 189         #
 190         svcprop -p $THIS_PROPERTY $TEST_SERVICE > /dev/null 2>&1
 191         ret=$?
 192         [[ $ret -ne 0 ]] &&  {
 193                 echo "--DIAG: [${assertion}, test $test_id]
 194                 property group $THIS_PROPERTY 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 done
 205 
 206 # 
 207 # Create the instance - if this fails it's a fatal error
 208 #
 209 cat <<EOF >$CMDFILE
 210 select ${TEST_SERVICE}
 211 add ${TEST_INSTANCE}
 212 EOF
 213 
 214 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 215 ret=$?
 216 
 217 [[ $ret -ne 0 ]] && {
 218         echo "--DIAG: [${assertion}]
 219         svccfg add expected to return 0, got $ret
 220         error output is $(cat $ERRFILE)"
 221         
 222         exit $STF_UNRESOLVED
 223 }
 224 
 225 # Make sure the service is there
 226 service_exists ${TEST_SERVICE}:${TEST_INSTANCE}
 227 [[ $? -ne 0 ]] && {
 228         echo "--DIAG: [${assertion}]
 229         service $TEST_SERVICE should exist in
 230         repository after being added, but does not"
 231 
 232         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 233         exit $RESULT
 234 }
 235 
 236 # 
 237 # Test #3, #4: Add a pg to an instance with a P and p flag
 238 #
 239 
 240 for pgflag in P p
 241 do
 242 
 243         typeset -i TEST_RESULT=$STF_PASS
 244         echo "--INFO: Starting $assertion, test $test_id ($pgflag flag instance)" 
 245         ((test_id = test_id + 1))
 246 
 247         THIS_PROPERTY=${TEST_PROPERTY}_$pgflag
 248 
 249         #
 250         # Add a property group to the service
 251         #
 252         cat << EOF >$CMDFILE
 253         select ${TEST_SERVICE}
 254         select ${TEST_INSTANCE}
 255         addpg ${THIS_PROPERTY} astring $pgflag
 256 EOF
 257 
 258         svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 259         ret=$?
 260 
 261         # Verify that the return value is as expected - non-fatal error
 262         [[ $ret -ne 0 ]] &&  {
 263                 echo "--DIAG: [${assertion}, test $test_id]
 264                 svccfg expected to return 0, got $ret
 265                 error output is $(cat $ERRFILE)"
 266 
 267                 TEST_RESULT=$STF_FAIL
 268         }
 269 
 270         # Verify that nothing in stdout - non-fatal error
 271         [[ -s $OUTFILE ]] &&  {
 272                 echo "--DIAG: [${assertion}, test $test_id]
 273                 stdout not expected, but got $(cat $OUTFILE)"
 274 
 275                 TEST_RESULT=$STF_FAIL
 276         }
 277 
 278         # Verify that nothing in stderr - non-fatal error
 279         [[ -s $ERRFILE ]] &&  {
 280                 echo "--DIAG: [${assertion}, test 1]
 281                 stderr not expected, but got $(cat $ERRFILE)"
 282 
 283                 TEST_RESULT=$STF_FAIL
 284         }
 285 
 286         #
 287         # Check that the property group exists - fatal error
 288         #
 289         svcprop -p $THIS_PROPERTY ${TEST_SERVICE}:${TEST_INSTANCE} > /dev/null 2>&1
 290         ret=$?
 291         [[ $ret -ne 0 ]] &&  {
 292                 echo "--DIAG: [${assertion}, test $test_id]
 293                 property group $THIS_PROPERTY does not exist"
 294 
 295                 TEST_RESULT=$STF_FAIL
 296         }
 297 
 298 
 299         rm -f $ERRFILE $OUTFILE $CMDFILE
 300 
 301         print_result $TEST_RESULT
 302         RESULT=$(update_result $TEST_RESULT $RESULT)
 303 done
 304 
 305 exit $RESULT