Added ability to upload files via SCP with the SSH class
This commit is contained in:
parent
d48b79e8ec
commit
b0574aa95c
|
@ -3,10 +3,12 @@ $:.unshift(libdir)
|
||||||
PROJECT_ROOT = File.join(libdir, '..')
|
PROJECT_ROOT = File.join(libdir, '..')
|
||||||
|
|
||||||
require 'ftools'
|
require 'ftools'
|
||||||
|
require 'json'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
require 'virtualbox'
|
require 'virtualbox'
|
||||||
require 'net/ssh'
|
require 'net/ssh'
|
||||||
|
require 'net/scp'
|
||||||
require 'ping'
|
require 'ping'
|
||||||
require 'hobo/busy'
|
require 'hobo/busy'
|
||||||
require 'hobo/util'
|
require 'hobo/util'
|
||||||
|
|
|
@ -22,6 +22,12 @@ module Hobo
|
||||||
end
|
end
|
||||||
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?
|
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]
|
||||||
Net::SSH.start(Hobo.config.ssh.host, Hobo.config.ssh.username, :port => port, :password => Hobo.config.ssh.password, :timeout => 5) do |ssh|
|
Net::SSH.start(Hobo.config.ssh.host, Hobo.config.ssh.username, :port => port, :password => Hobo.config.ssh.password, :timeout => 5) do |ssh|
|
||||||
|
|
|
@ -26,17 +26,24 @@ class SshTest < Test::Unit::TestCase
|
||||||
|
|
||||||
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(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
|
Hobo::SSH.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
should "use custom host if set" do
|
should "use custom host if set" do
|
||||||
Hobo.config.ssh.host = "foo"
|
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
|
Hobo::SSH.execute
|
||||||
end
|
end
|
||||||
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
|
context "checking if host is up" do
|
||||||
setup do
|
setup do
|
||||||
hobo_mock_config
|
hobo_mock_config
|
||||||
|
|
Loading…
Reference in New Issue