diff --git a/lib/hobo/config.rb b/lib/hobo/config.rb index 0d8396374..0614866f5 100644 --- a/lib/hobo/config.rb +++ b/lib/hobo/config.rb @@ -38,8 +38,8 @@ module Hobo end class SSHConfig < Base - attr_accessor :uname - attr_accessor :pass + attr_accessor :username + attr_accessor :password attr_accessor :host attr_accessor :forwarded_port_key attr_accessor :max_tries diff --git a/lib/hobo/ssh.rb b/lib/hobo/ssh.rb index b07ae7fc0..5fb2a58e5 100644 --- a/lib/hobo/ssh.rb +++ b/lib/hobo/ssh.rb @@ -5,26 +5,26 @@ module Hobo class << self def connect(opts={}) options = {} - [:host, :pass, :uname].each do |param| + [:host, :password, :username].each do |param| options[param] = opts[param] || Hobo.config.ssh.send(param) end # The port is special options[:port] = opts[:port] || Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport] - Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip + Kernel.exec "#{SCRIPT} #{options[:username]} #{options[:password]} #{options[:host]} #{options[:port]}".strip end def execute port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport] - Net::SSH.start("localhost", Hobo.config[:ssh][:uname], :port => port, :password => Hobo.config[:ssh][:pass]) do |ssh| + Net::SSH.start(Hobo.config.ssh.host, Hobo.config[:ssh][:username], :port => port, :password => Hobo.config[:ssh][:password]) do |ssh| yield ssh end end def up? port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport] - Ping.pingecho "localhost", 1, port + Ping.pingecho Hobo.config.ssh.host, 1, port end end end diff --git a/test/hobo/ssh_test.rb b/test/hobo/ssh_test.rb index 5e128137b..e0ac59eeb 100644 --- a/test/hobo/ssh_test.rb +++ b/test/hobo/ssh_test.rb @@ -13,28 +13,45 @@ class SshTest < Test::Unit::TestCase test "should call exec with defaults when no options are supplied" do ssh = Hobo.config.ssh port = Hobo.config.vm.forwarded_ports[ssh.forwarded_port_key][:hostport] - Kernel.expects(:exec).with("#{@script} #{ssh[:uname]} #{ssh[:pass]} #{ssh[:host]} #{port}") + Kernel.expects(:exec).with("#{@script} #{ssh[:username]} #{ssh[:password]} #{ssh[:host]} #{port}") Hobo::SSH.connect end test "should call exec with supplied params" do - args = {:uname => 'bar', :pass => 'baz', :host => 'bak', :port => 'bag'} - Kernel.expects(:exec).with("#{@script} #{args[:uname]} #{args[:pass]} #{args[:host]} #{args[:port]}") + args = {:username => 'bar', :password => 'baz', :host => 'bak', :port => 'bag'} + Kernel.expects(:exec).with("#{@script} #{args[:username]} #{args[:password]} #{args[:host]} #{args[:port]}") Hobo::SSH.connect(args) end end context "net-ssh interaction" do should "call net::ssh.start with the proper names" do - Net::SSH.expects(:start).with("localhost", Hobo.config[:ssh][:uname], anything).once + Net::SSH.expects(:start).with(Hobo.config.ssh.host, Hobo.config[:ssh][:username], anything).once + Hobo::SSH.execute + end + + should "use custom host if set" do + Hobo.config.ssh.host = "foo" + Net::SSH.expects(:start).with(Hobo.config.ssh.host, Hobo.config[:ssh][:username], anything).once Hobo::SSH.execute end end context "checking if host is up" do + setup do + hobo_mock_config + end + should "pingecho the server" do port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport] - Ping.expects(:pingecho).with("localhost", 1, port).once + Ping.expects(:pingecho).with(Hobo.config.ssh.host, 1, port).once + Hobo::SSH.up? + end + + should "use custom host if set" do + port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport] + Hobo.config.ssh.host = "foo" + Ping.expects(:pingecho).with(Hobo.config.ssh.host, 1, port).once Hobo::SSH.up? end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 626f96f46..2f234d202 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -34,8 +34,8 @@ class Test::Unit::TestCase Hobo::Config.run do |config| config.dotfile_name = ".hobo" - config.ssh.uname = "foo" - config.ssh.pass = "bar" + config.ssh.username = "foo" + config.ssh.password = "bar" config.ssh.host = "baz" config.ssh.forwarded_port_key = "ssh" config.ssh.max_tries = 10