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_inventory_001
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'inventory file' subcommand, where file is a
  35 #       service bundle, then the FMRIs of the services and instances
  36 #       it describes are printed to stdout.  For each service, the
  37 #       FMRIs of its insances are displayed before the FMRI of the
  38 #       service.
  39 #
  40 # STRATEGY:
  41 #       Inventory a .xml file that has multiple services and instances.
  42 #       The output is compared against an expected output file.  This
  43 #       is a good verification strategy because the output of the
  44 #       command should be stable.
  45 #       
  46 #
  47 # end __stf_assertion__
  48 ###############################################################################
  49 
  50 
  51 # First STF library
  52 . ${STF_TOOLS}/include/stf.kshlib
  53 
  54 # Load GL library
  55 . ${STF_SUITE}/include/gltest.kshlib
  56 
  57 readonly ME=$(whence -p ${0})
  58 readonly MYLOC=$(dirname ${ME})
  59 
  60 # Initialize test result 
  61 typeset -i RESULT=$STF_PASS
  62 
  63 
  64 function cleanup {
  65         
  66         rm -f $OUTFILE $ERRFILE 
  67 
  68         exit $RESULT
  69 }
  70 
  71 trap cleanup 0 1 2 15
  72 
  73 # make sure that the environment is sane - svc.configd  is up and running
  74 check_gl_env
  75 [[ $? -ne 0 ]] && {
  76         echo "--DIAG: 
  77                 Invalid test environment - svc.configd  not available"
  78 
  79         RESULT=$STF_UNRESOLVED
  80         exit $RESULT
  81 }
  82 
  83 assertion=svccfg_inventory_001
  84 
  85 # extract and print assertion information from this source script.
  86 extract_assertion_info $ME
  87 
  88 # Before starting make sure that the test service doesn't already exist.
  89 # If it does then consider it a fatal error.
  90 
  91 typeset service_prefix=svccfg_inventory
  92 
  93 
  94 svccfg list ${service_prefix}* > $OUTFILE 2>$ERRFILE
  95 [[ -s ${OUTFILE}  ]] && {
  96         echo "--DIAG: [${assertion}]
  97         services with prefix "$service_prefix" should not exist in
  98         repository but does.  They are:
  99         $(cat $OUTFILE))"
 100 
 101         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 102         exit $RESULT
 103 }
 104 
 105 #  
 106 #Start assertion testing
 107 #
 108 
 109 readonly registration_file=$MYLOC/inventory_001.xml
 110 
 111 svccfg  inventory $registration_file > $OUTFILE 2>$ERRFILE
 112 ret=$?
 113 
 114 [[ $ret -ne 0 ]] &&  {
 115         echo "--DIAG: [${assertion}]
 116         svccfg inventory expected to return 0, got $ret"
 117 
 118         RESULT=$STF_FAIL
 119 }
 120 
 121 [[ ! -f ${MYLOC}/inventory_001.out ]] &&  {
 122         echo "--DIAG: [${assertion}]
 123         file ${MYLOC}/inventory_001.out not available - needed for the test"
 124 
 125         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 126         exit $RESULT
 127 }
 128 
 129 
 130 # Verify that nothing in stdout - this is a non-fatal error
 131 cmp -s $OUTFILE ${MYLOC}/inventory_001.out 
 132 ret=$?
 133 [[ $ret -ne 0 ]] &&  {
 134         echo "--DIAG: [${assertion}]
 135         expected output of svccfg inventory command is:
 136         $(cat ${MYLOC}/inventory_001.out)
 137         the actual output is:
 138         $(cat ${OUTFILE})"
 139 
 140         RESULT=$STF_FAIL
 141 }
 142 
 143 # Verify that nothing in stderr - this is a non-fatal error
 144 [[ -s $ERRFILE ]] &&  {
 145         echo "--DIAG: [${assertion}]
 146         stderr not expected, but got $(cat $ERRFILE)"
 147 
 148         RESULT=$STF_FAIL
 149 }
 150 
 151 # Make sure that the service doesn't exist in the repository - not likely 
 152 # to happen but it's an easy check.
 153 #
 154 svccfg list ${service_prefix}* > $OUTFILE 2>$ERRFILE
 155 [[ -s ${OUTFILE}  ]] && {
 156         echo "--DIAG: [${assertion}]
 157         services with prefix "$service_prefix" should not exist in
 158         repository but does"
 159 
 160         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 161         exit $RESULT
 162 }
 163 
 164 
 165 exit $RESULT