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_add_004
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'add name' subcommand with 'name' being invalid
  35 #       will return with a diagnostic message displayed on stderr.
  36 #       The exit status will be 1.
  37 #
  38 # STRATEGY:
  39 #       This assertion has two sub-tests:
  40 #       1) test with an invalid service name
  41 #       2) test with an invalid instance name
  42 #
  43 # end __stf_assertion__
  44 ###############################################################################
  45 
  46 # First STF library
  47 . ${STF_TOOLS}/include/stf.kshlib
  48 
  49 # Load GL library
  50 . ${STF_SUITE}/include/gltest.kshlib
  51 
  52 
  53 readonly ME=$(whence -p ${0})
  54 readonly MYLOC=$(dirname ${ME})
  55 
  56 # Initialize test result 
  57 typeset -i RESULT=$STF_PASS
  58 
  59 
  60 function cleanup {
  61         
  62         service_delete $TEST_SERVICE 
  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_add_004
  94 
  95 
  96 #
  97 # Test #1: Attempt to add a service with an invalid name.  This should fail.
  98 #
  99 
 100 echo "--INFO: Starting $assertion, test 1 (add invalid service)"
 101 
 102 typeset -i TEST_RESULT=$STF_PASS
 103 
 104 svccfg add $INVALID_NAME > $OUTFILE 2>$ERRFILE
 105 ret=$?
 106 [[ $ret -ne 1 ]] && {
 107         echo "--DIAG: [${assertion}, test 1]
 108         svccfg expected to return 1, got $ret"
 109 
 110         TEST_RESULT=$STF_FAIL
 111 }
 112 
 113 
 114 # Verify that nothing in stdout - non-fatal error
 115 [[ -s $OUTFILE ]] &&  {
 116         echo "--DIAG: [${assertion}, test 1]
 117         stdout not expected, but got $(cat $OUTFILE)"
 118 
 119         TEST_RESULT=$STF_FAIL
 120 }
 121 
 122 
 123 # Verify that a message is sent to stderr - non-fatal error
 124 if ! egrep -s "$INVALID_NAME_ERRMSG" $ERRFILE
 125 then
 126         echo "--DIAG: [${assertion}, test 1]
 127         Expected error message \"$INVALID_NAME_ERRMSG\"
 128         but got \"$(cat $ERRFILE)\""
 129 
 130         TEST_RESULT=$STF_FAIL
 131 fi
 132 
 133 
 134 # Verify that the service was not added
 135 service_exists ${INVALID_NAME}
 136 [[ $? -eq 0 ]] && {
 137         echo "--DIAG: [${assertion}, test 1]
 138         Service ${INVALID_NAME} should not exist but it does"
 139 
 140         TEST_RESULT=$STF_FAIL
 141 }
 142 
 143 rm -f $ERRFILE $OUTFILE
 144 
 145 print_result $TEST_RESULT
 146 RESULT=$(update_result $TEST_RESULT $RESULT)
 147 
 148 #
 149 # Test #2: Attempt to add an instance with an invalid name.  This should fail.
 150 #
 151 
 152 echo "--INFO: Starting $assertion, test 2 (add invalid instance)"
 153 
 154 typeset -i TEST_RESULT=$STF_PASS
 155 
 156 cat <<EOF >$CMDFILE
 157 add ${TEST_SERVICE}
 158 select ${TEST_SERVICE}
 159 add ${INVALID_NAME}
 160 EOF
 161 
 162 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 163 ret=$?
 164 
 165 [[ $ret -ne 1 ]] && {
 166         echo "--DIAG: [${assertion}, test 2]
 167         svccfg expected to return 1, got $ret"
 168 
 169         TEST_RESULT=$STF_FAIL
 170 }
 171 
 172 
 173 # Verify that nothing in stdout - non-fatal error
 174 [[ -s $OUTFILE ]] &&  {
 175         echo "--DIAG: [${assertion}, test 2]
 176         stdout not expected, but got $(cat $OUTFILE)"
 177 
 178         TEST_RESULT==$STF_FAIL
 179 }
 180 
 181 
 182 # Verify that a message is sent to stderr - non-fatal error
 183 if ! egrep -s "$INVALID_NAME_ERRMSG" $ERRFILE
 184 then
 185         echo "--DIAG: [${assertion}, test 2]
 186         Expected error message \"$INVALID_NAME_ERRMSG\"
 187         but got \"$(cat $ERRFILE)\""
 188 
 189         TEST_RESULT=$STF_FAIL
 190 fi
 191 
 192 
 193 # Verify that the instance was not added
 194 service_exists ${TEST_SERVICE}:${INVALID_NAME}
 195 [[ $? -eq 0 ]] && {
 196         echo "--DIAG: [${assertion}, test 2]
 197         Instance ${TEST_SERVICE}:${INVALID_NAME} should not exist but it does"
 198 
 199         TEST_RESULT=$STF_FAIL
 200 }
 201 
 202 rm -f $ERRFILE $OUTFILE
 203 
 204 print_result $TEST_RESULT
 205 RESULT=$(update_result $TEST_RESULT $RESULT)
 206 
 207 
 208 exit $RESULT