lib/beaker/host/unix/exec.rb
def reboot(wait_time=10, max_connection_tries=9, uptime_retries=18)
    require 'time'

    begin
      original_boot_time_str = exec(Beaker::Command.new('who -b'), {:max_connection_tries => max_connection_tries, :silent => true}).stdout
      original_boot_time_line = original_boot_time_str.lines.grep(/boot/).first

      raise Beaker::Host::RebootFailure, "Could not find system boot time using 'who -b': #{original_boot_time_str}" unless original_boot_time_line

      original_boot_time = Time.parse(original_boot_time_line)

      exec(Beaker::Command.new('/bin/systemctl reboot -i || reboot || /sbin/shutdown -r now'), :expect_connection_failure => true)
    rescue Beaker::Host::CommandFailure => e
      raise Beaker::Host::RebootFailure, "Command failed when attempting to reboot: #{e.message}"
    rescue RuntimeError => e
      raise Beaker::Host::RebootFailure, "Unexpected exception in reboot: #{e.message}"
    rescue ArgumentError => e
      raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
    end

    attempts = 0
    begin
      # give the host a little time to shutdown
      @logger.debug("Waiting #{wait_time} for host to shut down.")
      sleep wait_time

      current_boot_time_str = exec(Beaker::Command.new('who -b'), {:max_connection_tries => max_connection_tries, :silent => true}).stdout
      current_boot_time = Time.parse(current_boot_time_str.lines.grep(/boot/).first)

      @logger.debug("Original Boot Time: #{original_boot_time}")
      @logger.debug("Current Boot Time: #{current_boot_time}")

      unless current_boot_time > original_boot_time
        raise Beaker::Host::RebootFailure, "Boot time did not reset. Reboot appears to have failed."
      end
    rescue Beaker::Host::RebootFailure => e
      attempts += 1
      if attempts < uptime_retries
        @logger.debug("Boot time did not reset. Will retry #{uptime_retries - attempts} more times.")
        retry
      else
        raise
      end
    rescue Beaker::Host::CommandFailure => e
      raise Beaker::Host::RebootFailure, "Command failed when attempting to reboot: #{e.message}"
    rescue RuntimeError => e
      raise Beaker::Host::RebootFailure, "Unexpected exception in reboot: #{e.message}"
    rescue ArgumentError => e
      raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
    end
  end
# Reboots the host, comparing uptime values to verify success
# @param [Integer] wait_time How long to wait after sending the reboot
#                            command before attempting to check in on the host
# @param [Integer] max_connection_tries How many times to retry connecting to
#                            host after reboot. Note that there is an fibbonacci
#                            backoff when attempting retries so the time spent
#                            waiting on this can grow quickly.
# @param [Integer] uptime_retries How many times to check to see if the value of the uptime has reset.
#
# Will throw an exception RebootFailure if it fails
Reboots the host, comparing uptime values to verify success
Reboots the host comparing uptime values to verify success
def reboot(wait_time=10, max_connection_tries=9, uptime_retries=18)
    require 'time'
    begin
      original_boot_time_str = exec(Beaker::Command.new('who -b'), {:max_connection_tries => max_connection_tries, :silent => true}).stdout
      original_boot_time_line = original_boot_time_str.lines.grep(/boot/).first
      raise Beaker::Host::RebootFailure, "Could not find system boot time using 'who -b': #{original_boot_time_str}" unless original_boot_time_line
      original_boot_time = Time.parse(original_boot_time_line)
      exec(Beaker::Command.new('/bin/systemctl reboot -i || reboot || /sbin/shutdown -r now'), :expect_connection_failure => true)
    rescue Beaker::Host::CommandFailure => e
      raise Beaker::Host::RebootFailure, "Command failed when attempting to reboot: #{e.message}"
    rescue RuntimeError => e
      raise Beaker::Host::RebootFailure, "Unexpected exception in reboot: #{e.message}"
    rescue ArgumentError => e
      raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
    end
    attempts = 0
    begin
      @logger.debug("Waiting #{wait_time} for host to shut down.")
      sleep wait_time
      current_boot_time_str = exec(Beaker::Command.new('who -b'), {:max_connection_tries => max_connection_tries, :silent => true}).stdout
      current_boot_time = Time.parse(current_boot_time_str.lines.grep(/boot/).first)
      @logger.debug("Original Boot Time: #{original_boot_time}")
      @logger.debug("Current Boot Time: #{current_boot_time}")
      unless current_boot_time > original_boot_time
        raise Beaker::Host::RebootFailure, "Boot time did not reset. Reboot appears to have failed."
      end
    rescue Beaker::Host::RebootFailure => e
      attempts += 1
      if attempts < uptime_retries
        @logger.debug("Boot time did not reset. Will retry #{uptime_retries - attempts} more times.")
        retry
      else
        raise
      end
    rescue Beaker::Host::CommandFailure => e
      raise Beaker::Host::RebootFailure, "Command failed when attempting to reboot: #{e.message}"
    rescue RuntimeError => e
      raise Beaker::Host::RebootFailure, "Unexpected exception in reboot: #{e.message}"
    rescue ArgumentError => e
      raise Beaker::Host::RebootFailure, "Unable to parse time: #{e.message}"
    end
  end
