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: depends_035
  32 # DESCRIPTION:
  33 #  Dependencies can be added to an online service.
  34 #
  35 # end __stf_assertion__
  36 #
  37 
  38 . ${STF_TOOLS}/include/stf.kshlib
  39 . ${STF_SUITE}/include/gltest.kshlib
  40 . ${STF_SUITE}/include/svc.startd_config.kshlib
  41 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  42 
  43 typeset service_setup=0
  44 function cleanup {
  45         common_cleanup
  46         rm -f $service_state1 $service_state2
  47 }
  48 
  49 trap cleanup 0 1 2 15
  50 
  51 readonly ME=$(whence -p ${0})
  52 readonly MYLOC=$(dirname ${ME})
  53 
  54 DATA=$MYLOC
  55 
  56 readonly registration_template=$DATA/service_035.xml
  57 
  58 extract_assertion_info $ME
  59 
  60 # make sure that the svc.startd is running
  61 verify_daemon
  62 if [ $? -ne 0 ]; then
  63         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  64         print -- "  continue"
  65         exit $STF_UNRESOLVED
  66 fi
  67 
  68 # Make sure the environment is clean - the test service isn't running
  69 print -- "--INFO: Cleanup any old $test_FMRI1, $test_FMRI2 state"
  70 service_cleanup $test_service
  71 if [ $? -ne 0 ]; then
  72         print -- "--DIAG: $assertion: cleanup of a previous instance failed"
  73         exit $STF_UNRESOLVED
  74 fi
  75 
  76 print -- "--INFO: generating manifest for importation into repository"
  77 manifest_generate $registration_template \
  78         TEST_SERVICE=$test_service \
  79         TEST_INSTANCE1=$test_instance1 \
  80         TEST_INSTANCE2=$test_instance2 \
  81         SERVICE_APP=$service_app \
  82         LOGFILE=$service_log \
  83         STATEFILE1=$service_state1 \
  84         STATEFILE2=$service_state2 > $registration_file
  85 
  86 print -- "--INFO: Importing service into repository"
  87 manifest_purgemd5 $registration_file
  88 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  89 
  90 if [ $? -ne 0 ]; then
  91         print -- "--DIAG: $assertion: Unable to import the services $test_FMRI1"
  92         print -- "  and $test_FMRI2 error messages from svccfg: "
  93         print -- "  \"$(cat $svccfg_errfile)\""
  94         exit $STF_UNRESOLVED
  95 fi
  96 service_setup=1
  97 
  98 print -- "--INFO: Waiting for $test_FMRI1 to come online"
  99 service_wait_state $test_FMRI1 online
 100 if [ $? -ne 0 ]; then
 101         print -- "--DIAG: $assertion: Service $test_FMRI1 did not come online"
 102         exit $STF_FAIL
 103 fi
 104 
 105 print -- "--INFO: Waiting for $test_FMRI2 to come online"
 106 service_wait_state $test_FMRI2 online
 107 if [ $? -ne 0 ]; then
 108         print -- "--DIAG: $assertion: Service $test_FMRI2 did not come online"
 109         exit $STF_FAIL
 110 fi
 111 
 112 print -- "--INFO: Add dependency from $test_FMRI2 -> $test_FMRI1"
 113 service_dependency_add $test_FMRI2 btoa require_all refresh svc:/$test_FMRI1
 114 
 115 print -- "--INFO: Refresh $test_FMRI2"
 116 svcadm refresh $test_FMRI2
 117 if [ $? -ne 0 ]; then
 118         print -- "--DIAG: $assertion: Service $test_FMRI2 didn't refresh"
 119         exit $STF_FAIL
 120 fi
 121 
 122 print -- "--INFO: Verfify service $test_FMRI2 is online"
 123 service_wait_state $test_FMRI2 online
 124 if [ $? -ne 0 ]; then
 125         print -- "--DIAG: $assertion: Service $test_FMRI2 isn't online"
 126         exit $STF_FAIL
 127 fi
 128 
 129 print -- "--INFO: Disable the service $test_FMRI1"
 130 svcadm disable $test_FMRI1
 131 if [ $? -ne 0 ]; then
 132         print -- "--DIAG: could not disable $test_FMRI1"
 133         exit $STF_FAIL
 134 fi
 135 
 136 print -- "--INFO: Waiting for service $test_FMRI2 to go offline"
 137 service_wait_state $test_FMRI2 offline
 138 if [ $? -ne 0 ]; then
 139         print -- "--DIAG: service $test_FMRI2 didn't go offline"
 140         exit $STF_FAIL
 141 fi
 142 
 143 print -- "--INFO: Cleaning up service"
 144 cleanup
 145 
 146 exit $STF_PASS