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_001
  32 #
  33 # DESCRIPTION:
  34 #       Calling the "import file" subcommand where the file contains a
  35 #       valid service manifest will result in the service and instances
  36 #       specified within the file being enabled, if the services are
  37 #       specified to be enabled.  If no errors have occurred during
  38 #       processing, there is nothing seen on stderr and the
  39 #       command exit status is 0.
  40 #
  41 # STRATEGY:
  42 #       This is a simple test - import a manifest file with a enabled
  43 #       service.  The service used is the standard test service.
  44 #       To verify make sure that the service is in the repository
  45 #       and the test service is running.
  46 #
  47 #       Note: the DTD tests do testing of the import command.  This
  48 #         test is a simple positive test.  For addition import
  49 #         testing run the DTD tests.
  50 #       
  51 #
  52 # end __stf_assertion__
  53 ###############################################################################
  54 
  55 
  56 # First STF library
  57 . ${STF_TOOLS}/include/stf.kshlib
  58 
  59 # Load GL library
  60 . ${STF_SUITE}/include/gltest.kshlib
  61 
  62 # Load svc.startd library for manifest_generate
  63 . ${STF_SUITE}/include/svc.startd_config.kshlib
  64 
  65 readonly ME=$(whence -p ${0})
  66 readonly MYLOC=$(dirname ${ME})
  67 
  68 # Initialize test result 
  69 typeset -i RESULT=$STF_PASS
  70 
  71 
  72 function cleanup {
  73         
  74         # Note that $TEST_SERVICE may or may not exist so don't check
  75         # results.  Just make sure the service is gone.
  76 
  77         manifest_purgemd5 $registration_file
  78 
  79         service_cleanup ${TEST_SERVICE}
  80 
  81         service_exists ${TEST_SERVICE}
  82         [[ $? -eq 0 ]] && {
  83                 echo "--DIAG: [${assertion}, cleanup]
  84                 service ${TEST_SERVICE} should not exist in 
  85                 repository after being deleted, but does"
  86 
  87                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  88         }
  89 
  90         rm -f $OUTFILE $ERRFILE $LOGFILE $STATEFILE $registration_file
  91 
  92         exit $RESULT
  93 }
  94 
  95 trap cleanup 0 1 2 15
  96 
  97 # make sure that the environment is sane - svc.configd  is up and running
  98 check_gl_env
  99 [[ $? -ne 0 ]] && {
 100         echo "--DIAG: 
 101                 Invalid test environment - svc.configd  not available"
 102 
 103         RESULT=$STF_UNRESOLVED
 104         exit $RESULT
 105 }
 106 
 107 assertion=svccfg_import_001
 108 
 109 # extract and print assertion information from this source script.
 110 extract_assertion_info $ME
 111 
 112 # Before starting make sure that the test service doesn't already exist.
 113 # If it does then consider it a fatal error.
 114 
 115 service_exists $TEST_SERVICE
 116 [[ $? -eq 0 ]] && {
 117         echo "--DIAG: [${assertion}]
 118         service $TEST_SERVICE should not exist in
 119         repository but does"
 120 
 121         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 122         exit $RESULT
 123 }
 124 
 125 # Make sure that no instances of the test service are running.  This
 126 # is to ensure that the subsequent pgrep used to verify the assertion
 127 # does not falsely fail.
 128 #
 129 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 130 ret=$?
 131 [[ $ret -eq 0 ]] && {
 132         echo "--DIAG: [${assertion}]
 133         an instance of $(basename $SERVICE_APP) is running but should not be
 134         to ensure correct validation of this test"
 135 
 136         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 137         exit $RESULT
 138 }
 139 
 140 
 141 # # Start assertion testing
 142 #
 143 
 144 readonly registration_template=$MYLOC/import_001.xml
 145 readonly registration_file=/tmp/import_001.xml
 146 
 147 readonly LOGFILE=/tmp/log.$$
 148 readonly STATEFILE=/tmp/state.$$
 149 
 150 manifest_generate $registration_template \
 151         TEST_SERVICE=$TEST_SERVICE \
 152         TEST_INSTANCE=$TEST_INSTANCE \
 153         SERVICE_APP=$SERVICE_APP  \
 154         LOGFILE=$LOGFILE \
 155         STATEFILE=$STATEFILE >$registration_file
 156 
 157 
 158 manifest_purgemd5 $registration_file
 159 
 160 
 161 svccfg  import $registration_file > $OUTFILE 2>$ERRFILE
 162 ret=$?
 163 
 164 [[ $ret -ne 0 ]] &&  {
 165         echo "--DIAG: [${assertion}]
 166         svccfg import expected to return 0, got $ret"
 167 
 168         RESULT=$STF_FAIL
 169 }
 170 
 171 # Verify that nothing in stdout - this is a non-fatal error
 172 [[ -s $OUTFILE ]] &&  {
 173         echo "--DIAG: [${assertion}]
 174         stdout not expected, but got $(cat $OUTFILE)"
 175 
 176         RESULT=$STF_FAIL
 177 }
 178 
 179 # Verify that nothing in stderr - this is a non-fatal error
 180 [[ -s $ERRFILE ]] &&  {
 181         echo "--DIAG: [${assertion}]
 182         stderr not expected, but got $(cat $ERRFILE)"
 183 
 184         RESULT=$STF_FAIL
 185 }
 186 
 187 service_wait_state $TEST_SERVICE:$TEST_INSTANCE online 60
 188 [[ $? -ne 0 ]] && {
 189         echo "--DIAG: [${assertion}]
 190         service $TEST_SERVICE should exist in repository but does not"
 191 
 192         RESULT=$STF_FAIL
 193 }
 194 
 195 
 196 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 197 ret=$?
 198 [[ $ret -ne 0 ]] && {
 199         echo "--DIAG: [${assertion}]
 200         app $(basename $SERVICE_APP) is not running but should be"
 201 
 202         RESULT=$STF_FAIL
 203 }
 204 
 205 exit $RESULT