Class: Torpedo::NetUtil
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Torpedo::NetUtil
- Defined in:
- lib/torpedo/net_util.rb
Class Method Summary collapse
- .ping_test(ip_addr, network_namespace = nil) ⇒ Object
- .ssh_test(ip_addr, network_namespace, test_cmd, test_output, admin_pass) ⇒ Object
Class Method Details
.ping_test(ip_addr, network_namespace = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/torpedo/net_util.rb', line 47 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 |
.ssh_test(ip_addr, network_namespace, test_cmd, test_output, admin_pass) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/torpedo/net_util.rb', line 6 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 |