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_delpg_005
  32 #
  33 # DESCRIPTION:
  34 #       The 'delpg' subcommand expects one argument - the name of the
  35 #       property group.  If no arguments or more than one argument are
  36 #       given than a diagnostic message is sent to stderr and an 
  37 #       exit status of 1 is returned.
  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 
  50 readonly ME=$(whence -p ${0})
  51 readonly MYLOC=$(dirname ${ME})
  52 
  53 # Initialize test result 
  54 typeset -i RESULT=$STF_PASS
  55 
  56 
  57 function cleanup {
  58         
  59         # Note that $TEST_SERVICE may or may not exist so don't check
  60         # results.  Just make sure the service is gone.
  61         service_delete $TEST_SERVICE > /dev/null 2>&1
  62 
  63         service_exists ${TEST_SERVICE}
  64         [[ $? -eq 0 ]] && {
  65                 echo "--DIAG: [${assertion}, cleanup]
  66                 service ${TEST_SERVICE} should not exist in 
  67                 repository after being deleted, but does"
  68 
  69                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  70         }
  71 
  72         rm -f $OUTFILE $ERRFILE $CMDFILE
  73 
  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 assertion=svccfg_delpg_005
  93 
  94 
  95 # Before starting make sure that the test service doesn't already exist.
  96 # If it does then consider it a fatal error.
  97 service_exists $TEST_SERVICE
  98 [[ $? -eq 0 ]] && {
  99         echo "--DIAG: [${assertion}]
 100         service $TEST_SERVICE should not exist in repository but does"
 101 
 102         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 103         exit $RESULT
 104 }
 105 
 106 
 107 #
 108 # Add the service.  If this fails consider it a fatal error
 109 #
 110 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 111 ret=$?
 112 [[ $ret -ne 0 ]] && {
 113         echo "--DIAG: [${assertion}]
 114         error adding service $TEST_SERVICE needed for test
 115         error output is $(cat $ERRFILE)"
 116 
 117         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 118         exit $RESULT
 119 }
 120 
 121 # Make sure the service is there
 122 service_exists $TEST_SERVICE
 123 [[ $? -ne 0 ]] && {
 124         echo "--DIAG: [${assertion}]
 125         service $TEST_SERVICE should exist in
 126         repository after being added, but does not"
 127 
 128         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 129         exit $RESULT
 130 }
 131 
 132 
 133 #
 134 # Test #1: call delpg with no arguments
 135 #
 136 echo "--INFO: Starting $assertion, test 1 (no args)"
 137 
 138 typeset -i TEST_RESULT=$STF_PASS
 139 
 140 #
 141 # Add a property group to the service
 142 #
 143 cat <<EOF>$CMDFILE
 144 select ${TEST_SERVICE}
 145 delpg 
 146 EOF
 147 
 148 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 149 ret=$?
 150 
 151 # Verify that the return value is as expected - non-fatal error
 152 [[ $ret -ne 1 ]] &&  {
 153         echo "--DIAG: [${assertion}, test 1]
 154         svccfg delpg expected to return 1, got $ret"
 155 
 156         TEST_RESULT=$STF_FAIL
 157 }
 158 
 159 # Verify that nothing in stdout - non-fatal error
 160 [[ -s $OUTFILE ]] &&  {
 161         echo "--DIAG: [${assertion}, test 1]
 162         stdout not expected, but got $(cat $OUTFILE)"
 163 
 164         TEST_RESULT=$STF_FAIL
 165 }
 166 
 167 
 168 # Verify that message in stderr - non-fatal error
 169 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
 170 then
 171         echo "--DIAG: [${assertion}, test 1]
 172         Expected error message \"$SYNTAX_ERRMSG\"
 173         but got \"$(cat $ERRFILE)\""
 174 
 175         TEST_RESULT=$STF_FAIL
 176 fi
 177 
 178 rm -f $ERRFILE $OUTFILE $CMDFILE
 179 print_result $TEST_RESULT
 180 RESULT=$(update_result $TEST_RESULT $RESULT)
 181 
 182 
 183 #
 184 # Test #2: call delpg with two arguments
 185 #
 186 echo "--INFO: Starting $assertion, test 2 (2 arguments)"
 187 
 188 typeset -i TEST_RESULT=$STF_PASS
 189 
 190 #
 191 # Add a property group to the service
 192 #
 193 cat <<EOF>$CMDFILE
 194 select ${TEST_SERVICE}
 195 delpg ${TEST_PROPERTY} extra_option
 196 EOF
 197 
 198 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 199 ret=$?
 200 
 201 # Verify that the return value is as expected - non-fatal error
 202 [[ $ret -eq 0 ]] &&  {
 203         echo "--DIAG: [${assertion}, test 2]
 204         svccfg delpg expected to return 1, got $ret"
 205 
 206         TEST_RESULT=$STF_FAIL
 207 }
 208 
 209 # Verify that nothing in stdout - non-fatal error
 210 [[ -s $OUTFILE ]] &&  {
 211         echo "--DIAG: [${assertion}, test 2]
 212         stdout not expected, but got $(cat $OUTFILE)"
 213 
 214         TEST_RESULT=$STF_FAIL
 215 }
 216 
 217 # Verify that message in stderr - non-fatal error
 218 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
 219 then
 220         echo "--DIAG: [${assertion}, test 2]
 221         Expected error message \"$SYNTAX_ERRMSG\"
 222         but got \"$(cat $ERRFILE)\""
 223 
 224         TEST_RESULT=$STF_FAIL
 225 fi
 226 
 227 
 228 print_result $TEST_RESULT
 229 RESULT=$(update_result $TEST_RESULT $RESULT)
 230 
 231 exit $RESULT