Rename config values for SSH to more human terms
This commit is contained in:
parent
7971d656fe
commit
21b1aa50f7
|
@ -38,8 +38,8 @@ module Hobo
|
||||||
end
|
end
|
||||||
|
|
||||||
class SSHConfig < Base
|
class SSHConfig < Base
|
||||||
attr_accessor :uname
|
attr_accessor :username
|
||||||
attr_accessor :pass
|
attr_accessor :password
|
||||||
attr_accessor :host
|
attr_accessor :host
|
||||||
attr_accessor :forwarded_port_key
|
attr_accessor :forwarded_port_key
|
||||||
attr_accessor :max_tries
|
attr_accessor :max_tries
|
||||||
|
|
|
@ -5,26 +5,26 @@ module Hobo
|
||||||
class << self
|
class << self
|
||||||
def connect(opts={})
|
def connect(opts={})
|
||||||
options = {}
|
options = {}
|
||||||
[:host, :pass, :uname].each do |param|
|
[:host, :password, :username].each do |param|
|
||||||
options[param] = opts[param] || Hobo.config.ssh.send(param)
|
options[param] = opts[param] || Hobo.config.ssh.send(param)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The port is special
|
# The port is special
|
||||||
options[:port] = opts[:port] || Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
|
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
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
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]
|
||||||
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
|
yield ssh
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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 "localhost", 1, port
|
Ping.pingecho Hobo.config.ssh.host, 1, port
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,28 +13,45 @@ class SshTest < Test::Unit::TestCase
|
||||||
test "should call exec with defaults when no options are supplied" do
|
test "should call exec with defaults when no options are supplied" do
|
||||||
ssh = Hobo.config.ssh
|
ssh = Hobo.config.ssh
|
||||||
port = Hobo.config.vm.forwarded_ports[ssh.forwarded_port_key][:hostport]
|
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
|
Hobo::SSH.connect
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should call exec with supplied params" do
|
test "should call exec with supplied params" do
|
||||||
args = {:uname => 'bar', :pass => 'baz', :host => 'bak', :port => 'bag'}
|
args = {:username => 'bar', :password => 'baz', :host => 'bak', :port => 'bag'}
|
||||||
Kernel.expects(:exec).with("#{@script} #{args[:uname]} #{args[:pass]} #{args[:host]} #{args[:port]}")
|
Kernel.expects(:exec).with("#{@script} #{args[:username]} #{args[:password]} #{args[:host]} #{args[:port]}")
|
||||||
Hobo::SSH.connect(args)
|
Hobo::SSH.connect(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "net-ssh interaction" do
|
context "net-ssh interaction" do
|
||||||
should "call net::ssh.start with the proper names" 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
|
Hobo::SSH.execute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "checking if host is up" do
|
context "checking if host is up" do
|
||||||
|
setup do
|
||||||
|
hobo_mock_config
|
||||||
|
end
|
||||||
|
|
||||||
should "pingecho the server" do
|
should "pingecho the server" do
|
||||||
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.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?
|
Hobo::SSH.up?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,8 +34,8 @@ class Test::Unit::TestCase
|
||||||
Hobo::Config.run do |config|
|
Hobo::Config.run do |config|
|
||||||
config.dotfile_name = ".hobo"
|
config.dotfile_name = ".hobo"
|
||||||
|
|
||||||
config.ssh.uname = "foo"
|
config.ssh.username = "foo"
|
||||||
config.ssh.pass = "bar"
|
config.ssh.password = "bar"
|
||||||
config.ssh.host = "baz"
|
config.ssh.host = "baz"
|
||||||
config.ssh.forwarded_port_key = "ssh"
|
config.ssh.forwarded_port_key = "ssh"
|
||||||
config.ssh.max_tries = 10
|
config.ssh.max_tries = 10
|
||||||
|
|
Loading…
Reference in New Issue