broke up ssh connection to a target and options, so we can pass options through to rsync (no rsync yet)

This commit is contained in:
Nick Gauthier 2010-02-09 09:56:06 -05:00
parent c743175875
commit 5b53276af6
4 changed files with 15 additions and 13 deletions

View File

@ -11,7 +11,6 @@ begin
gem.homepage = "http://github.com/ngauthier/hydra" gem.homepage = "http://github.com/ngauthier/hydra"
gem.authors = ["Nick Gauthier"] gem.authors = ["Nick Gauthier"]
gem.add_development_dependency "shoulda", "= 2.10.3" gem.add_development_dependency "shoulda", "= 2.10.3"
gem.add_dependency "net-ssh", "= 2.0.19"
end end
Jeweler::GemcutterTasks.new Jeweler::GemcutterTasks.new
rescue LoadError rescue LoadError

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Nick Gauthier"] s.authors = ["Nick Gauthier"]
s.date = %q{2010-02-06} s.date = %q{2010-02-09}
s.description = %q{Spread your tests over multiple machines to test your code faster.} s.description = %q{Spread your tests over multiple machines to test your code faster.}
s.email = %q{nick@smartlogicsolutions.com} s.email = %q{nick@smartlogicsolutions.com}
s.extra_rdoc_files = [ s.extra_rdoc_files = [
@ -81,14 +81,11 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<shoulda>, ["= 2.10.3"]) s.add_development_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_runtime_dependency(%q<net-ssh>, ["= 2.0.19"])
else else
s.add_dependency(%q<shoulda>, ["= 2.10.3"]) s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<net-ssh>, ["= 2.0.19"])
end end
else else
s.add_dependency(%q<shoulda>, ["= 2.10.3"]) s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<net-ssh>, ["= 2.0.19"])
end end
end end

View File

@ -94,14 +94,17 @@ module Hydra #:nodoc:
def boot_ssh_worker(worker) def boot_ssh_worker(worker)
runners = worker.fetch('runners') { raise "You must specify the number of runners" } runners = worker.fetch('runners') { raise "You must specify the number of runners" }
connect = worker.fetch('connect') { raise "You must specify SSH connection options" } connect = worker.fetch('connect') { raise "You must specify an SSH connection target" }
ssh_opts = worker.fetch('ssh_opts') { "" }
directory = worker.fetch('directory') { raise "You must specify a remote directory" } directory = worker.fetch('directory') { raise "You must specify a remote directory" }
command = worker.fetch('command') { command = worker.fetch('command') {
"ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Worker.new(:io => Hydra::Stdio.new, :runners => #{runners}, :verbose => #{@verbose});\"" "ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Worker.new(:io => Hydra::Stdio.new, :runners => #{runners}, :verbose => #{@verbose});\""
} }
trace "Synchronizing with #{connect} [NOT REALLY]"
trace "Booting SSH worker" trace "Booting SSH worker"
ssh = Hydra::SSH.new(connect, directory, command) ssh = Hydra::SSH.new("#{ssh_opts} #{connect}", directory, command)
return { :io => ssh, :idle => false, :type => :ssh } return { :io => ssh, :idle => false, :type => :ssh }
end end

View File

@ -17,18 +17,21 @@ module Hydra #:nodoc:
include Open3 include Open3
include Hydra::MessagingIO include Hydra::MessagingIO
# Initialize new SSH connection. The single parameters is passed # Initialize new SSH connection.
# directly to ssh for starting a connection. So you can do: # The first parameter is passed directly to ssh for starting a connection.
# Hydra::SSH.new('localhost') # The second parameter is the directory to CD into once connected.
# Hydra::SSH.new('user@server.com') # The third parameter is the command to run
# Hydra::SSH.new('-p 3022 user@server.com') # So you can do:
# etc.. # Hydra::SSH.new('-p 3022 user@server.com', '/home/user/Desktop', 'ls -l')
# To connect to server.com as user on port 3022, then CD to their desktop, then
# list all the files.
def initialize(connection_options, directory, command) def initialize(connection_options, directory, command)
@writer, @reader, @error = popen3("ssh -tt #{connection_options}") @writer, @reader, @error = popen3("ssh -tt #{connection_options}")
@writer.write("cd #{directory}\n") @writer.write("cd #{directory}\n")
@writer.write(command+"\n") @writer.write(command+"\n")
end end
# Close the SSH connection
def close def close
@writer.write "exit\n" @writer.write "exit\n"
super super