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_unselect_002
  32 #
  33 # DESCRIPTION:
  34 #       The subcommand "unselect" causes the 'parent' of the 
  35 #       current selection to become the currently selected 
  36 #       entity.  If the current selection has no parent, then 
  37 #       a diagnostic message is displayed on stderr.  The exit 
  38 #       status will be 1.
  39 #
  40 # end __stf_assertion__
  41 ###############################################################################
  42 
  43 
  44 # First STF library
  45 . ${STF_TOOLS}/include/stf.kshlib
  46 
  47 # Load GL library
  48 . ${STF_SUITE}/include/gltest.kshlib
  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 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 
  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=$(update_result $STF_UNRESOLVED $RESULT)
  86         exit $RESULT
  87 }
  88 
  89 # extract and print assertion information from this source script.
  90 extract_assertion_info $ME
  91 
  92 assertion=svccfg_unselect_002
  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 svccfg add ${TEST_SERVICE} > $OUTFILE 2>$ERRFILE
 108 ret=$?
 109 [[ $? -ne 0 ]] && {
 110         echo "--DIAG: [${assertion}]
 111         error setting up service $TEST_SERVICE and 
 112         $instance TEST_INSTANCE; here is error output:
 113         $(cat $ERRFILE)"
 114 
 115         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 116         exit $RESULT
 117 }
 118 
 119 
 120 all unselect from the service level
 121 cat << EOF > $CMDFILE
 122 select ${TEST_SERVICE}
 123 unselect
 124 unselect
 125 EOF
 126 
 127 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 128 ret=$?
 129 
 130 # Verify that the return value is as expected - non-fatal error
 131 [[ $ret -ne 1 ]] &&  {
 132         echo "--DIAG: [${assertion}]
 133         svccfg add expected to return 1, got $ret"
 134 
 135         RESULT=$STF_FAIL
 136 }
 137 
 138 # Verify that nothing in stdout - non-fatal error
 139 [[ -s $OUTFILE ]] &&  {
 140         echo "--DIAG: [${assertion}]
 141         stdout not expected, but got $(cat $OUTFILE)"
 142 
 143         RESULT=$STF_FAIL
 144 }
 145 
 146 
 147 # Verify that message in stderr - non-fatal error
 148 if ! egrep -s "$UNSELECT_SCOPE_ERRMSG" $ERRFILE
 149 then
 150         echo "--DIAG: [${assertion}]
 151         Expected error message \"$UNSELECT_SCOPE_ERRMSG\"
 152         but got \"$(cat $ERRFILE)\""
 153 
 154         RESULT=$STF_FAIL
 155 fi
 156 
 157 rm -f $ERRFILE $OUTFILE $CMDFILE
 158 
 159 print_result $RESULT
 160 
 161 exit $RESULT