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