1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 
  27 # First STF library
  28 . ${STF_TOOLS}/include/stf.kshlib
  29 
  30 # Load GL library
  31 . ${STF_SUITE}/include/gltest.kshlib
  32 
  33 # Load svc.startd library for manifest_generate
  34 . ${STF_SUITE}/include/svc.startd_config.kshlib
  35 
  36 readonly ME=$(whence -p ${0})
  37 readonly MYLOC=$(dirname ${ME})
  38 
  39 cleanup() {
  40         manifest_purgemd5 $registration_file
  41 
  42         service_cleanup ${test_service}
  43 
  44         rm -f $OUTFILE $ERRFILE $LOGFILE $STATEFILE $registration_file
  45 
  46         exit $RESULT
  47 }
  48 
  49 #
  50 # Function:     verify_multi
  51 # 
  52 # Synopsis:     verify_multi service prop value...
  53 #
  54 #
  55 # Description:
  56 #       Verify the values in multi value properties.  One condition of
  57 #       this function is that none of the values can contain white space.
  58 #
  59 verify_multi() {
  60         vm_serv=$1
  61         vm_prop=$2
  62         shift 2
  63         vm_prop_count=$#
  64         vm_desired="$*"
  65 
  66         # Get properties from the repository
  67         #
  68         $SVCPROP -p $vm_prop $vm_serv > /dev/null
  69         if [ $? -ne 0 ] ; then
  70                 echo "--DIAG : Can't get properties for $vm_prop"
  71                 RESULT=$STF_FAIL
  72                 return
  73         fi
  74         vm_actual=`$SVCPROP -p $vm_prop $vm_serv | sed -e 's/\\\//g'`
  75         vm_actual_count=`echo $vm_actual | wc -w`
  76 
  77         # Did we get the correct number?
  78         #
  79         if [ "$vm_prop_count" -ne "$vm_actual_count" ] ; then
  80                 echo "--DIAG : $vm_prop has wrong number of properties."
  81                 echo "         Expected: $vm_desired"
  82                 echo "         Actual: $vm_actual"
  83                 RESULT=$STF_FAIL
  84                 return
  85         fi
  86 
  87         # Verify the values
  88         #
  89         for vm_d in $vm_desired ; do
  90                 vm_found=0
  91                 for vm_a in $vm_actual ; do
  92                         if [ "$vm_d" = "$vm_a" ] ; then
  93                                 vm_found=1
  94                         fi
  95                 done
  96                 if [ $vm_found -eq 0 ] ; then
  97                         echo "--DIAG : $vm_d is missing from $vm_prop"
  98                         RESULT=$STF_FAIL
  99                 fi
 100         done
 101 }
 102 
 103 # Function:     verify_prop
 104 #
 105 # Synopsis:     verify_prop service prop type value...
 106 #
 107 # Description:
 108 #       Scan the svccfg listprop output for the specified service looking
 109 #       for prop.  prop should be of the form pg_name/prop_name.  If the
 110 #       property is found, the type and value are verified.
 111 #
 112 verify_prop() {
 113         ISNOT=""
 114         QUIET=0
 115         if [ "$1" != "POS" -a "$1" != "NEG" ] ; then
 116                 exp_result=0
 117         else
 118                 if [ "$1" == "POS" ] ; then
 119                         exp_result=0
 120                 else
 121                         ISNOT="is not"
 122                         exp_result=1
 123                 fi
 124                 shift
 125         fi
 126 
 127         if [ "$1" == "QUIET" ]
 128         then
 129                 QUIET=1
 130                 shift
 131         fi
 132 
 133         vp_serv=$1
 134         vp_prop=$2
 135         vp_type=$3
 136         shift 3
 137         vp_value="$*"
 138         if [ -z $vp_value ]
 139         then
 140                 vp_value=\"\"
 141         fi
 142 
 143         if [ $QUIET -eq 0 ]
 144         then
 145                 echo "--INFO: Validate the property group pattern $vp_prop"
 146                 echo "  with type $vp_type and values of :"
 147                 for v in $vp_value
 148                 do
 149                         echo "          $v"
 150                 done
 151                 echo "  $ISNOT in service $vp_serv"
 152         fi
 153         $SVCPROP -c $vp_serv | \
 154                 sed -e 's/\\//g' | \
 155                 /usr/xpg4/bin/awk '
 156                         BEGIN   {
 157                                         Ec=1
 158                                         PropSeen = 0
 159                         }
 160                         $1 == prop {
 161                                 PropSeen = 1
 162                                 if ($2 != type) {
 163                                         printf "wrong type\n"
 164                                         exit 1
 165                                 }
 166                                 # Check ws separated value
 167                                 # elements
 168                                 #
 169                                 value_count = split(value, v, " ")
 170                                 for (i = 1; i <= NF - 2; i++) {
 171                                         if (i > value_count) {
 172                                                 printf "value_count = %d i = %d \n", value_count, i
 173                                                 exit 1
 174                                         }
 175                                         fn = i + 2
 176                                         if ($fn != v[i]) {
 177                                                 printf "val[%d]\n", i
 178                                                 exit 1
 179                                         }
 180                                 }
 181                                 if (i < NF - 2) {
 182                                         printf "NF\n"
 183                                         exit 1
 184                                 } else {
 185                                         Ec=0
 186                                         exit Ec
 187                                 }
 188                         }
 189                         END     {
 190                                 if (PropSeen == 0) {
 191                                         printf "no property\n"
 192                                 }
 193                                 exit Ec
 194                         }
 195                 ' prop=$vp_prop type=$vp_type value="${vp_value}"
 196         ret=$?
 197         if [ $exp_result -eq 0 -a $ret -ne 0 ] ; then
 198                 echo "--DIAG : Prop. verification failure for \"${vp_prop}\"" \
 199                         "\"${vp_type}\""
 200                 RESULT=$STF_FAIL
 201         else 
 202                 if [ $exp_result -eq 1 -a $ret -eq 0 ] ; then
 203                         echo "--DIAG : Prop. verification failure for \"${vp_prop}\"" \
 204                                 "\"${vp_type}\", expected not to be present"
 205                         RESULT=$STF_FAIL
 206                 fi
 207         fi
 208 }
 209 
 210 # Function:     validate_fail
 211 #
 212 # Synopsis:     validate_fail manifest fail_msg
 213 #
 214 # Description:
 215 #       This function validates a manifest, and expects the validation to
 216 #       fail.  The error output of the validate command is checked to be
 217 #       sure that it contains fail_msg
 218 #
 219 validate_fail()
 220 {
 221         vf_man="$1"
 222         vf_msg="$2"
 223 
 224         # Make sure the manifest exists.
 225 
 226         if [ ! -f $vf_man ] ; then
 227                 echo "\"${vf_man}\" is missing"
 228                 RESULT=$STF_UNRESOLVED
 229                 return
 230         fi
 231 
 232         # Attempt to validate the manifest
 233 
 234         $SVCCFG validate $vf_man >$OUTFILE 2>$ERRFILE
 235         if [ $? -eq 0 ] ; then
 236                 echo "-- DIAG: [${assertion}]
 237                 $SVCCFG validate expected to fail, but did not."
 238 
 239                 RESULT=$STF_FAIL
 240                 return
 241         fi
 242 
 243         if [ ! -s $ERRFILE ] ; then
 244                 echo "-- DIAG: [${assertion}]
 245                 $SVCCFG validate did not send output to stderr"
 246 
 247                 RESULT=$STF_FAIL
 248                 return
 249         fi
 250 
 251         # Make sure the we failed for the correct reason
 252 
 253         grep "$vf_msg" $ERRFILE > /dev/null 2>&1
 254         if [ $? -ne 0 ] ; then
 255                 echo "Validate failed for wrong reason"
 256                 echo "Error output follows"
 257 
 258                 RESULT=$STF_FAIL
 259                 cat $ERRFILE
 260         fi
 261 }
 262 
 263 # Function:     verify_import
 264 #
 265 # Sysnopsis:    verify_import pos/neg manifest outlog errlog
 266 #
 267 # Description:
 268 #       Will do the import and determine if a failure occurred if it does then
 269 #       dump out the error and log the result
 270 #
 271 verify_import()
 272 {
 273         #
 274         # By default the import is considered possitive, so if no
 275         # positve or negative value is provided then pass_fail is pos
 276         #
 277         if [ `echo $1 | tr '[:lower:]' '[:upper:]'` == "NEG" ]; then
 278                 echo "--INFO: Verify the import fails"
 279                 pass_fail=-1
 280                 shift
 281         else
 282                 echo "--INFO: Verify the import succeeds"
 283                 pass_fail=0
 284                 if [ `echo $1 | tr '[:lower:]' '[:upper:]'` == "POS" ]; then
 285                         shift
 286                 fi
 287         fi
 288 
 289         impmanifest=$1
 290         servicename=$2
 291         outlog=${3:-$OUTFILE}
 292         errlog=${4:-$ERRFILE}
 293 
 294         $SVCCFG -v import -V $impmanifest > $outlog 2> $errlog
 295         ret=$?
 296 
 297         grep "Successful import" $errlog > /dev/null 2>&1
 298         successimport=$?
 299 
 300         #
 301         # Clear out the success messages
 302         #
 303         errcnt=`grep -v 'Taking \"initial\" snapshot' $errlog |
 304                 grep -v 'Taking \"last-import\" snapshot' |
 305                 grep -v Refreshed | grep -v 'Successful import' |
 306                 grep -v "^Warning:" | wc -l`
 307 
 308         if [ $ret -eq $pass_fail ]; then
 309                 if [ $successimport -ne 0 -o $errcnt -ne 0 ]; then
 310                         echo "-- DIAG: " \
 311                             "expect import to succeed but returned $ret"
 312 
 313                         echo "$outlog :"
 314                         cat $outlog
 315                         echo "$errlog :"
 316                         cat $errlog
 317 
 318                         RESULT=$STF_FAIL
 319                         return 1
 320                 fi
 321         else
 322                 if [ $pass_fail -eq -1 ]; then
 323                         $SVCS -a | grep $servicename > /dev/null 2>&1
 324                         svc_exists=$?
 325                         if [ $successimport -eq 0 -o $errcnt -eq 0 -o \
 326                             $svc_exists -eq 0 ]; then
 327                                 echo "-- DIAG: "\
 328                                     "expected failure but import did not fail"
 329 
 330                                 echo "$outlog :"
 331                                 cat $outlog
 332                                 echo "$errlog :"
 333                                 cat $errlog
 334 
 335                                 RESULT=$STF_FAIL
 336                                 return 1
 337                         fi
 338                 else
 339                         echo "-- DIAG: "\
 340                             "expected failure but import did not fail"
 341 
 342                         echo "$outlog :"
 343                         cat $outlog
 344                         echo "$errlog :"
 345                         cat $errlog
 346 
 347                         RESULT=$STF_FAIL
 348                         return 1
 349                 fi
 350         fi
 351 
 352         echo "$outlog :"
 353         cat $outlog
 354         echo "$errlog :"
 355         cat $errlog
 356 
 357         return 0
 358 }