Method: Unix::Exec#ping

Defined in:
lib/beaker/host/unix/exec.rb

#ping(target, attempts = 5) ⇒ Boolean

Attempt to ping the provided target hostname

Parameters:

  • target (String)

    The hostname to ping

  • attempts (Integer) (defaults to: 5)

    Amount of times to attempt ping before giving up

Returns:

  • (Boolean)

    true of ping successful, overwise false



175
176
177
178
179
180
181
182
183
184
# File 'lib/beaker/host/unix/exec.rb', line 175

def ping target, attempts = 5
  try = 0
  while try < attempts
    result = exec(Beaker::Command.new("ping -c 1 #{target}"), :accept_all_exit_codes => true)
    return true if result.exit_code == 0

    try += 1
  end
  result.exit_code == 0
end