diff --git a/lib/hobo.rb b/lib/hobo.rb index 603affa4d..0a12dadad 100644 --- a/lib/hobo.rb +++ b/lib/hobo.rb @@ -3,10 +3,12 @@ $:.unshift(libdir) PROJECT_ROOT = File.join(libdir, '..') require 'ftools' +require 'json' require 'pathname' require 'logger' require 'virtualbox' require 'net/ssh' +require 'net/scp' require 'ping' require 'hobo/busy' require 'hobo/util' diff --git a/lib/hobo/ssh.rb b/lib/hobo/ssh.rb index e01482775..d252a8262 100644 --- a/lib/hobo/ssh.rb +++ b/lib/hobo/ssh.rb @@ -22,6 +22,12 @@ module Hobo end end + def upload!(from, to) + Net::SCP.upload!(Hobo.config.ssh.host, Hobo.config.ssh.username, + from, to, + :password => Hobo.config.ssh.password) + end + def up? port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport] Net::SSH.start(Hobo.config.ssh.host, Hobo.config.ssh.username, :port => port, :password => Hobo.config.ssh.password, :timeout => 5) do |ssh| diff --git a/test/hobo/ssh_test.rb b/test/hobo/ssh_test.rb index cf4dbc149..c73c38714 100644 --- a/test/hobo/ssh_test.rb +++ b/test/hobo/ssh_test.rb @@ -26,17 +26,24 @@ class SshTest < Test::Unit::TestCase context "net-ssh interaction" do should "call net::ssh.start with the proper names" do - Net::SSH.expects(:start).with(Hobo.config.ssh.host, Hobo.config[:ssh][:username], 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 + Net::SSH.expects(:start).with(Hobo.config.ssh.host, Hobo.config.ssh.username, anything).once Hobo::SSH.execute end end + context "SCPing files to the remote host" do + should "use the SSH information to SCP files" do + Net::SCP.expects(:upload!).with(Hobo.config.ssh.host, Hobo.config.ssh.username, "foo", "bar", :password => Hobo.config.ssh.password) + Hobo::SSH.upload!("foo", "bar") + end + end + context "checking if host is up" do setup do hobo_mock_config