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_007
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'import' subcommand where the file is a 
  35 #       service archive will result in a diagnostic message
  36 #       displayed on stderr.  The exit status will be 1.
  37 #
  38 # end __stf_assertion__
  39 ###############################################################################
  40 
  41 
  42 # First STF library
  43 . ${STF_TOOLS}/include/stf.kshlib
  44 
  45 # Load GL library
  46 . ${STF_SUITE}/include/gltest.kshlib
  47 
  48 # Load svc.startd library
  49 . ${STF_SUITE}/include/svc.startd_config.kshlib
  50 
  51 readonly ME=$(whence -p ${0})
  52 readonly MYLOC=$(dirname ${ME})
  53 
  54 
  55 # Initialize test result
  56 typeset -i RESULT=$STF_PASS
  57 
  58 function cleanup {
  59         # Note that $TEST_SERVICE may not exist.  So don't check
  60         # reslts.  Just make sure the service is gone
  61 
  62         manifest_purgemd5 $manifest_file
  63 
  64         rm -f $OUTFILE $ERRFILE $manifest_file $archive_file
  65 }
  66 
  67 trap cleanup 0 1 2 15
  68 
  69 # make sure that the environment is sane -- svc.configd is up and running
  70 check_gl_env
  71 [[ $? -ne 0 ]] && {
  72         echo "--DIAG: 
  73         Invalid test environment - svc.configd  not available"
  74 
  75         RESULT=$STF_UNRESOLVED
  76         exit $RESULT
  77 }
  78 
  79 assertion=svccfg_import_007
  80 
  81 # Extract and print assertion information from this source script
  82 extract_assertion_info $ME
  83 
  84 # Before starting, make sure that the test service doesn't already exist.
  85 # If it does, then consider it a fatal error.  This also mean the previous
  86 # test did not successfully clean up after itself
  87 #
  88 service_exists $TEST_SERVICE
  89 ret=$?
  90 [[ $ret -eq 0 ]] && {
  91         echo "--DIAG: [${assertion}]
  92         service $TEST_SERVICE should not exist in
  93         repository but does"
  94 
  95         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  96         exit $RESULT
  97 }
  98 
  99 # Make sure that no instances of the test service are running.  This
 100 # is to ensure that the subsequent pgrep used to verify the assertion
 101 # does not falsely fail.
 102 #
 103 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
 104 ret=$?
 105 [[ $ret -eq 0 ]] && {
 106         echo "--DIAG: [${assertion}]
 107         an instance of $(basename $SERVICE_APP) is running but should not be
 108         to ensure correct validation of this test"
 109 
 110         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 111         exit $RESULT
 112 }
 113 
 114 
 115 # # Start assertion testing
 116 #
 117 readonly archive_file=$PWD/svccfg_archive.xml
 118 readonly manifest_file=$archive_file
 119 
 120 manifest_purgemd5 $manifest_file
 121 
 122 # Create an svccfg archive file from the current contents of the repository
 123 #
 124 echo "--INFO: Create an svccfg archive file from current repository contents"
 125 svccfg archive > $archive_file 2>&1
 126 ret=$?
 127 if [[ $ret -ne 0 ]]; then
 128         echo "--DIAG: [${assertion}]
 129         'svccfg archive' failed to generate proper archives
 130         EXPECTED: command exitcode 0
 131         RETURNED: command exitcode $ret"
 132         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 133         exit $RESULT
 134 fi
 135 
 136 # Now verify the assertion
 137 echo "--INFO: Now attempt to import the generated svccfg archive.
 138         Expect failure."
 139 
 140 svccfg import $manifest_file > $OUTFILE 2>$ERRFILE
 141 ret=$?
 142 [[ $ret -ne 1 ]] && {
 143         echo "--DIAG: [$assertion]
 144         'svccfg import' did not fail as expected when supplied an archive file
 145         EXPECTED: command exitcode 1
 146         RETURNED: command exitcode $ret"
 147 
 148         RESULT=$STF_FAIL
 149 }
 150 
 151 # Verify that there's nothing in stdout
 152 [[ -s $OUTFILE ]] && {
 153         echo "--DIAG: $assertion
 154         stdout not expected, but got $(cat $OUTFILE)"
 155 
 156         RESULT=$STF_FAIL
 157 }
 158 
 159 # Verify that stderr is not empty
 160 [[ ! -s $ERRFILE ]] && {
 161         echo "--DIAG: $assertion
 162         Expected error output to stderr, but got nothing"
 163 
 164         RESULT=$STF_FAIL
 165 }
 166 
 167 # Verify that stderr contains the expected error message
 168 if ! egrep -s "$NOT_MANIFEST_ERRMSG" $ERRFILE
 169 then
 170         echo "--DIAG: [${assertion}]
 171         Expected error message \"$NOT_MANIFEST_ERRMSG\"
 172         but got \"$(cat $ERRFILE)\""
 173 
 174         RESULT=$STF_FAIL
 175 fi
 176 
 177 exit $RESULT