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_008
  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 *no* changes to any of the existing
  37 #       repository information, if the override property is not 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 /tmp/export.$$.? $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_008
 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_008.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/' >$registration_file
 137 
 138 
 139 manifest_purgemd5 $registration_file
 140 
 141 cp $registration_file /tmp/1.xml
 142 
 143 svccfg  import $registration_file > $OUTFILE 2>$ERRFILE
 144 ret=$?
 145 [[ $ret -ne 0 ]] &&  {
 146         echo "--DIAG: [${assertion}]
 147         svccfg import expected to return 0, got $ret"
 148 
 149         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 150         exit $RESULT
 151 }
 152 
 153 
 154 service_wait_state $TEST_SERVICE:$TEST_INSTANCE disabled
 155 ret=$?
 156 [[ $ret -ne 0 ]] && {
 157         echo "--DIAG: [${assertion}]
 158         service $TEST_SERVICE:$TEST_INSTANCE not diabled as expected"
 159 
 160         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 161         exit $RESULT
 162 }
 163 
 164 
 165 svccfg export $TEST_SERVICE > /tmp/export.$$.1
 166 
 167 # create a manifest with all the same data EXCEPT the value of one
 168 # property should be different
 169 manifest_generate $registration_template \
 170         TEST_SERVICE=$TEST_SERVICE \
 171         TEST_INSTANCE=$TEST_INSTANCE \
 172         SERVICE_APP=$SERVICE_APP  \
 173         LOGFILE=$LOGFILE \
 174         STATEFILE=$STATEFILE | sed 's/TESTDATA/second/' >$registration_file
 175 
 176 # Try to import the file again 
 177 svccfg  import $registration_file > $OUTFILE 2>$ERRFILE
 178 ret=$?
 179 [[ $ret -ne 0 ]] &&  {
 180         echo "--DIAG: [${assertion}]
 181         svccfg mport expected to return 0, got $ret"
 182 
 183         RESULT=$STF_FAIL
 184 }
 185 
 186 # Verify that nothing in stdout - this is a non-fatal error
 187 [[ -s $OUTFILE ]] &&  {
 188         echo "--DIAG: [${assertion}]
 189         stdout not expected, but got $(cat $OUTFILE)"
 190 
 191         RESULT=$STF_FAIL
 192 }
 193 
 194 # Verify that nothing in sterr - this is a non-fatal error
 195 [[ -s $ERRFILE ]] &&  {
 196         echo "--DIAG: [${assertion}]
 197         stderr not expected, but got $(cat $ERRFILE)"
 198 
 199         RESULT=$STF_FAIL
 200 }
 201 
 202 
 203 
 204 svccfg export $TEST_SERVICE > /tmp/export.$$.2
 205 
 206 cmp -s /tmp/export.$$.1 /tmp/export.$$.2
 207 ret=$?
 208 [[ $ret -ne 0 ]] && {
 209         echo "--DIAG: [${assertion}]
 210         repository unexpectedly changed after 2nd import.
 211         The output after the first import is:
 212         $(cat /tmp/export.$$.1)
 213         The output after the second import is:
 214         $(cat /tmp/export.$$.2)"
 215 
 216         RESULT=$STF_FAIL
 217 }
 218 
 219 rm -f $ERRFILE $OUTFILE /tmp/export.$$.?
 220 exit $RESULT