def reboot ( wait_time = 10 , max_connection_tries = 9 , uptime_retries = 18 ) require 'time' begin original_boot_time_str = exec ( Beaker :: Command . new ( 'who -b' ) , { :max_connection_tries => max_connection_tries , :silent => true } ) . stdout original_boot_time_line = original_boot_time_str . lines . grep ( / boot / ) . first raise Beaker :: Host :: RebootFailure , "Could not find system boot time using 'who -b': #{original_boot_time_str}" unless original_boot_time_line original_boot_time = Time . parse ( original_boot_time_line ) exec ( Beaker :: Command . new ( '/bin/systemctl reboot -i || reboot || /sbin/shutdown -r now' ) , :expect_connection_failure => true ) rescue Beaker :: Host :: CommandFailure => e raise Beaker :: Host :: RebootFailure , "Command failed when attempting to reboot: #{e.message}" rescue RuntimeError => e raise Beaker :: Host :: RebootFailure , "Unexpected exception in reboot: #{e.message}" rescue ArgumentError => e raise Beaker :: Host :: RebootFailure , "Unable to parse time: #{e.message}" end attempts = 0 begin @logger . debug ( "Waiting #{wait_time} for host to shut down." ) sleep wait_time current_boot_time_str = exec ( Beaker :: Command . new ( 'who -b' ) , { :max_connection_tries => max_connection_tries , :silent => true } ) . stdout current_boot_time = Time . parse ( current_boot_time_str . lines . grep ( / boot / ) . first ) @logger . debug ( "Original Boot Time: #{original_boot_time}" ) @logger . debug ( "Current Boot Time: #{current_boot_time}" ) unless current_boot_time > original_boot_time raise Beaker :: Host :: RebootFailure , "Boot time did not reset. Reboot appears to have failed." end rescue Beaker :: Host :: RebootFailure => e attempts += 1 if attempts < uptime_retries @logger . debug ( "Boot time did not reset. Will retry #{uptime_retries - attempts} more times." ) retry else raise end rescue Beaker :: Host :: CommandFailure => e raise Beaker :: Host :: RebootFailure , "Command failed when attempting to reboot: #{e.message}" rescue RuntimeError => e raise Beaker :: Host :: RebootFailure , "Unexpected exception in reboot: #{e.message}" rescue ArgumentError => e raise Beaker :: Host :: RebootFailure , "Unable to parse time: #{e.message}" end end
Reboots the host, comparing uptime values to verify success
Reboots the host comparing uptime values to verify success
# give the host a little time to shutdown
wait_time
max_connection_tries
uptime_retries
uptime_retries How many times to check to see if the value of the uptime has reset. Will throw an exception RebootFailure if it fails
uptime_retries How many times to check to see if the value of the uptime has reset . Will throw an exception RebootFailure if it fails