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_009
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'import' subcommand with a valid service manifest 
  35 #       that was previously applied (with the same services and
  36 #       instances) will result in changes to any of the existing
  37 #       repository information, if the override property is set.
  38 #
  39 #
  40 # STRATEGY:
  41 #       This test loads in the a simple .xml file - the same as the basic
  42 #       .xml file in import_001 with one additional property used for 
  43 #       testing this assertion.  The property is a simple astring
  44 #       called "testinfo".  This .xml is imported into the repository.
  45 #       After this the xml file is modified such that the value of
  46 #       the property "testinfo" is changed.  Then the .xml file is
  47 #       imported again.  The assertion is verified by checking that
  48 #       the "testinfo" property had *not* been updated.
  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 $ERRFILE $OUTFILE $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_009
 106 
 107 # extract and print assertion information from this source script.
 108 extract_assertion_info $ME
 109 
 110 # Before starting make sure that the test service doesn't already exist.
 111 # If it does then consider it a fatal error.
 112 
 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 # # Start assertion testing
 124 #
 125 
 126 readonly registration_template=$MYLOC/import_009.xml
 127 readonly registration_file=$MYLOC/foo.xml
 128 readonly LOGFILE=/tmp/log.$$
 129 readonly STATEFILE=/tmp/state.$$
 130 
 131 manifest_generate $registration_template \
 132         TEST_SERVICE=$TEST_SERVICE \
 133         TEST_INSTANCE=$TEST_INSTANCE \
 134         SERVICE_APP=$SERVICE_APP  \
 135         LOGFILE=$LOGFILE \
 136         STATEFILE=$STATEFILE | sed 's/TESTDATA/first/' | sed 's/OVERRIDE_VALUE/true/' >$registration_file
 137 
 138 
 139 manifest_purgemd5 $registration_file
 140 
 141 svccfg  import $registration_file > $OUTFILE 2>$ERRFILE
 142 ret=$?
 143 
 144 [[ $ret -ne 0 ]] &&  {
 145         echo "--DIAG: [${assertion}]
 146         svccfg import expected to return 0, got $ret"
 147 
 148         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 149         exit $RESULT
 150 }
 151 
 152 service_exists $TEST_SERVICE
 153 [[ $? -ne 0 ]] && {
 154         echo "--DIAG: [${assertion}]
 155         service $TEST_SERVICE should exist in repository but does not"
 156 
 157         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 158         exit $RESULT
 159 }
 160 
 161 
 162 prop_value_1=$(svcprop -p cfg/testinfo $TEST_SERVICE:$TEST_INSTANCE)
 163 [[ "${prop_value_1}" != "first" ]] && {
 164         echo "--DIAG: [${assertion}]
 165         cfg/testinfo property value is ${prop_value_1}, expected first"
 166 
 167         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 168         exit $RESULT
 169 }
 170 
 171 
 172 # create a manifest with all the same data EXCEPT the value of one
 173 # property should be different
 174 manifest_generate $registration_template \
 175         TEST_SERVICE=$TEST_SERVICE \
 176         TEST_INSTANCE=$TEST_INSTANCE \
 177         SERVICE_APP=$SERVICE_APP  \
 178         LOGFILE=$LOGFILE \
 179         STATEFILE=$STATEFILE | sed 's/TESTDATA/second/' | sed 's/OVERRIDE_VALUE/true/' >$registration_file
 180 
 181 # Try to import the file again 
 182 svccfg  import $registration_file > $OUTFILE 2>$ERRFILE
 183 ret=$?
 184 [[ $ret -ne 0 ]] &&  {
 185         echo "--DIAG: [${assertion}]
 186         svccfg import expected to return 0, got $ret"
 187 
 188         RESULT=$STF_FAIL
 189 }
 190 
 191 # Verify that nothing in stdout - this is a non-fatal error
 192 [[ -s $OUTFILE ]] &&  {
 193         echo "--DIAG: [${assertion}]
 194         stdout not expected, but got $(cat $OUTFILE)"
 195 
 196         RESULT=$STF_FAIL
 197 }
 198 
 199 # Verify that nothing in sterr - this is a non-fatal error
 200 [[ -s $ERRFILE ]] &&  {
 201         echo "--DIAG: [${assertion}]
 202         stderr not expected, but got $(cat $ERRFILE)"
 203 
 204         RESULT=$STF_FAIL
 205 }
 206 
 207 
 208 
 209 prop_value_2=$(svcprop -p cfg/testinfo $TEST_SERVICE:$TEST_INSTANCE)
 210 [[ "${prop_value_2}" != "second" ]] && {
 211         echo "--DIAG: [${assertion}]
 212         cfg/testinfo updated property value is ${prop_value_2}, expected second"
 213 
 214         RESULT=$STF_FAIL
 215 }
 216 
 217 rm -f $ERRFILE $OUTFILE /tmp/export.$$.?
 218 exit $RESULT