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_030
  32 # DESCRIPTION:
  33 #  If a service, service_A, has a dependency on another service,
  34 #  service_B, and service_B has no dependencies. Both are put
  35 #  online. If service_B has a dependency added that causes it to
  36 #  now depend on service_A then service_B will be transitioned to
  37 #  maintenance mode immediately. Any effort to move it out of
  38 #  maintenance mode will fail until it has the dependency removed.
  39 #  (single link circular dependency)
  40 #
  41 # end __stf_assertion__
  42 #
  43 
  44 . ${STF_TOOLS}/include/stf.kshlib
  45 . ${STF_SUITE}/include/gltest.kshlib
  46 . ${STF_SUITE}/include/svc.startd_config.kshlib
  47 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  48 
  49 typeset service_setup=0
  50 function cleanup {
  51         common_cleanup
  52         rm -f $service_state1 $service_state2
  53 }
  54 
  55 trap cleanup 0 1 2 15
  56 
  57 readonly ME=$(whence -p ${0})
  58 readonly MYLOC=$(dirname ${ME})
  59 
  60 DATA=$MYLOC
  61 
  62 readonly registration_template=$DATA/service_030.xml
  63 
  64 extract_assertion_info $ME
  65 
  66 # make sure that the svc.startd is running
  67 verify_daemon
  68 if [ $? -ne 0 ]; then
  69         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  70         print -- "  continue"
  71         exit $STF_UNRESOLVED
  72 fi
  73 
  74 # Make sure the environment is clean - the test service isn't running
  75 print -- "--INFO: Cleanup any old $test_FMRI1, $test_FMRI2 state"
  76 service_cleanup $test_service
  77 if [ $? -ne 0 ]; then
  78         print -- "--DIAG: $assertion: cleanup of a previous instance failed"
  79         exit $STF_UNRESOLVED
  80 fi
  81 
  82 print -- "--INFO: generating manifest for importation into repository"
  83 manifest_generate $registration_template \
  84         TEST_SERVICE=$test_service \
  85         TEST_INSTANCE1=$test_instance1 \
  86         TEST_INSTANCE2=$test_instance2 \
  87         SERVICE_APP=$service_app \
  88         LOGFILE=$service_log \
  89         STATEFILE1=$service_state1 \
  90         STATEFILE2=$service_state2 \
  91         > $registration_file
  92 
  93 print -- "--INFO: Importing service into repository"
  94 manifest_purgemd5 $registration_file
  95 svccfg -v import $registration_file >$svccfg_errfile 2>&1
  96 
  97 if [ $? -ne 0 ]; then
  98         print -- "--DIAG: $assertion: Unable to import the services $test_FMRI1"
  99         print -- "  and $test_FMRI2 error messages from svccfg: "
 100         print -- "  \"$(cat $svccfg_errfile)\""
 101         exit $STF_UNRESOLVED
 102 fi
 103 service_setup=1
 104 
 105 print -- "--INFO: Wait for $test_FMRI2 to go online"
 106 service_wait_state $test_FMRI2 online
 107 if [ $? -ne 0 ]; then
 108         print -- "--DIAG: $assertion: Service $test_FMRI2 didn't go"
 109         print -- "  online. It is in " \
 110                 "\"$(svcs -H -o STATE $test_FMRI2)\" state."
 111         exit $STF_FAIL
 112 fi
 113 
 114 print -- "--INFO: Verifying that $test_FMRI1 is in the online state"
 115 service_wait_state $test_FMRI1 online
 116 if [ $? -ne 0 ]; then
 117         print -- "--DIAG: $assertion: Service $test_FMRI1 did not go to the"
 118         print -- "  online state. It is in the " \
 119                 "\"$(svcs -H -o STATE $test_FMRI1)\" state."
 120         exit $STF_FAIL
 121 fi
 122 
 123 print -- "--INFO: Adding the dependency from $test_FMRI2 -> $test_FMRI1"
 124 service_dependency_add $test_FMRI2 btoa require_all error $test_FMRI1
 125 if [ $? -ne 0 ]; then
 126         print -- "--DIAG: Could not add dependency"
 127         exit $STF_FAIL
 128 fi
 129 
 130 print -- "--INFO: Refreshing $test_FMRI2"
 131 svcadm refresh $test_FMRI2
 132 if [ $? -ne 0 ]; then
 133         print -- "--DIAG: Could not refresh service $test_FMRI2"
 134         exit $STF_FAIL
 135 fi
 136 
 137 typeset inmaint=
 138 typeset notinmaint=
 139 
 140 print -- "--INFO: Either $test_FMRI1 or $test_FMRI2 will enter maintenance"
 141 print -- "--INFO: Wait for $test_FMRI1 to enter maintenance state"
 142 service_wait_state $test_FMRI1 maintenance
 143 typeset maint=$?
 144 
 145 if [ $maint -ne 0 ]; then
 146         print -- "--INFO: Wait for $test_FMRI2 to enter maintenance state"
 147         service_wait_state $test_FMRI2 maintenance
 148         if [ $? -eq 0 ]; then
 149                 inmaint=$test_FMRI2
 150                 notinmaint=$test_FMRI1
 151         fi
 152 else
 153         inmaint=$test_FMRI1
 154         notimaint=$test_FMRI2
 155 fi
 156 
 157 if [ -z "$inmaint" ]; then
 158         print -- "--DIAG: neither $test_FMRI1 or $test_FMRI2 entered the"
 159         print -- "  maintenance state"
 160         print -- "  $test_FMRI1 has the '$(svcs -H -o state $test_FMRI1)' state"
 161         print -- "  $test_FMRI2 has the '$(svcs -H -o state $test_FMRI2)' state"
 162         exit $STF_FAIL
 163 fi
 164 
 165 print -- "--INFO: Trying to remove maintenance mode while dependency exists"
 166 svcadm clear $inmaint
 167 
 168 print -- "--INFO: wait for service to re-enter maintenance mode"
 169 service_wait_state $inmaint maintenance
 170 if [ $? -ne 0 ]; then
 171         print -- "--DIAG: service $inmaint did not re-enter maintenance state"
 172         exit $STF_UNRESOLVED
 173 fi
 174 
 175 print -- "--INFO: Removing dependency service_b to service_a"
 176 service_dependency_remove $test_FMRI2 btoa
 177 if [ $? -ne 0 ]; then
 178         print -- "--DIAG: Could not remove dependency"
 179         exit $STF_FAIL
 180 fi
 181 
 182 print -- "--INFO: Refreshing $inmaint"
 183 svcadm refresh $inmaint
 184 if [ $? -ne 0 ]; then
 185         print -- "--DIAG: Could not refresh service $inmaint"
 186         exit $STF_UNRESOLVED
 187 fi
 188 
 189 echo "--INFO: Clearing maintenance mode in $inmaint"
 190 svcadm clear $inmaint
 191 if [ $? -ne 0 ]; then
 192         echo "--DIAG: $assertion: Could not clear $inmaint"
 193         exit $STF_UNRESOLVED
 194 fi
 195 
 196 print -- "--INFO: Wait for $inmaint to enter online state"
 197 service_wait_state $inmaint online
 198 if [ $? -ne 0 ]; then
 199         print -- "--DIAG: service $inmaint did not enter online state"
 200         exit $STF_FAIL
 201 fi
 202 
 203 print -- "--INFO: Cleaning up service"
 204 cleanup
 205 
 206 exit $STF_PASS