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: context_042
  32 # DESCRIPTION:
  33 #  svc.startd will transition a service to the maintenance state if the
  34 #  method to be executed's projectid specified by the project attribute
  35 #  of the method_context does not exist.
  36 #
  37 # end __stf_assertion__
  38 #
  39 
  40 . ${STF_TOOLS}/include/stf.kshlib
  41 . ${STF_SUITE}/include/gltest.kshlib
  42 . ${STF_SUITE}/include/svc.startd_config.kshlib
  43 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  44 
  45 typeset service_setup=0
  46 function cleanup {
  47         common_cleanup
  48 }
  49 
  50 trap cleanup 0 1 2 15
  51 
  52 readonly ME=$(whence -p ${0})
  53 readonly MYLOC=$(dirname ${ME})
  54 
  55 DATA=$MYLOC
  56 
  57 readonly registration_template=$DATA/service_042.xml
  58 
  59 extract_assertion_info $ME
  60 
  61 # make sure that the svc.startd is running
  62 verify_daemon
  63 if [ $? -ne 0 ]; then
  64         echo "--DIAG: $assertion: svc.startd is not executing. Cannot "
  65         echo "  continue"
  66         exit $STF_UNRESOLVED
  67 fi
  68 
  69 # Make sure the environment is clean - the test service isn't running
  70 echo "--INFO: Cleanup any old $test_FMRI state"
  71 service_cleanup $test_service
  72 if [ $? -ne 0 ]; then
  73         echo "--DIAG: $assertion: cleanup of a previous instance failed"
  74         exit $STF_UNRESOLVED
  75 fi
  76 
  77 echo "--INFO: create world read/writeable log file for the service"
  78 rm -f $service_log
  79 touch $service_log
  80 if [ $? -ne 0 ]; then
  81         echo "--DIAG: $assertion: could not create log file"
  82         exit $STF_UNRESOLVED
  83 fi
  84 chmod a+rw $service_log
  85 if [ $? -ne 0 ]; then
  86         echo "--DIAG: $assertion: could not make log file world writeable"
  87         exit $STF_UNRESOLVED
  88 fi
  89 chmod a+rwx $RUNDIR
  90 if [ $? -ne 0 ]; then
  91         echo "--DIAG: $assertion: could not make $RUNDIR world rwx"
  92         exit $STF_UNRESOLVED
  93 fi
  94 
  95 echo "--INFO: Find an unused project ID"
  96 typeset atproj=0
  97 typeset projid=
  98 
  99 while [ $atproj -lt 1000 ]; do
 100         typeset lprojid=$(getent project $atproj | cut -d: -f 2,2)
 101         if [ -z "$lprojid" ]; then
 102                 projid=$atproj
 103                 break
 104         fi
 105         atproj=$((atproj + 1))
 106 done
 107 readonly context_projid=$atproj
 108 
 109 echo "--INFO: generating manifest for importation into repository"
 110 manifest_generate $registration_template \
 111         TEST_SERVICE=$test_service \
 112         TEST_INSTANCE=$test_instance \
 113         SERVICE_APP=$service_app \
 114         LOGFILE=$service_log \
 115         PROJECT=$context_projid \
 116         STATEFILE=$service_state > $registration_file
 117 manifest_zone_clean $registration_file
 118 
 119 echo "--INFO: Importing service into repository"
 120 manifest_purgemd5 $registration_file
 121 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 122 
 123 if [ $? -ne 0 ]; then
 124         echo "--DIAG: $assertion: Unable to import the service $test_FMRI"
 125         echo "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 126         exit $STF_UNRESOLVED
 127 fi
 128 service_setup=1
 129 
 130 echo "--INFO: Wait for $test_FMRI to enter maintenance mode"
 131 service_wait_state $test_FMRI maintenance
 132 if [ $? -ne 0 ]; then
 133         echo "--DIAG: $assertion: Service $test_FMRI did not enter maintenance"
 134         echo "  it is in the '$(svcs -H -o STATE $test_FMRI)' state."
 135         exit $STF_FAIL
 136 fi
 137 
 138 echo "--INFO: Cleaning up service"
 139 cleanup
 140 
 141 exit $STF_PASS