midway through making ssh workers

This commit is contained in:
Nick Gauthier 2010-01-29 17:21:48 -05:00
parent 7a39fe8855
commit 727bdcf1b7
6 changed files with 45 additions and 3 deletions

5
TODO
View File

@ -8,9 +8,12 @@ YML configuration
hydra:
workers:
- type: local
runners: 1
runners: 4
- type: ssh
connect: localhost
directory: /path/to/suite
[command: rake hydra:worker RUNNERS=1]
runners: 4
v0.6.0

View File

@ -1,5 +1,6 @@
require 'hydra/pipe'
require 'hydra/ssh'
require 'hydra/stdio'
require 'hydra/message'
require 'hydra/runner'
require 'hydra/worker'

View File

@ -18,11 +18,14 @@ module Hydra #:nodoc:
@files = opts.fetch(:files) { [] }
@workers = []
@listeners = []
@verbose = opts.fetch(:verbose) { false }
# default is one worker that is configured to use a pipe with one runner
worker_cfg = opts.fetch(:workers) {
[ { :type => :local, :runners => 1} ]
}
$stdout.write "MASTER| Initialized\n" if @verbose
boot_workers worker_cfg
process_messages
end
@ -44,26 +47,41 @@ module Hydra #:nodoc:
private
def boot_workers(workers)
$stdout.write "MASTER| Booting workers\n" if @verbose
workers.select{|worker| worker[:type] == :local}.each do |worker|
$stdout.write "MASTER| Booting local worker\n" if @verbose
boot_local_worker(worker)
end
workers.select{|worker| worker[:type] == :ssh}.each do |worker|
$stdout.write "MASTER| Booting ssh worker\n" if @verbose
boot_ssh_worker(worker)
end
end
def boot_local_worker(worker)
runners = worker.fetch(:runners) { raise "You must specify the number of runners" }
pipe = Hydra::Pipe.new
child = Process.fork do
pipe.identify_as_child
Hydra::Worker.new(:io => pipe, :runners => worker[:runners])
Hydra::Worker.new(:io => pipe, :runners => runners)
end
pipe.identify_as_parent
@workers << { :pid => child, :io => pipe, :idle => false }
end
def boot_ssh_worker(worker)
raise "Don't know how to boot SSH workers yet"
runners = worker.fetch(:runners) { raise "You must specify the number of runners" }
connect = worker.fetch(:connect) { raise "You must specify SSH connection options" }
directory = worker.fetch(:directory) { raise "You must specify a remote directory" }
command = worker.fetch(:command) {
"ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Worker.new(:io => Hydra::Stdio.new, :runners => #{runners});\""
}
ssh = nil
child = Process.fork do
ssh = Hydra::SSH.new(connect, directory, command)
end
@workers << { :pid => child, :io => ssh, :idle => false }
end
def process_messages

View File

@ -12,6 +12,9 @@ module Hydra #:nodoc:
message = @reader.gets
return nil unless message
return Message.build(eval(message.chomp))
rescue SyntaxError => ex
$stderr.write "Not a message: [#{message.inspect}]\n"
return nil
end
# Write a Message to the output IO object. It will automatically

View File

@ -1,3 +1,4 @@
require 'test/unit'
module Hydra #:nodoc:
# Hydra class responsible for running test files.
#

View File

@ -58,5 +58,21 @@ class MasterTest < Test::Unit::TestCase
finish = Time.now
assert (finish-start) < 15, "took #{finish-start} seconds"
end
should "run a test via ssh" do
Hydra::Master.new(
:files => [test_file],
:workers => [{
:type => :ssh,
:connect => 'localhost',
:directory => File.expand_path(File.join(File.dirname(__FILE__), '..')),
:runners => 1
}],
:verbose => true
)
assert File.exists?(target_file)
assert_equal "HYDRA", File.read(target_file)
end
end
end