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_import_011
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'import' subcommand with a valid service manifest that
  35 #       lists dependencies on other services will create these dependencies,
  36 #       assuming these services are known and valid.
  37 #
  38 # STRATEGY:
  39 #       Simple test which imports an .xml file with dependencies and
  40 #       verifies that they are successfully loaded into the repository.
  41 #
  42 # end __stf_assertion__
  43 ###############################################################################
  44 
  45 
  46 
  47 # First STF library
  48 . ${STF_TOOLS}/include/stf.kshlib
  49 
  50 # Load GL library
  51 . ${STF_SUITE}/include/gltest.kshlib
  52 
  53 # Load svc.startd library for manifest_generate
  54 . ${STF_SUITE}/include/svc.startd_config.kshlib
  55 
  56 readonly ME=$(whence -p ${0})
  57 readonly MYLOC=$(dirname ${ME})
  58 
  59 # Initialize test result 
  60 typeset -i RESULT=$STF_PASS
  61 
  62 
  63 function cleanup {
  64         
  65         # Note that $TEST_SERVICE may or may not exist so don't check
  66         # results.  Just make sure the service is gone.
  67 
  68         manifest_purgemd5 ${registration_file_1}
  69         manifest_purgemd5 ${registration_file_2}
  70 
  71         service_cleanup ${TEST_SERVICE_1}
  72         service_cleanup ${TEST_SERVICE_2}
  73 
  74         service_exists ${TEST_SERVICE_1}
  75         [[ $? -eq 0 ]] && {
  76                 echo "--DIAG: [${assertion}, cleanup]
  77                 service ${TEST_SERVICE_1} should not exist in 
  78                 repository after being deleted, but does"
  79 
  80                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  81         }
  82 
  83         service_exists ${TEST_SERVICE_2}
  84         [[ $? -eq 0 ]] && {
  85                 echo "--DIAG: [${assertion}, cleanup]
  86                 service ${TEST_SERVICE_2} should not exist in 
  87                 repository after being deleted, but does"
  88 
  89                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  90         }
  91 
  92 
  93         rm -f $OUTFILE $ERRFILE ${LOGFILE_1} ${LOGFILE_2} \
  94                 ${STATEFILE_1} ${STATEFILE_2}  ${registration_file_1} \
  95                 ${registration_file_2}
  96 
  97         exit $RESULT
  98 }
  99 
 100 trap cleanup 0 1 2 15
 101 
 102 # make sure that the environment is sane - svc.configd  is up and running
 103 check_gl_env
 104 [[ $? -ne 0 ]] && {
 105         echo "--DIAG: 
 106                 Invalid test environment - svc.configd  not available"
 107 
 108         RESULT=$STF_UNRESOLVED
 109         exit $RESULT
 110 }
 111 
 112 assertion=svccfg_import_011
 113 
 114 # extract and print assertion information from this source script.
 115 extract_assertion_info $ME
 116 
 117 # Before starting make sure that the test services don't already exist.
 118 # If it does then consider it a fatal error.
 119 
 120 service_exists ${TEST_SERVICE_1}
 121 [[ $? -eq 0 ]] && {
 122         echo "--DIAG: [${assertion}]
 123         service ${TEST_SERVICE_1} should not exist in
 124         repository but does"
 125 
 126         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 127         exit $RESULT
 128 }
 129 
 130 service_exists ${TEST_SERVICE_2}
 131 [[ $? -eq 0 ]] && {
 132         echo "--DIAG: [${assertion}]
 133         service ${TEST_SERVICE_2} should not exist in
 134         repository but does"
 135 
 136         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 137         exit $RESULT
 138 }
 139 
 140 
 141 # # Start assertion testing
 142 #
 143 
 144 readonly TEST_SERVICE_1=${TEST_SERVICE}_1
 145 readonly TEST_SERVICE_2=${TEST_SERVICE}_2
 146 readonly TEST_INSTANCE_1=${TEST_INSTANCE}_1
 147 readonly TEST_INSTANCE_2=${TEST_INSTANCE}_2
 148 readonly LOGFILE_1=/tmp/log.$$.1
 149 readonly LOGFILE_2=/tmp/log.$$.2
 150 readonly STATEFILE_1=/tmp/state.$$.1
 151 readonly STATEFILE_2=/tmp/state.$$.2
 152 readonly registration_file_1=$MYLOC/foo_1.xml
 153 readonly registration_file_2=$MYLOC/foo_2.xml
 154 readonly FMRI_1=${TEST_SERVICE_1}:${TEST_INSTANCE_1}
 155 readonly FMRI_2=${TEST_SERVICE_2}:${TEST_INSTANCE_2}
 156 
 157 
 158 # Use the registration file from import_001
 159 registration_template=$MYLOC/import_001.xml
 160 
 161 manifest_generate $registration_template \
 162         TEST_SERVICE=${TEST_SERVICE_1} \
 163         TEST_INSTANCE=${TEST_INSTANCE_1} \
 164         SERVICE_APP=$SERVICE_APP  \
 165         LOGFILE=${LOGFILE_1} \
 166         STATEFILE=${STATEFILE_1} >${registration_file_1}
 167 
 168 
 169 manifest_purgemd5 ${registration_file_1}
 170 
 171 svccfg import ${registration_file_1} > $OUTFILE 2>$ERRFILE
 172 ret=$?
 173 [[ $ret -ne 0 ]] &&  {
 174         echo "--DIAG: [${assertion}]
 175         svccfg import expected to return 0, got $ret"
 176 
 177         RESULT=$STF_FAIL
 178 }
 179 
 180 # Verify that nothing in stdout - this is a non-fatal error
 181 [[ -s $OUTFILE ]] &&  {
 182         echo "--DIAG: [${assertion}]
 183         stdout not expected, but got $(cat $OUTFILE)"
 184 
 185         RESULT=$STF_FAIL
 186 }
 187 
 188 # Verify that nothing in stderr - this is a non-fatal error
 189 [[ -s $ERRFILE ]] &&  {
 190         echo "--DIAG: [${assertion}]
 191         stderr not expected, but got $(cat $ERRFILE)"
 192 
 193         RESULT=$STF_FAIL
 194 }
 195 
 196 service_exists ${TEST_SERVICE_1}
 197 [[ $? -ne 0 ]] && {
 198         echo "--DIAG: [${assertion}]
 199         service ${TEST_SERVICE_1} should exist in repository but does not"
 200 
 201         RESULT=$STF_FAIL
 202 }
 203 
 204 registration_template=$MYLOC/import_011.xml
 205 
 206 manifest_generate $registration_template \
 207         TEST_SERVICE=${TEST_SERVICE_2} \
 208         TEST_INSTANCE=${TEST_INSTANCE_2} \
 209         SERVICE_APP=$SERVICE_APP  \
 210         LOGFILE=${LOGFILE_1} \
 211         STATEFILE=${STATEFILE_2} | sed "s/FMRI/${FMRI_1}/" >${registration_file_2}
 212 
 213 manifest_purgemd5 ${registration_file_2}
 214 
 215 svccfg  import ${registration_file_2} > $OUTFILE 2>$ERRFILE
 216 ret=$?
 217 [[ $ret -ne 0 ]] &&  {
 218         echo "--DIAG: [${assertion}]
 219         svccfg import expected to return 0, got $ret"
 220 
 221         RESULT=$STF_FAIL
 222 }
 223 
 224 
 225 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${FMRI_1} > /dev/null 2>&1
 226 ret=$?
 227 [[ $ret -ne 0 ]] && {
 228         echo "--DIAG: [${assertion}]
 229         dependency on service ${FMRI_1} not in the repository but should be"
 230 
 231         RESULT=$STF_FAIL
 232 }
 233 
 234 rm -f $ERRFILE $OUTFILE 
 235 exit $RESULT