SSH.up? uses Net::SSH timeouts again, for now. Looks like checking if a VM is up is finally working properly.
This commit is contained in:
parent
8c2068565b
commit
d48b79e8ec
|
@ -24,7 +24,13 @@ module Hobo
|
||||||
|
|
||||||
def up?
|
def up?
|
||||||
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
||||||
Ping.pingecho Hobo.config.ssh.host, 1, port
|
Net::SSH.start(Hobo.config.ssh.host, Hobo.config.ssh.username, :port => port, :password => Hobo.config.ssh.password, :timeout => 5) do |ssh|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
|
rescue Errno::ECONNREFUSED
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,17 +42,21 @@ class SshTest < Test::Unit::TestCase
|
||||||
hobo_mock_config
|
hobo_mock_config
|
||||||
end
|
end
|
||||||
|
|
||||||
should "pingecho the server" do
|
should "return true if SSH connection works" do
|
||||||
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
Net::SSH.expects(:start).yields("success")
|
||||||
Ping.expects(:pingecho).with(Hobo.config.ssh.host, 1, port).once
|
assert Hobo::SSH.up?
|
||||||
Hobo::SSH.up?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "use custom host if set" do
|
should "return false if SSH connection times out" do
|
||||||
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
Net::SSH.expects(:start)
|
||||||
Hobo.config.ssh.host = "foo"
|
assert !Hobo::SSH.up?
|
||||||
Ping.expects(:pingecho).with(Hobo.config.ssh.host, 1, port).once
|
end
|
||||||
Hobo::SSH.up?
|
|
||||||
|
should "return false if the connection is refused" do
|
||||||
|
Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
|
||||||
|
assert_nothing_raised {
|
||||||
|
assert !Hobo::SSH.up?
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -119,13 +119,13 @@ class VMTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "repeatedly ping the SSH port and return false with no response" do
|
should "repeatedly ping the SSH port and return false with no response" do
|
||||||
seq = sequence('pings')
|
seq = sequence('pings')
|
||||||
Ping.expects(:pingecho).times(Hobo.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
|
Hobo::SSH.expects(:up?).times(Hobo.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
|
||||||
Ping.expects(:pingecho).once.returns(true).in_sequence(seq)
|
Hobo::SSH.expects(:up?).once.returns(true).in_sequence(seq)
|
||||||
assert @vm.start
|
assert @vm.start
|
||||||
end
|
end
|
||||||
|
|
||||||
should "ping the max number of times then just return" do
|
should "ping the max number of times then just return" do
|
||||||
Ping.expects(:pingecho).times(Hobo.config[:ssh][:max_tries].to_i).returns(false)
|
Hobo::SSH.expects(:up?).times(Hobo.config[:ssh][:max_tries].to_i).returns(false)
|
||||||
assert !@vm.start
|
assert !@vm.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue