Sha256: 8503b0ec247443040f685db62dfab3e815fb6a75b8af8372da663fd25a9134e8
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
require 'net/ssh' module Torpedo class NetUtil < Test::Unit::TestCase def self.ssh_test(ip_addr, network_namespace, test_cmd, test_output, admin_pass) if network_namespace then out=%x{ip netns exec #{network_namespace} torpedo ssh --ip-address=#{ip_addr} --test-command='#{test_cmd}' --test-output='#{test_output}' --admin-password='#{admin_pass}'} retval=$? if retval.success? then return true else puts out return false end end ssh_opts = {:paranoid => false} if TEST_ADMIN_PASSWORD then ssh_opts.store(:password, admin_pass) else ssh_identity=SSH_PRIVATE_KEY ssh_opts.store(:keys, ssh_identity) end begin Timeout::timeout(SSH_TIMEOUT) do while(1) do begin Net::SSH.start(ip_addr, 'root', ssh_opts) do |ssh| return ssh.exec!(test_cmd) == test_output end rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, Net::SSH::Exception next end end end rescue Timeout::Error => te fail("Timeout trying to ssh to server: #{ip_addr}") end return false end def self.ping_test(ip_addr, network_namespace=nil) begin namespace_cmd = network_namespace.nil? ? "" : "ip netns exec #{network_namespace} " ping = TEST_IP_TYPE == 6 ? 'ping6' : 'ping' ping_command = "#{namespace_cmd}#{ping} -c 1 #{ip_addr} > /dev/null 2>&1" Timeout::timeout(PING_TIMEOUT) do while(1) do return true if system(ping_command) end end rescue Timeout::Error => te fail("Timeout pinging server: #{ping_command}") end return false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
torpedo-2.1.0 | lib/torpedo/net_util.rb |