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_addpg_001
  32 #
  33 # DESCRIPTION:
  34 #       The 'addpg name type [flags]' subcommand adds a property group
  35 #       of name 'name' and type 'type' to the currently selected entity.
  36 #       If no flags argument is given then no flag is associated with
  37 #       the property group.
  38 #
  39 # STRATEGY:
  40 #       This assertion has two subtests:
  41 #       1) add a property group to a service
  42 #       2) add a property group to an instance
  43 #
  44 #       Both of these subtests is performed from a svccfg command
  45 #       file.
  46 #
  47 # end __stf_assertion__
  48 ###############################################################################
  49 
  50 ###############################################################################
  51 # start __stf_assertion__
  52 #
  53 # ASSERTION: svccfg_delpg_001
  54 #
  55 # DESCRIPTION:
  56 #       The 'delpg name' subcommand deletes the property group of the
  57 #       currently selected entity as named by 'name'.  How does this
  58 #       affect running services?
  59 #
  60 # STRATEGY:
  61 #       This assetion has two subtests:
  62 #       1) delete a property group from a service
  63 #       1) delete a property group from an service
  64 #
  65 # end __stf_assertion__
  66 ###############################################################################
  67 
  68 
  69 # First STF library
  70 . ${STF_TOOLS}/include/stf.kshlib
  71 
  72 # Load GL library
  73 . ${STF_SUITE}/include/gltest.kshlib
  74 
  75 
  76 readonly ME=$(whence -p ${0})
  77 readonly MYLOC=$(dirname ${ME})
  78 
  79 readonly NUM_PROPS=50
  80 
  81 typeset -i index
  82 
  83 
  84 # Initialize test result 
  85 typeset -i RESULT=$STF_PASS
  86 
  87 
  88 function cleanup {
  89         
  90         # Note that $TEST_SERVICE may or may not exist so don't check
  91         # results.  Just make sure the service is gone.
  92         service_delete ${TEST_SERVICE} > /dev/null 2>&1
  93 
  94         service_exists ${TEST_SERVICE}
  95         [[ $? -eq 0 ]] && {
  96                 echo "--DIAG: [${assertion}, cleanup]
  97                 service ${TEST_SERVICE} should not exist in 
  98                 repository after being deleted, but does"
  99 
 100                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 101         }
 102 
 103         rm -f $OUTFILE $ERRFILE $CMDFILE
 104 
 105         exit $RESULT
 106 }
 107 
 108 
 109 function check_pg {
 110 
 111         entity=$1
 112         exist=$2
 113 
 114         typeset -i ret_value=0
 115 
 116         index=0
 117         while [ $index -lt ${NUM_PROPS} ]
 118         do
 119                 svcprop -p ${TEST_PROPERTY}_${index} ${entity} > /dev/null 2>&1
 120                 ret=$?
 121                 if [ "$exist" = "TRUE" ] 
 122                 then
 123                         [[ $ret -ne 0 ]] &&   {
 124                                 echo "--DIAG: [${assertion}]
 125                 property group ${TEST_PROPERTY}_${index} does not exist"
 126                                 ret_value=1
 127                         }
 128                 
 129                 else
 130                         [[ $ret -eq 0 ]] &&   {
 131                                 echo "--DIAG: [${assertion}]
 132                 property group ${TEST_PROPERTY}_${index} should not 
 133                 exist, but does"
 134                                 ret_value=1
 135                         }
 136                         
 137                 fi
 138                 (( index = index + 1 ))
 139         done
 140 
 141         return $ret_value
 142 }
 143 
 144 trap cleanup 0 1 2 15
 145 
 146 # make sure that the environment is sane - svc.configd is up and running
 147 check_gl_env
 148 [[ $? -ne 0 ]] && {
 149         echo "--DIAG: 
 150         Invalid test environment -svc.configd not available"
 151 
 152         RESULT=$STF_UNRESOLVED
 153         exit $RESULT
 154 }
 155 
 156 # extract and print assertion information from this source script.
 157 extract_assertion_info $ME
 158 
 159 assertion=svccfg_addpg_001
 160 
 161 # 
 162 # Test #1: Add a property group to a service
 163 #
 164 
 165 echo "--INFO: Starting $assertion, test 1 (add a pg to a service)"
 166 
 167 typeset -i TEST_RESULT=$STF_PASS
 168 
 169 
 170 # Before starting make sure that the test service doesn't already exist.
 171 # If it does then consider it a fatal error.
 172 service_exists $TEST_SERVICE
 173 [[ $? -eq 0 ]] && {
 174         echo "--DIAG: [${assertion}, test 1]
 175         service $TEST_SERVICE should not exist in repository but does"
 176 
 177         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 178         exit $RESULT
 179 }
 180 
 181 
 182 #
 183 # Add the service.  If this fails consider it a fatal error
 184 #
 185 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 186 ret=$?
 187 [[ $ret -ne 0 ]] && {
 188         echo "--DIAG: [${assertion}]
 189         error adding service $TEST_SERVICE needed for test
 190         error output is $(cat $ERRFILE)"
 191 
 192         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 193         exit $RESULT
 194 }
 195 
 196 # Make sure the service is there
 197 service_exists $TEST_SERVICE
 198 [[ $? -ne 0 ]] && {
 199         echo "--DIAG: [${assertion}, test 1]
 200         service $TEST_SERVICE should exist in
 201         repository after being added, but does not"
 202 
 203         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 204         exit $RESULT
 205 }
 206 
 207 
 208 #
 209 # Add property groups to the service
 210 #
 211 cat <<EOF>$CMDFILE
 212 select ${TEST_SERVICE}
 213 EOF
 214 
 215 index=0
 216 while [ $index -lt ${NUM_PROPS} ]
 217 do
 218         cat <<EOF >> $CMDFILE
 219         addpg ${TEST_PROPERTY}_$index astring
 220 EOF
 221         (( index = index + 1 ))
 222 done
 223 
 224 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 225 ret=$?
 226 
 227 # Verify that the return value is as expected - non-fatal error
 228 [[ $ret -ne 0 ]] &&  {
 229         echo "--DIAG: [${assertion}, test 1]
 230         svccfg expected to return 0, got $ret
 231         error output is $(cat $ERRFILE)"
 232 
 233         TEST_RESULT=$STF_FAIL
 234 }
 235 
 236 # Verify that nothing in stdout - non-fatal error
 237 [[ -s $OUTFILE ]] &&  {
 238         echo "--DIAG: [${assertion}, test 1]
 239         stdout not expected, but got $(cat $OUTFILE)"
 240 
 241         TEST_RESULT=$STF_FAIL
 242 }
 243 
 244 # Verify that nothing in stderr - non-fatal error
 245 [[ -s $ERRFILE ]] &&  {
 246         echo "--DIAG: [${assertion}, test 1]
 247         stderr not expected, but got $(cat $ERRFILE)
 248         error output is $(cat $ERRFILE)"
 249 
 250         TEST_RESULT=$STF_FAIL
 251 }
 252 
 253 #
 254 # Check that the property groups exists - fatal error
 255 #
 256 check_pg ${TEST_SERVICE} TRUE
 257 [[ $? -ne 0 ]] && TEST_RESULT=$STF_FAIL
 258 
 259 rm -f $ERRFILE $OUTFILE $CMDFILE
 260 
 261 print_result $TEST_RESULT
 262 RESULT=$(update_result $TEST_RESULT $RESULT)
 263 
 264 # 
 265 # Test #2: Add a property group to a service instance
 266 #
 267 
 268 echo "--INFO: Starting $assertion, test 2 (add a pg to an instance)"
 269 
 270 typeset -i TEST_RESULT=$STF_PASS
 271 
 272 # 
 273 # Create the instance - if this fails it's a fatal error
 274 #
 275 cat <<EOF >$CMDFILE
 276 select ${TEST_SERVICE}
 277 add ${TEST_INSTANCE}
 278 EOF
 279 
 280 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 281 ret=$?
 282 [[ $ret -ne 0 ]] && {
 283         echo "--DIAG: [${assertion}, test 2]
 284         svccfg expected to return 0, got $ret
 285         error output is $(cat $ERRFILE)"
 286         
 287         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 288         exit $RESULT
 289 }
 290                                        
 291 #
 292 # Add a property group to the service instance
 293 #
 294 
 295 cat <<EOF>$CMDFILE
 296 select ${TEST_SERVICE}
 297 select ${TEST_INSTANCE}
 298 EOF
 299 
 300 index=0
 301 while [ $index -lt ${NUM_PROPS} ]
 302 do
 303         cat <<EOF >> $CMDFILE
 304         addpg ${TEST_PROPERTY}_$index astring
 305 EOF
 306         (( index = index + 1 ))
 307 done
 308 
 309 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 310 ret=$?
 311 
 312 # Verify that the return value is as expected - non-fatal error
 313 [[ $ret -ne 0 ]] &&  {
 314         echo "--DIAG: [${assertion}, test 2]
 315         svccfg expected to return 0, got $ret
 316         error output is $(cat $ERRFILE)"
 317 
 318         TEST_RESULT=$STF_FAIL
 319 }
 320 
 321 # Verify that nothing in stdout - non-fatal error
 322 [[ -s $OUTFILE ]] &&  {
 323         echo "--DIAG: [${assertion}, test 2]
 324         stdout not expected, but got $(cat $OUTFILE)"
 325 
 326         TEST_RESULT=$STF_FAIL
 327 }
 328 
 329 # Verify that nothing in stderr - non-fatal error
 330 [[ -s $ERRFILE ]] &&  {
 331         echo "--DIAG: [${assertion}, test 2]
 332         stderr not expected, but got $(cat $ERRFILE)"
 333 
 334         TEST_RESULT=$STF_FAIL
 335 }
 336 
 337 #
 338 # Check that the property group exists - fatal error
 339 #
 340 check_pg ${TEST_SERVICE}:${TEST_INSTANCE} TRUE
 341 [[ $? -ne 0 ]] && 
 342         TEST_RESULT=$STF_FAIL
 343 
 344 
 345 
 346 rm -f $ERRFILE $OUTFILE $CMDFILE
 347 
 348 print_result $TEST_RESULT
 349 RESULT=$(update_result $TEST_RESULT $RESULT)
 350 
 351 # 
 352 # BEGIN delpg testing
 353 #
 354 
 355 assertion=svccfg_delpg_001
 356 
 357 # 
 358 # Test #1 for delpg 
 359 #
 360 
 361 echo "--INFO: Starting $assertion, test 1 (delete a pg from a service)"
 362 typeset -i TEST_RESULT=$STF_PASS
 363 
 364 cat << EOF > $CMDFILE
 365 select ${TEST_SERVICE}
 366 EOF
 367 
 368 index=0
 369 while [ $index -lt ${NUM_PROPS} ]
 370 do
 371         cat <<EOF >> $CMDFILE
 372         delpg ${TEST_PROPERTY}_$index 
 373 EOF
 374         (( index = index + 1 ))
 375 done
 376 
 377 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 378 ret=$?
 379 
 380 # Verify that the return value is as expected - non-fatal error
 381 [[ $ret -ne 0 ]] &&  {
 382         echo "--DIAG: [${assertion}, test 1]
 383         svccfg expected to return 0, got $ret
 384         error output is $(cat $ERRFILE)"
 385 
 386         TEST_RESULT=$STF_FAIL
 387 }
 388 
 389 # Verify that nothing in stdout - non-fatal error
 390 [[ -s $OUTFILE ]] &&  {
 391         echo "--DIAG: [${assertion}, test 1]
 392         stdout not expected, but got $(cat $OUTFILE)"
 393 
 394         TEST_RESULT=$STF_FAIL
 395 }
 396 
 397 # Verify that nothing in stderr - non-fatal error
 398 [[ -s $ERRFILE ]] &&  {
 399         echo "--DIAG: [${assertion}, test 1]
 400         stderr not expected, but got $(cat $ERRFILE)"
 401 
 402         TEST_RESULT=$STF_FAIL
 403 }
 404 
 405 #
 406 # Check that the property groups do not exist - fatal error
 407 #
 408 check_pg ${TEST_SERVICE} FALSE
 409 [[ $? -ne 0 ]] && TEST_RESULT=$STF_FAIL
 410 
 411 rm -f $ERRFILE $OUTFILE $CMDFILE
 412 
 413 print_result $TEST_RESULT
 414 RESULT=$(update_result $TEST_RESULT $RESULT)
 415 
 416 # 
 417 # Test #2 for delpg 
 418 #
 419 
 420 echo "--INFO: Starting $assertion, test 2 (delete a pg from an instance )"
 421 typeset -i TEST_RESULT=$STF_PASS
 422 
 423 cat << EOF > $CMDFILE
 424 select ${TEST_SERVICE}
 425 select ${TEST_INSTANCE}
 426 EOF
 427 
 428 index=0
 429 while [ $index -lt ${NUM_PROPS} ]
 430 do
 431         cat <<EOF >> $CMDFILE
 432         delpg ${TEST_PROPERTY}_$index 
 433 EOF
 434         (( index = index + 1 ))
 435 done
 436 
 437 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 438 ret=$?
 439 
 440 # Verify that the return value is as expected - non-fatal error
 441 [[ $ret -ne 0 ]] &&  {
 442         echo "--DIAG: [${assertion}, test 2]
 443         svccfg expected to return 0, got $ret
 444         error output is $(cat $ERRFILE)"
 445 
 446         TEST_RESULT=$STF_FAIL
 447 }
 448 
 449 # Verify that nothing in stdout - non-fatal error
 450 [[ -s $OUTFILE ]] &&  {
 451         echo "--DIAG: [${assertion}, test 2]
 452         stdout not expected, but got $(cat $OUTFILE)"
 453 
 454         TEST_RESULT=$STF_FAIL
 455 }
 456 
 457 # Verify that nothing in stderr - non-fatal error
 458 [[ -s $ERRFILE ]] &&  {
 459         echo "--DIAG: [${assertion}, test 2]
 460         stderr not expected, but got $(cat $ERRFILE)"
 461 
 462         TEST_RESULT=$STF_FAIL
 463 }
 464 
 465 #
 466 # Check that the property groups do not exist - fatal error
 467 #
 468 check_pg ${TEST_SERVICE} FALSE
 469 [[ $? -ne 0 ]] && TEST_RESULT=$STF_FAIL
 470 
 471 rm -f $ERRFILE $OUTFILE $CMDFILE
 472 
 473 print_result $TEST_RESULT
 474 RESULT=$(update_result $TEST_RESULT $RESULT)
 475 
 476 exit $RESULT