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 2009 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_012
  32 #
  33 # DESCRIPTION:
  34 #       Deleting and reimporting services with dependencies to verify
  35 #       everything is working as expected
  36 #
  37 # STRATEGY:
  38 #       Import services with the following dependencies:
  39 #       svccfg_import_012a <-- svccfg_import_012b <-> svccfg_import_012b:default --> svccfg_import_012c
  40 #
  41 #       Delete services in various scenarios and verify expected
  42 #       behavior
  43 #
  44 # end __stf_assertion__
  45 ###############################################################################
  46 
  47 # First STF library
  48 . ${STF_TOOLS}/include/stf.kshlib
  49 
  50 # Load GL library
  51 . ${STF_SUITE}/include/gltest.kshlib
  52 
  53 # Load svc.startd library for manifest_generate
  54 . ${STF_SUITE}/include/svc.startd_config.kshlib
  55 
  56 readonly ME=$(whence -p ${0})
  57 readonly MYLOC=$(dirname ${ME})
  58 
  59 # Initialize test result 
  60 typeset -i RESULT=$STF_PASS
  61 
  62 function cleanup {
  63         
  64         # Note that $TEST_SERVICE_# may or may not exist so don't check
  65         # results.  Just make sure the service is gone.
  66 
  67         manifest_purgemd5 ${registration_file_1}
  68         manifest_purgemd5 ${registration_file_2}
  69         manifest_purgemd5 ${registration_file_3}
  70 
  71         service_cleanup ${TEST_SERVICE_1}
  72         service_cleanup ${TEST_SERVICE_2}
  73         service_cleanup ${TEST_SERVICE_3}
  74 
  75         service_exists ${TEST_SERVICE_1}
  76         [[ $? -eq 0 ]] && {
  77                 echo "--DIAG: [${assertion}, cleanup]
  78                 service ${TEST_SERVICE_1} should not exist in 
  79                 repository after being deleted, but does"
  80 
  81                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  82         }
  83 
  84         service_exists ${TEST_SERVICE_2}
  85         [[ $? -eq 0 ]] && {
  86                 echo "--DIAG: [${assertion}, cleanup]
  87                 service ${TEST_SERVICE_2} should not exist in 
  88                 repository after being deleted, but does"
  89 
  90                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  91         }
  92 
  93         service_exists ${TEST_SERVICE_3}
  94         [[ $? -eq 0 ]] && {
  95                 echo "--DIAG: [${assertion}, cleanup]
  96                 service ${TEST_SERVICE_2} should not exist in 
  97                 repository after being deleted, but does"
  98 
  99                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 100         }
 101 
 102         exit $RESULT
 103 }
 104 
 105 trap cleanup 0 1 2 15
 106 
 107 # make sure that the environment is sane - svc.configd is up and running
 108 check_gl_env
 109 [[ $? -ne 0 ]] && {
 110         echo "--DIAG: 
 111         Invalid test environment - svc.configd not available"
 112 
 113         RESULT=$STF_UNRESOLVED
 114         exit $RESULT
 115 }
 116 
 117 assertion=svccfg_import_012
 118 
 119 # extract and print assertion information from this source script.
 120 extract_assertion_info $ME
 121 
 122 # Start assertion testing
 123 
 124 readonly TEST_SERVICE_1=svccfg_import_012a
 125 readonly TEST_SERVICE_2=svccfg_import_012b
 126 readonly TEST_SERVICE_3=svccfg_import_012c
 127 readonly TEST_INSTANCE_1=default
 128 readonly TEST_INSTANCE_2=default
 129 readonly TEST_INSTANCE_3=default
 130 readonly registration_file_1=$MYLOC/import_012a.xml
 131 readonly registration_file_2=$MYLOC/import_012b.xml
 132 readonly registration_file_3=$MYLOC/import_012c.xml
 133 readonly FMRI_1=${TEST_SERVICE_1}:${TEST_INSTANCE_1}
 134 readonly FMRI_2=${TEST_SERVICE_2}:${TEST_INSTANCE_2}
 135 readonly FMRI_3=${TEST_SERVICE_3}:${TEST_INSTANCE_3}
 136 
 137 # Before starting make sure that the test services don't already exist.
 138 # If it does then consider it a fatal error.
 139 
 140 service_exists ${TEST_SERVICE_1}
 141 [[ $? -eq 0 ]] && {
 142         echo "--DIAG: [${assertion}]
 143         service ${TEST_SERVICE_1} should not exist in
 144         repository but does"
 145 
 146         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 147         exit $RESULT
 148 }
 149 
 150 service_exists ${TEST_SERVICE_2}
 151 [[ $? -eq 0 ]] && {
 152         echo "--DIAG: [${assertion}]
 153         service ${TEST_SERVICE_2} should not exist in
 154         repository but does"
 155 
 156         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 157         exit $RESULT
 158 }
 159 
 160 service_exists ${TEST_SERVICE_3}
 161 [[ $? -eq 0 ]] && {
 162         echo "--DIAG: [${assertion}]
 163         service ${TEST_SERVICE_3} should not exist in
 164         repository but does"
 165 
 166         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 167         exit $RESULT
 168 }
 169 
 170 
 171 #######################################################################
 172 # Import the 3 services and verify dependencies
 173 #######################################################################
 174 
 175 #
 176 # Import each service 
 177 #
 178 service_import ${TEST_SERVICE_1} ${registration_file_1} 
 179 ret=$?
 180 [[ $ret -ne 0 ]] && {
 181         echo "--DIAG: [${assertion}]
 182         import of ${TEST_SERVICE_1} failed"
 183 
 184         RESULT=$STF_FAIL
 185 }
 186 
 187 # Import 2nd service
 188 service_import ${TEST_SERVICE_2} ${registration_file_2} 
 189 ret=$?
 190 [[ $ret -ne 0 ]] && {
 191         echo "--DIAG: [${assertion}]
 192         import of ${TEST_SERVICE_2} failed"
 193 
 194         RESULT=$STF_FAIL
 195 }
 196 
 197 # Import 3rd service
 198 service_import ${TEST_SERVICE_3} ${registration_file_3} 
 199 ret=$?
 200 [[ $ret -ne 0 ]] && {
 201         echo "--DIAG: [${assertion}]
 202         import of ${TEST_SERVICE_3} failed"
 203 
 204         RESULT=$STF_FAIL
 205 }
 206 
 207 #
 208 # Verify dependencies. svccfg_import_012b should list both svccfg_import_012a and svccfg_import_012c
 209 #
 210 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_1} > /dev/null 2>&1
 211 ret=$?
 212 [[ $ret -ne 0 ]] && {
 213         echo "--DIAG: [${assertion}]
 214         dependency on service ${FMRI_2} not in the repository but should be"
 215 
 216         RESULT=$STF_FAIL
 217 }
 218 
 219 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_3} > /dev/null 2>&1
 220 ret=$?
 221 [[ $ret -ne 0 ]] && {
 222         echo "--DIAG: [${assertion}]
 223         dependency on service ${FMRI_2} not in the repository but should be"
 224 
 225         RESULT=$STF_FAIL
 226 }
 227 
 228 #
 229 # svcs should also report dependencies
 230 #
 231 svcs -dH ${FMRI_2} | egrep -s ${FMRI_1} > /dev/null 2>&1
 232 ret=$?
 233 [[ $ret -ne 0 ]] && {
 234         echo "--DIAG: [${assertion}]
 235         dependency on service ${FMRI_2} for ${FMRI_1} not in the repository but should be"
 236 
 237         RESULT=$STF_FAIL
 238 }
 239 
 240 svcs -dH ${FMRI_2} | egrep -s ${FMRI_3} > /dev/null 2>&1
 241 ret=$?
 242 [[ $ret -ne 0 ]] && {
 243         echo "--DIAG: [${assertion}]
 244         dependency on service ${FMRI_2} for $FMRI_3} not in the repository but should be"
 245 
 246         RESULT=$STF_FAIL
 247 }
 248 
 249 
 250 #######################################################################
 251 # Delete only dependent service, verify dependencies, and reimport
 252 #######################################################################
 253 
 254 #
 255 # Delete the svccfg_import_012b service
 256 #
 257 svccfg delete ${TEST_SERVICE_2} > /dev/null 2>&1
 258 ret=$?
 259 [[ $ret -ne 0 ]] && {
 260         echo "--DIAG: [${assertion}]
 261         svccfg delete failed for service ${TEST_SERVICE_2}: ret=$ret"
 262 
 263         RESULT=$STF_FAIL
 264 }
 265 
 266 #
 267 # Verify the dummy svccfg_import_012b service still exists
 268 #
 269 svcs -H ${FMRI_2} > /dev/null 2>&1
 270 ret=$?
 271 [[ $ret -ne 0 ]] && {
 272         echo "--DIAG: [${assertion}]
 273         Dummy service for ${FMRI_2} does not exist as expected"
 274 
 275         RESULT=$STF_FAIL
 276 }
 277 
 278 #
 279 # Verify dependencies still exist for svccfg_import_012b
 280 #
 281 svcs -dH ${FMRI_2} | egrep -s ${FMRI_1} > /dev/null 2>&1
 282 ret=$?
 283 [[ $ret -ne 0 ]] && {
 284         echo "--DIAG: [${assertion}] 
 285         dependency on service ${FMRI_2} for ${FMRI_1} not reported as expected"
 286 
 287         RESULT=$STF_FAIL
 288 }
 289 
 290 svcs -dH ${FMRI_2} | egrep -s ${FMRI_3} > /dev/null 2>&1
 291 ret=$?
 292 [[ $ret -ne 0 ]] && {
 293         echo "--DIAG: [${assertion}]
 294         dependency on service ${FMRI_2} for ${FMRI_3} not reported as expected"
 295 
 296         RESULT=$STF_FAIL
 297 }
 298 
 299 #
 300 # Verify extended properties are still reported by svcprop
 301 #
 302 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_1} > /dev/null 2>&1
 303 ret=$?
 304 [[ $ret -ne 0 ]] && {
 305         echo "--DIAG: [${assertion}]
 306         dependency on service ${FMRI_2} for ${TEST_SERVICE_1} not in the repository but should be"
 307 
 308         RESULT=$STF_FAIL
 309 }
 310 
 311 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_3} > /dev/null 2>&1
 312 ret=$?
 313 [[ $ret -ne 0 ]] && {
 314         echo "--DIAG: [${assertion}]
 315         dependency on service ${FMRI_2} for ${TEST_SERVICE_3} not in the repository but should be"
 316 
 317         RESULT=$STF_FAIL
 318 }
 319 
 320 #
 321 # Reimport svccfg_import_012b
 322 #
 323 service_import ${TEST_SERVICE_2} ${registration_file_2} 
 324 ret=$?
 325 [[ $ret -ne 0 ]] && {
 326         echo "--DIAG: [${assertion}]
 327         import of ${TEST_SERVICE_2} failed"
 328 
 329         RESULT=$STF_FAIL
 330 }
 331 
 332 #
 333 # Verify dependencies are still intact
 334 #
 335 svcs -dH ${FMRI_2} | egrep -s ${FMRI_1} > /dev/null 2>&1
 336 ret=$?
 337 [[ $ret -ne 0 ]] && {
 338         echo "--DIAG: [${assertion}]
 339         dependency on service ${FMRI_2} not reported as expected"
 340 
 341         RESULT=$STF_FAIL
 342 }
 343 
 344 svcs -dH ${FMRI_2} | egrep -s ${FMRI_3} > /dev/null 2>&1
 345 ret=$?
 346 [[ $ret -ne 0 ]] && {
 347         echo "--DIAG: [${assertion}]
 348         dependency on service ${FMRI_2} not reported as expected"
 349 
 350         RESULT=$STF_FAIL
 351 }
 352 
 353 #
 354 # Verify dependences remained intact
 355 #
 356 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_1} > /dev/null 2>&1
 357 ret=$?
 358 [[ $ret -ne 0 ]] && {
 359         echo "--DIAG: [${assertion}]
 360         dependency on service ${FMRI_2} for ${TEST_SERVICE_1} not in the repository but should be"
 361 
 362         RESULT=$STF_FAIL
 363 }
 364 
 365 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_3} > /dev/null 2>&1
 366 ret=$?
 367 [[ $ret -ne 0 ]] && {
 368         echo "--DIAG: [${assertion}]
 369         dependency on service ${FMRI_2} for ${TEST_SERVICE_3} not in the repository but should be"
 370 
 371         RESULT=$STF_FAIL
 372 }
 373 
 374 
 375 #######################################################################
 376 # Delete svccfg_import_012a and svccfg_import_012b service, verify dependencies, reimport
 377 #######################################################################
 378 
 379 #
 380 # Delete svccfg_import_012a and svccfg_import_012b
 381 #
 382 svccfg delete ${TEST_SERVICE_1} > /dev/null 2>&1
 383 ret=$?
 384 [[ $ret -ne 0 ]] && {
 385         echo "--DIAG: [${assertion}]
 386         svccfg delete failed for service ${TEST_SERVICE_1}: ret=$ret"
 387 
 388         RESULT=$STF_FAIL
 389 }
 390 
 391 svccfg delete ${TEST_SERVICE_2} > /dev/null 2>&1
 392 ret=$?
 393 [[ $ret -ne 0 ]] && {
 394         echo "--DIAG: [${assertion}]
 395         svccfg delete failed for service ${TEST_SERVICE_2}: ret=$ret"
 396 
 397         RESULT=$STF_FAIL
 398 }
 399 
 400 #
 401 # Verify the dummy svccfg_import_012b service still exists
 402 #
 403 svcs -H ${FMRI_2} > /dev/null 2>&1
 404 ret=$?
 405 [[ $ret -ne 0 ]] && {
 406         echo "--DIAG: [${assertion}]
 407         Dummy service for ${FMRI_2} does not exist as expected"
 408 
 409         RESULT=$STF_FAIL
 410 }
 411 
 412 #
 413 # Verify appropriate dependencies still exist for svccfg_import_012b
 414 #
 415 svcs -dH ${FMRI_2} | egrep -s ${FMRI_1} > /dev/null 2>&1
 416 ret=$?
 417 [[ $ret -eq 0 ]] && {
 418         echo "--DIAG: [${assertion}]
 419         dependency on service ${FMRI_2} not reported as expected"
 420 
 421         RESULT=$STF_FAIL
 422 }
 423 
 424 svcs -dH ${FMRI_2} | egrep -s ${FMRI_3} > /dev/null 2>&1
 425 ret=$?
 426 [[ $ret -ne 0 ]] && {
 427         echo "--DIAG: [${assertion}]
 428         dependency on service ${FMRI_2} not reported as expected"
 429 
 430         RESULT=$STF_FAIL
 431 }
 432 
 433 #
 434 # Verify extended properties are reported as expected by svcprop
 435 #
 436 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_1} > /dev/null 2>&1
 437 ret=$?
 438 [[ $ret -eq 0 ]] && {
 439         echo "--DIAG: [${assertion}]
 440         dependency on service ${FMRI_2} for ${TEST_SERVICE_1} is in the repository but shouldn't be"
 441 
 442         RESULT=$STF_FAIL
 443 }
 444 
 445 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_3} > /dev/null 2>&1
 446 ret=$?
 447 [[ $ret -ne 0 ]] && {
 448         echo "--DIAG: [${assertion}]
 449         dependency on service ${FMRI_2} not in the repository but should be"
 450 
 451         RESULT=$STF_FAIL
 452 }
 453 
 454 #
 455 # Reimport svccfg_import_012a
 456 #
 457 service_import ${TEST_SERVICE_1} ${registration_file_1} 
 458 ret=$?
 459 [[ $ret -ne 0 ]] && {
 460         echo "--DIAG: [${assertion}]
 461         import of ${TEST_SERVICE_1} failed"
 462 
 463         RESULT=$STF_FAIL
 464 }
 465 
 466 #
 467 # Reimport svccfg_import_012b
 468 #
 469 service_import ${TEST_SERVICE_2} ${registration_file_2} 
 470 ret=$?
 471 [[ $ret -ne 0 ]] && {
 472         echo "--DIAG: [${assertion}]
 473         import of ${TEST_SERVICE_2} failed"
 474 
 475         RESULT=$STF_FAIL
 476 }
 477 
 478 #
 479 # Verify dependences remained intact
 480 #
 481 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_1} > /dev/null 2>&1
 482 ret=$?
 483 [[ $ret -ne 0 ]] && {
 484         echo "--DIAG: [${assertion}]
 485         dependency on service ${FMRI_2} for ${TEST_SERVICE_1} not in the repository but should be"
 486 
 487         RESULT=$STF_FAIL
 488 }
 489 
 490 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_3} > /dev/null 2>&1
 491 ret=$?
 492 [[ $ret -ne 0 ]] && {
 493         echo "--DIAG: [${assertion}]
 494         dependency on service ${FMRI_2} for ${TEST_SERVICE_3} not in the repository but should be"
 495 
 496         RESULT=$STF_FAIL
 497 }
 498 
 499 
 500 #######################################################################
 501 # Delete only svccfg_import_012c service and svccfg_import_012b service
 502 #######################################################################
 503 
 504 #
 505 # Delete svccfg_import_012c and svccfg_import_012b, verify dependencies haven't been lost
 506 #
 507 svccfg delete ${TEST_SERVICE_2} > /dev/null 2>&1
 508 ret=$?
 509 [[ $ret -ne 0 ]] && {
 510         echo "--DIAG: [${assertion}]
 511         svccfg delete failed for service ${TEST_SERVICE_2}: ret=$ret"
 512 
 513         RESULT=$STF_FAIL
 514 }
 515 
 516 svccfg delete ${TEST_SERVICE_3} > /dev/null 2>&1
 517 ret=$?
 518 [[ $ret -ne 0 ]] && {
 519         echo "--DIAG: [${assertion}]
 520         svccfg delete failed for service ${TEST_SERVICE_3}: ret=$ret"
 521 
 522         RESULT=$STF_FAIL
 523 }
 524 
 525 
 526 #
 527 # Verify the dummy svccfg_import_012b service no longer exists
 528 #
 529 svcs -H ${FMRI_2} > /dev/null 2>&1
 530 ret=$?
 531 [[ $ret -eq 0 ]] && {
 532         echo "--DIAG: [${assertion}]
 533         Dummy service for ${FMRI_2} should not exist"
 534 
 535         RESULT=$STF_FAIL
 536 }
 537 
 538 #
 539 # Verify svcprop fails for svccfg_import_012b
 540 #
 541 svcprop ${FMRI_2} > /dev/null 2>&1
 542 ret=$?
 543 [[ $ret -eq 0 ]] && {
 544         echo "--DIAG: [${assertion}]
 545         svcprop succeeded for ${FMRI_2} and shouldn't have"
 546 
 547         RESULT=$STF_FAIL
 548 }
 549 
 550 #
 551 # Verify svccfg_import_012b service is *not* listed in dependency graph
 552 #
 553 output=$(echo ::vertex | mdb -p `pgrep startd` | grep svccfg_import_012b)
 554 if [[ -n "$output" ]]; then
 555         echo "--DIAG: [${assertion}]
 556         $TEST_SERVICE_2 should not be listed in dependency graph"
 557 
 558         RESULT=$STF_FAIL
 559 fi
 560 
 561 #
 562 # Reimport svccfg_import_012b
 563 #
 564 service_import ${TEST_SERVICE_2} ${registration_file_2}
 565 ret=$?
 566 [[ $ret -ne 0 ]] && {
 567         echo "--DIAG: [${assertion}]
 568         Import of ${registration_file_2} expected to return 0, got $ret"
 569 
 570         RESULT=$STF_FAIL
 571 }
 572 
 573 #
 574 # Reimport svccfg_import_012c
 575 #
 576 service_import ${TEST_SERVICE_3} ${registration_file_3} 
 577 ret=$?
 578 [[ $ret -ne 0 ]] && {
 579         echo "--DIAG: [${assertion}]
 580         Import of ${registration_file_2} expected to return 0, got $ret"
 581 
 582         RESULT=$STF_FAIL
 583 }
 584 
 585 #
 586 # Verify appropriate dependencies are correct for all services
 587 #
 588 svcs -dH ${FMRI_2} | egrep -s ${FMRI_1} > /dev/null 2>&1
 589 ret=$?
 590 [[ $ret -ne 0 ]] && {
 591         echo "--DIAG: [${assertion}]
 592         dependency on service ${FMRI_2} for ${FMRI_1} not reported as expected"
 593 
 594         RESULT=$STF_FAIL
 595 }
 596 
 597 svcs -dH ${FMRI_2} | egrep -s ${FMRI_3} > /dev/null 2>&1
 598 ret=$?
 599 [[ $ret -ne 0 ]] && {
 600         echo "--DIAG: [${assertion}]
 601         dependency on service ${FMRI_2} for ${FMRI_3} not reported as expected"
 602 
 603         RESULT=$STF_FAIL
 604 }
 605 
 606 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_1} > /dev/null 2>&1
 607 ret=$?
 608 [[ $ret -ne 0 ]] && {
 609         echo "--DIAG: [${assertion}]
 610         dependency on service ${FMRI_2} for ${TEST_SERVICE_1} not in the repository but should be"
 611 
 612         RESULT=$STF_FAIL
 613 }
 614 
 615 svcprop ${FMRI_2} | egrep test_dependency | egrep -s ${TEST_SERVICE_3} > /dev/null 2>&1
 616 ret=$?
 617 [[ $ret -ne 0 ]] && {
 618         echo "--DIAG: [${assertion}]
 619         dependency on service ${FMRI_2} for ${TEST_SERVICE_3} not in the repository but should be"
 620 
 621         RESULT=$STF_FAIL
 622 }
 623 
 624 exit $RESULT