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_037
  32 # DESCRIPTION:
  33 #  Dependencies can be added to a service in maintenance state.
  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 $service_state3
  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_037.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 svc:/$test_service 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         TEST_INSTANCE3=$test_instance3 \
  82         SERVICE_APP=$service_app \
  83         LOGFILE=$service_log \
  84         STATEFILE1=$service_state1 \
  85         STATEFILE2=$service_state2 \
  86         STATEFILE3=$service_state3 \
  87         > $registration_file
  88 
  89 print -- "--INFO: Importing service into repository"
  90 manifest_purgemd5 $registration_file
  91 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  92 
  93 if [ $? -ne 0 ]; then
  94         print -- "--DIAG: $assertion: Unable to import svc:/$test_service"
  95         print -- "  error messages from svccfg: "
  96         print -- "  \"$(cat $svccfg_errfile)\""
  97         exit $STF_UNRESOLVED
  98 fi
  99 service_setup=1
 100 
 101 print -- "--INFO: Waiting for $test_FMRI2 to come online"
 102 service_wait_state $test_FMRI2 online
 103 if [ $? -ne 0 ]; then
 104         print -- "--DIAG: $assertion: Service $test_FMRI2 did not come online"
 105         exit $STF_UNRESOLVED
 106 fi
 107 
 108 print -- "--INFO: Wait for $test_FMRI3 to go to online"
 109 service_wait_state $test_FMRI3 online
 110 if [ $? -ne 0 ]; then
 111         print -- "--DIAG: $assertion: Service $test_FMRI3 did not go online"
 112         exit $STF_UNRESOLVED
 113 fi
 114 
 115 print -- "--INFO: Transition $test_FMRI3 to maintenance"
 116 svcadm mark maintenance $test_FMRI3
 117 if [ $? -ne 0 ]; then
 118         print -- "--DIAG: $assertion: Service $test_FMRI3 did not accept"
 119         print -- "  maintenance request"
 120         exit $STF_UNRESOLVED
 121 fi
 122 
 123 print -- "--INFO: Wait for $test_FMRI3 to enter maintenance mode"
 124 service_wait_state $test_FMRI3 maintenance
 125 if [ $? -ne 0 ]; then
 126         print -- "--DIAG: $assertion: Service $test_FMRI3 did not enter"
 127         print -- "  maintenance state. It is instead "
 128         print -- "  in: '$(svcs -H -o STATE $test_FMRI3)' state"
 129 fi
 130 
 131 print -- "--INFO: Add dependency from $test_FMRI3 -> $test_FMRI2"
 132 service_dependency_elt_add $test_FMRI3 cdepa svc:/$test_FMRI2
 133 
 134 print -- "--INFO: Refresh $test_FMRI3"
 135 svcadm refresh $test_FMRI3
 136 if [ $? -ne 0 ]; then
 137         print -- "--DIAG: $assertion: Service $test_FMRI3 didn't refresh"
 138         exit $STF_FAIL
 139 fi
 140 print -- "--INFO: Refresh $test_FMRI2"
 141 svcadm refresh $test_FMRI2
 142 if [ $? -ne 0 ]; then
 143         print -- "--DIAG: $assertion: Service $test_FMRI2 didn't refresh"
 144         exit $STF_FAIL
 145 fi
 146 print -- "--INFO: Refresh $test_FMRI1"
 147 svcadm refresh $test_FMRI1
 148 if [ $? -ne 0 ]; then
 149         print -- "--DIAG: $assertion: Service $test_FMRI1 didn't refresh"
 150         exit $STF_FAIL
 151 fi
 152 
 153 print -- "--INFO: Verify service $test_FMRI3 is still in maintenance"
 154 service_wait_state $test_FMRI3 maintenance
 155 if [ $? -ne 0 ]; then
 156         print -- "--DIAG: $assertion: Service $test_FMRI3 isn't in"
 157         print -- "  maintenance. It is in '$(svcs -H -o STATE $test_FMRI3)'"
 158         print -- "  state."
 159         exit $STF_FAIL
 160 fi
 161 
 162 print -- "--INFO: Cleaning up service"
 163 cleanup
 164 
 165 exit $STF_PASS