Added ability to upload files via SCP with the SSH class

This commit is contained in:
Mitchell Hashimoto 2010-02-09 17:08:34 -08:00
parent d48b79e8ec
commit b0574aa95c
3 changed files with 17 additions and 2 deletions

View File

@ -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'

View File

@ -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|

View File

@ -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