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_003
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'add name' subcommand with 'name' being an 
  35 #       entity that was previously deleted (with 'delete name') 
  36 #       will add the entity.  If no errors have occurred during 
  37 #       processing, there is nothing seen on stderr and the 
  38 #       command exit status is 0.
  39 #
  40 # end __stf_assertion__
  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 readonly ME=$(whence -p ${0})
  50 readonly MYLOC=$(dirname ${ME})
  51 
  52 # Initialize test result 
  53 typeset -i RESULT=$STF_PASS
  54 
  55 
  56 function cleanup {
  57         
  58         # Note that $TEST_SERVICE may or may not exist so don't check
  59         # results.  Just make sure the service is gone.
  60         service_delete $TEST_SERVICE 
  61 
  62         service_exists ${TEST_SERVICE}
  63         [[ $? -eq 0 ]] && {
  64                 echo "--DIAG: [${assertion}, cleanup]
  65                 service ${TEST_SERVICE} should not exist in 
  66                 repository after being deleted, but does"
  67 
  68                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  69         }
  70 
  71         rm -f $OUTFILE $ERRFILE $CMDFILE
  72 
  73         exit $RESULT
  74 }
  75 
  76 trap cleanup 0 1 2 15
  77 
  78 # make sure that the environment is sane - svc.configd is up and running
  79 check_gl_env
  80 [[ $? -ne 0 ]] && {
  81         echo "--DIAG: 
  82         Invalid test environment - svc.configd is not available"
  83 
  84         RESULT=$STF_UNRESOLVED 
  85         exit $RESULT
  86 }
  87 
  88 # extract and print assertion information from this source script.
  89 extract_assertion_info $ME
  90 
  91 assertion=svccfg_add_003
  92 
  93 
  94 # Before starting make sure that the test service doesn't already exist.
  95 # If it does then consider it a fatal error.
  96 service_exists $TEST_SERVICE
  97 [[ $? -eq 0 ]] && {
  98         echo "--DIAG: [${assertion}, test 1]
  99         service $TEST_SERVICE should not exist in 
 100         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 #
 122 # Delete the service.  If this fails consider it a fatal error
 123 #
 124 svccfg delete $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 125 ret=$?
 126 [[ $ret -ne 0 ]] && {
 127         echo "--DIAG: [${assertion}]
 128         error deleting service $TEST_SERVICE
 129         error output is $(cat $ERRFILE)"
 130 
 131         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 132         exit $RESULT
 133 }
 134 
 135 #
 136 # Start assertion testing
 137 #
 138 
 139 #
 140 # Re-add the service.  
 141 #
 142 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 143 ret=$?
 144 # Verify that the return value is as expected - this is a non-fatal error
 145 [[ $ret -ne 0 ]] &&  {
 146         echo "--DIAG: [${assertion}]
 147         svccfg add expected to return 0, got $ret"
 148 
 149         RESULT=$STF_FAIL
 150 }
 151 
 152 # Verify that nothing in stdout - this is a non-fatal error
 153 [[ -s $OUTFILE ]] &&  {
 154         echo "--DIAG: [${assertion}]
 155         stdout not expected, but got $(cat $OUTFILE)"
 156 
 157         RESULT=$STF_FAIL
 158 }
 159 
 160 # Verify that nothing in stderr - this is a non-fatal error
 161 [[ -s $ERRFILE ]] &&  {
 162         echo "--DIAG: [${assertion}]
 163         stderr not expected, but got $(cat $ERRFILE)"
 164 
 165         RESULT=$STF_FAIL
 166 }
 167 
 168 
 169 service_exists $TEST_SERVICE
 170 [[ $ret -ne 0 ]] && {
 171         echo "--DIAG: [${assertion}]
 172         error re-adding service $TEST_SERVICE" 
 173 
 174         RESULT=$STF_FAIL
 175 }
 176 
 177 exit $RESULT