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: svcadm_restart_007
  32 #
  33 # DESCRIPTION:
  34 #       Calling 'svcadm restart <FMRI1> <FMRI2>' where FMRI1 and FMRI2 is a 
  35 #       service instance that is in the online state will result in the 
  36 #       service being stopped and restarted.  The exit status shall be 0.
  37 #
  38 # STRATEGY:
  39 #       - Generate a manifest which starts and stops a process.
  40 #       - Enable it using svccfg import <manifest>
  41 #       - Make sure process is started, verify it whether it touched
  42 #               a expected file say 'foo.start'.
  43 #       - remove the file 'foo.start' now.
  44 #       - Call svcadm restart FMRI1 and FMRI2 and make sure it exits 0.
  45 #       - Now the above step, should touch a file  say 'foo.stop when
  46 #               trigerrring a stop event and touch a file say 'foo.start'
  47 #               when trigerring a start event.
  48 #       - Verify foo.start and foo.stop exists.
  49 #       - That proves restarts, restarts a process.
  50 #
  51 # COMMANDS: svcadm(1M)
  52 #
  53 # end __stf_assertion__
  54 ################################################################################
  55 
  56 # First load up definitions of STF result variables like STF_PASS etc.
  57 . ${STF_TOOLS}/include/stf.kshlib
  58 
  59 # Load up definitions of shell functionality common to all smf sub-suites.
  60 . ${STF_SUITE}/include/gltest.kshlib
  61 . ${STF_SUITE}/include/svc.startd_config.kshlib
  62 
  63 # Load up common functions for tests in this directory
  64 . ${STF_SUITE}/${STF_EXEC}/functions.kshlib
  65 
  66 # Define the test's cleanup function
  67 function cleanup {
  68         cleanup_leftovers $test_service1 $start_file1 $stop_file1 \
  69                 $start_process1 $stop_process1 $registration_file1
  70         cleanup_leftovers $test_service2 $start_file2 $stop_file2 \
  71                 $start_process2 $stop_process2 $registration_file2
  72         print_result $RESULT
  73 }
  74 
  75 # Define Variables
  76 readonly assertion=svcadm_restart_007
  77 readonly ME=$(whence -p ${0})
  78 readonly MYLOC=$(dirname ${ME})
  79 readonly registration_template=${STF_SUITE}/tests/svcadm/restart/template.xml
  80 readonly registration_file1=/var/tmp/svcadm_restart_007.$$1.xml
  81 readonly registration_file2=/var/tmp/svcadm_restart_007.$$2.xml
  82 readonly test_service1="smftest_svcadm_1"
  83 readonly test_service2="smftest_svcadm_2"
  84 readonly test_instance="$assertion"
  85 readonly start_process1="/var/tmp/$assertion.$$.start1"
  86 readonly start_process2="/var/tmp/$assertion.$$.start2"
  87 readonly stop_process1="/var/tmp/$assertion.$$.stop1"
  88 readonly stop_process2="/var/tmp/$assertion.$$.stop2"
  89 readonly start_file1="/var/tmp/$assertion.$$.startfile1"
  90 readonly start_file2="/var/tmp/$assertion.$$.startfile2"
  91 readonly stop_file1="/var/tmp/$assertion.$$.stopfile1"
  92 readonly stop_file2="/var/tmp/$assertion.$$.stopfile2"
  93 readonly fmri1="svc:/$test_service1:$test_instance"
  94 readonly fmri2="svc:/$test_service2:$test_instance"
  95 
  96 # Make sure we run as root
  97 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  98 then
  99         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 100         echo "--DIAG: [$assertion]
 101         This test must be run from root."
 102         exit $RESULT
 103 fi
 104 
 105 # Extract and print the assertion from this source script.
 106 extract_assertion_info $ME
 107 
 108 # Initialize test result to pass.
 109 typeset -i RESULT=${STF_UNRESOLVED}
 110 
 111 # Set a trap to execute the cleanup function
 112 trap cleanup 0 1 2 15
 113 
 114 # Exit code for individual commands.
 115 typeset -i tmp_rc=0
 116 
 117 # Execute environmental sanity checks.
 118 check_gl_env
 119 tmp_rc=$?
 120 if [[ $tmp_rc -ne 0 ]]
 121 then
 122         echo "--DIAG: [$assertion]
 123         Invalid smf environment, quitting."
 124         exit $RESULT
 125 fi
 126 
 127 echo "--INFO: [$assertion]
 128         Verify if required manifest template exists"
 129 
 130 if [ ! -s $registration_template ]; then
 131         echo "--DIAG: [$assertion]
 132         $registration_template is not located"
 133         exit $RESULT
 134 fi
 135 
 136 echo "--INFO: [$assertion]
 137         Create test processes in /var/tmp"
 138 
 139 # Create process scripts for test_service1
 140 echo "--INFO: [$assertion]
 141         (for $test_service1):
 142                 $start_process1
 143                 $stop_process1"
 144 
 145 cat > $start_process1 << EOF
 146 #!/bin/ksh -p
 147 /bin/rm -f $start_file1
 148 sleep 1
 149 /bin/date +\%Y\%m\%d\%H\%M\%S > $start_file1
 150 exit 0
 151 EOF
 152 
 153 cat > $stop_process1 << EOF
 154 #!/bin/ksh -p
 155 /bin/rm -f $stop_file1
 156 /bin/date +\%Y\%m\%d\%H\%M\%S > $stop_file1
 157 exit 0
 158 EOF
 159 
 160 # Create process scripts for test_service2
 161 echo "--INFO: [$assertion]
 162         (for $test_service2):
 163 $start_process2
 164 $stop_process2"
 165 
 166 cat > $start_process2 << EOF
 167 #!/bin/ksh -p
 168 /bin/rm -f $start_file2
 169 sleep 1
 170 /bin/date +\%Y\%m\%d\%H\%M\%S > $start_file2
 171 exit 0
 172 EOF
 173 
 174 cat > $stop_process2 << EOF
 175 #!/bin/ksh -p
 176 /bin/rm -f $stop_file2
 177 /bin/date +\%Y\%m\%d\%H\%M\%S > $stop_file2
 178 exit 0
 179 EOF
 180 
 181 echo "--INFO: [$assertion]
 182         chmod 755 $start_process1"
 183 
 184 chmod 755 $start_process1
 185 if [ $? -ne 0 ]; then
 186         echo "--DIAG: [$assertion]
 187         chmod 755 /var/tmp/$start_process1 failed"
 188         exit $RESULT
 189 fi
 190 
 191 echo "--INFO: [$assertion]
 192         chmod 755 $stop_process1"
 193 
 194 chmod 755 $stop_process1
 195 if [ $? -ne 0 ]; then
 196         echo "--DIAG: [$assertion]
 197         chmod 755 /var/tmp/$stop_process1 failed"
 198         exit $RESULT
 199 fi
 200 
 201 echo "--INFO: [$assertion]
 202         chmod 755 $start_process2"
 203 
 204 chmod 755 $start_process2
 205 if [ $? -ne 0 ]; then
 206         echo "--DIAG: [$assertion]
 207         chmod 755 /var/tmp/$start_process2 failed"
 208         exit $RESULT
 209 fi
 210 
 211 echo "--INFO: [$assertion]
 212         chmod 755 $stop_process2"
 213 
 214 chmod 755 $stop_process2
 215 if [ $? -ne 0 ]; then
 216         echo "--DIAG: [$assertion]
 217         chmod 755 /var/tmp/$stop_process2 failed"
 218         exit $RESULT
 219 fi
 220 
 221 # Generate the test service manifest for test service1
 222 echo "--INFO: [$assertion]
 223         Generate .xml required for $test_service1"
 224 
 225 manifest_generate $registration_template \
 226         TEST_SERVICE=$test_service1 \
 227         TEST_INSTANCE=$test_instance \
 228         START_NAME=$start_process1 \
 229         STOP_NAME=$stop_process1 \
 230         SERVICE_APP=$service_app \
 231         STATEFILE=$service_state > $registration_file1
 232 
 233 # Generate the test service manifest for test service2
 234 echo "--INFO: [$assertion]
 235         Generate .xml required for $test_service2"
 236 
 237 manifest_generate $registration_template \
 238         TEST_SERVICE=$test_service2 \
 239         TEST_INSTANCE=$test_instance \
 240         START_NAME=$start_process2 \
 241         STOP_NAME=$stop_process2 \
 242         SERVICE_APP=$service_app \
 243         STATEFILE=$service_state > $registration_file2
 244 
 245 
 246 # Verify that both registration templates were created properly
 247 echo "--INFO: [$assertion]
 248         Verify that registration templates exist and size > 0 bytes"
 249 
 250 if [ ! -s $registration_file1 ]; then
 251         echo "--DIAG: [$assertion]
 252         $registration_file1 not found or size <= 0 bytes"
 253         exit $RESULT
 254 fi
 255 
 256 if [ ! -s $registration_file2 ]; then
 257         echo "--DIAG: [$assertion]
 258         $registration_file2 not found or size <= 0 bytes"
 259         exit $RESULT
 260 fi
 261 
 262 # Import the services into the repository
 263 echo "--INFO: [$assertion]
 264         Import the service to repository using svccfg import"
 265 
 266 svccfg import $registration_file1 > /dev/null 2>&1
 267 if [ $? -ne 0 ]; then
 268         print "--DIAG: $assertion: Unable to import the service $test_service1"
 269         exit $RESULT
 270 fi
 271 
 272 svccfg import $registration_file2 > /dev/null 2>&1
 273 if [ $? -ne 0 ]; then
 274         print "--DIAG: $assertion: Unable to import the service  $test_service2"
 275         exit $RESULT
 276 fi
 277 
 278 echo "--INFO: [$assertion]
 279         Wait until $start_process1 is triggered"
 280 
 281 wait_process $start_file1 2>/dev/null
 282 if [ $? -ne 0 ]; then
 283         echo "--DIAG: [$assertion]
 284         $start_process1 not started"
 285         exit $RESULT
 286 fi
 287 
 288 echo "--INFO: [$assertion]
 289         Wait until $start_process2 is triggered"
 290 
 291 wait_process $start_file2 2>/dev/null
 292 if [ $? -ne 0 ]; then
 293         echo "--DIAG: [$assertion]
 294         $start_process2 not started"
 295         exit $RESULT
 296 fi
 297 
 298 # Wait until both services have transitioned to online state
 299 service_wait_state $fmri1 online
 300 if [ $? -ne 0 ]; then
 301         echo "--DIAG: [$assertion]
 302         <$fmri1> is not online"
 303         print_result $RESULT
 304         exit $RESULT
 305 fi
 306 service_wait_state $fmri2 online
 307 if [ $? -ne 0 ]; then
 308         echo "--DIAG: [$assertion]
 309         <$fmri2> is not online"
 310         print_result $RESULT
 311         exit $RESULT
 312 fi
 313 
 314 # Remove the $start_files and call svcadm restart. Expect that the stop
 315 # and start methods are triggered, IN THAT ORDER.
 316 
 317 /usr/bin/rm -f $start_file1 >/dev/null 2>&1
 318 if [ -f $start_file1 ]; then
 319         echo "--DIAG: [$assertion]
 320         $start_file1 should get removed, it is still there"
 321         exit $RESULT
 322 fi
 323 
 324 /usr/bin/rm -f $start_file2 >/dev/null 2>&1
 325 if [ -f $start_file2 ]; then
 326         echo "--DIAG: [$assertion]
 327         $start_file2 should get removed, it is still there"
 328         exit $RESULT
 329 fi
 330 
 331 # Restart the test services.
 332 echo "--INFO: [${assertion}]
 333         restart <$fmri1> <$fmri2> using svcadm"
 334 
 335 svcadm restart $fmri1 $fmri2 >/dev/null 2>&1
 336 ret=$?
 337 if [ $ret -ne 0 ]; then
 338         RESULT=$(update_result $STF_FAIL $RESULT)
 339         echo "--DIAG: [$assertion]
 340                 svcadm restart $fmri1 $fmri2 fails
 341         EXPECTED: output = ret 0
 342         ACTUAL: output ret = $ret"
 343         exit $RESULT
 344 fi
 345 
 346 # Verify stop event is trigerred.
 347 echo "--INFO: [$assertion]
 348         Wait until $stop_process1 is triggered"
 349 
 350 wait_process $stop_file1 2>/dev/null
 351 if [ $? -ne 0 ]; then
 352         RESULT=$(update_result $STF_FAIL $RESULT)
 353         echo "--DIAG: [$assertion]
 354         $stop_process1 not invoked"
 355         exit $RESULT
 356 fi
 357 
 358 echo "--INFO: [$assertion]
 359         Wait until $stop_process2 is triggered"
 360 
 361 wait_process $stop_file2 2>/dev/null
 362 if [ $? -ne 0 ]; then
 363         RESULT=$(update_result $STF_FAIL $RESULT)
 364         echo "--DIAG: [$assertion]
 365         $stop_process2 not invoked"
 366         exit $RESULT
 367 fi
 368 
 369 # Verify that the start processes were loaded
 370 echo "--INFO: [$assertion]
 371         Wait until $start_process1 and $start_process2 have been triggered"
 372 
 373 wait_process $start_file1 2>/dev/null
 374 if [ $? -ne 0 ]; then
 375         RESULT=$(update_result $STF_FAIL $RESULT)
 376         echo "--DIAG: [$assertion]
 377         $start_process1 not invoked"
 378         exit $RESULT
 379 fi
 380 
 381 wait_process $start_file2 2>/dev/null
 382 if [ $? -ne 0 ]; then
 383         RESULT=$(update_result $STF_FAIL $RESULT)
 384         echo "--DIAG: [$assertion]
 385         $start_process2 not invoked"
 386         exit $RESULT
 387 fi
 388 
 389 # Wait until both services are online
 390 service_wait_state $fmri1 online
 391 if [ $? -ne 0 ]; then
 392         RESULT=$(update_result $STF_FAIL $RESULT)
 393         echo "--DIAG: [$assertion]
 394         <$fmri1> is not online"
 395         print_result $RESULT
 396         exit $RESULT
 397 fi
 398 service_wait_state $fmri2 online
 399 if [ $? -ne 0 ]; then
 400         RESULT=$(update_result $STF_FAIL $RESULT)
 401         echo "--DIAG: [$assertion]
 402         <$fmri2> is not online"
 403         print_result $RESULT
 404         exit $RESULT
 405 fi
 406 
 407 # Verify that the start method was not triggered BEFORE the stop method.
 408 echo "--INFO: [$assertion]
 409         Verify that upon restart, stop method was executed BEFORE
 410         start method"
 411 
 412 typeset -i stop_runtime=`cat $stop_file1`
 413 typeset -i start_runtime=`cat $start_file1`
 414 if [ $start_runtime -le $stop_runtime ]; then
 415         RESULT=$(update_result $STF_FAIL $RESULT)
 416         echo "--DIAG: [$assertion]
 417         Restart error for \$fmri1 ($fmri1):
 418         start method was not rerun or was run before stop method
 419                 stop method run time:  `cat $stop_file1`
 420                 start method run time: `cat $start_file1`"
 421         exit $RESULT
 422 fi
 423 
 424 stop_runtime=`cat $stop_file2`
 425 start_runtime=`cat $start_file2`
 426 if [ $start_runtime -le $stop_runtime ]; then
 427         RESULT=$(update_result $STF_FAIL $RESULT)
 428         echo "--DIAG: [$assertion]
 429         Restart error on $fmri2:
 430         start method was not rerun or was run before stop method
 431                 stop method run time:  `cat $stop_file2`
 432                 start method run time: `cat $start_file2`"
 433         exit $RESULT
 434 fi
 435 
 436 # Disable the test instance
 437 svcadm disable $fmri1 $fmri2 >/dev/null 2>&1
 438 ret=$?
 439 if [ $ret -ne 0 ]; then
 440         echo "--DIAG: [$assertion]
 441         svcadm disable $fmri1 $fmri2 failed
 442         EXPECTED: ret = 0
 443         OBSERVED: ret = $ret"
 444         exit $RESULT
 445 fi
 446 
 447 # exit, trap set to call cleanup
 448 RESULT=$STF_PASS
 449 print_result $RESULT
 450 exit $RESULT
 451 
 452 #
 453 ### END
 454 #