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_036
  32 # DESCRIPTION:
  33 #  Dependencies can be added to an offline 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         rm -f $svccfg_errfile
  46         common_cleanup
  47         rm -f $service_state1 $service_state2 $service_state3
  48         return $?
  49 }
  50 
  51 trap cleanup 0 1 2 15
  52 
  53 readonly ME=$(whence -p ${0})
  54 readonly MYLOC=$(dirname ${ME})
  55 
  56 DATA=$MYLOC
  57 
  58 readonly registration_template=$DATA/service_036.xml
  59 
  60 extract_assertion_info $ME
  61 
  62 # make sure that the svc.startd is running
  63 verify_daemon
  64 if [ $? -ne 0 ]; then
  65         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  66         print -- "  continue"
  67         exit $STF_UNRESOLVED
  68 fi
  69 
  70 # Make sure the environment is clean - the test service isn't running
  71 print -- "--INFO: Cleanup any old svc:/$test_service state"
  72 service_cleanup $test_service
  73 if [ $? -ne 0 ]; then
  74         print -- "--DIAG: $assertion: cleanup of a previous instance failed"
  75         exit $STF_UNRESOLVED
  76 fi
  77 
  78 print -- "--INFO: generating manifest for importation into repository"
  79 manifest_generate $registration_template \
  80         TEST_SERVICE=$test_service \
  81         TEST_INSTANCE1=$test_instance1 \
  82         TEST_INSTANCE2=$test_instance2 \
  83         TEST_INSTANCE3=$test_instance3 \
  84         SERVICE_APP=$service_app \
  85         LOGFILE=$service_log \
  86         STATEFILE1=$service_state1 \
  87         STATEFILE2=$service_state2 \
  88         STATEFILE3=$service_state3 \
  89         > $registration_file
  90 
  91 print -- "--INFO: Importing service into repository"
  92 manifest_purgemd5 $registration_file
  93 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  94 
  95 if [ $? -ne 0 ]; then
  96         print -- "--DIAG: $assertion: Unable to import svc:/$test_service"
  97         print -- "  error messages from svccfg: "
  98         print -- "  \"$(cat $svccfg_errfile)\""
  99         exit $STF_UNRESOLVED
 100 fi
 101 service_setup=1
 102 
 103 print -- "--INFO: Waiting for $test_FMRI2 to come online"
 104 service_wait_state $test_FMRI2 online
 105 if [ $? -ne 0 ]; then
 106         print -- "--DIAG: $assertion: Service $test_FMRI2 did not come online
 107         Current state: `svcprop -p restarter/state $test_FMRI2`"
 108         exit $STF_FAIL
 109 fi
 110 
 111 print -- "--INFO: Wait for $test_FMRI3 to go to offline"
 112 service_wait_state $test_FMRI3 offline
 113 if [ $? -ne 0 ]; then
 114         print -- "--DIAG: $assertion: Service $test_FMRI3 did not go offline
 115         Current state: `svcprop -p restarter/state $test_FMRI3`"
 116         exit $STF_FAIL
 117 fi
 118 
 119 print -- "--INFO: Add dependency from $test_FMRI3 -> $test_FMRI2"
 120 service_dependency_elt_add $test_FMRI3 cdepa svc:/$test_FMRI2
 121 
 122 print -- "--INFO: Dump out new service manifest"
 123 svccfg export ${test_FMRI3%:*}
 124 
 125 print -- "--INFO: Refresh $test_FMRI3"
 126 svcadm refresh $test_FMRI3
 127 if [ $? -ne 0 ]; then
 128         print -- "--DIAG: $assertion: Could not refresh $test_FMRI3"
 129         exit $STF_FAIL
 130 fi
 131 
 132 print -- "--INFO: Verify service $test_FMRI3 is online"
 133 service_wait_state $test_FMRI3 online
 134 if [ $? -ne 0 ]; then
 135         print -- "--DIAG: $assertion: Service $test_FMRI3 isn't online
 136         Current state: `svcprop -p restarter/state $test_FMRI3`"
 137         exit $STF_FAIL
 138 fi
 139 
 140 print -- "--INFO: Disable the service $test_FMRI2"
 141 svcadm disable $test_FMRI2
 142 if [ $? -ne 0 ]; then
 143         print -- "--DIAG: could not disable $test_FMRI2"
 144         exit $STF_FAIL
 145 fi
 146 
 147 print -- "--INFO: Verify that service $test_FMRI3 goes offline"
 148 service_wait_state $test_FMRI3 offline
 149 if [ $? -ne 0 ]; then
 150         print -- "--DIAG: service $test_FMRI3 didn't go offline
 151         Current state: `svcprop -p restarter/state $test_FMRI3`"
 152         exit $STF_FAIL
 153 fi
 154 
 155 print -- "--INFO: Cleaning up service"
 156 cleanup
 157 
 158 exit $STF_PASS