midway through making ssh workers
This commit is contained in:
parent
7a39fe8855
commit
727bdcf1b7
5
TODO
5
TODO
|
@ -8,9 +8,12 @@ YML configuration
|
||||||
hydra:
|
hydra:
|
||||||
workers:
|
workers:
|
||||||
- type: local
|
- type: local
|
||||||
runners: 1
|
runners: 4
|
||||||
- type: ssh
|
- type: ssh
|
||||||
connect: localhost
|
connect: localhost
|
||||||
|
directory: /path/to/suite
|
||||||
|
[command: rake hydra:worker RUNNERS=1]
|
||||||
|
runners: 4
|
||||||
|
|
||||||
v0.6.0
|
v0.6.0
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'hydra/pipe'
|
require 'hydra/pipe'
|
||||||
require 'hydra/ssh'
|
require 'hydra/ssh'
|
||||||
|
require 'hydra/stdio'
|
||||||
require 'hydra/message'
|
require 'hydra/message'
|
||||||
require 'hydra/runner'
|
require 'hydra/runner'
|
||||||
require 'hydra/worker'
|
require 'hydra/worker'
|
||||||
|
|
|
@ -18,11 +18,14 @@ module Hydra #:nodoc:
|
||||||
@files = opts.fetch(:files) { [] }
|
@files = opts.fetch(:files) { [] }
|
||||||
@workers = []
|
@workers = []
|
||||||
@listeners = []
|
@listeners = []
|
||||||
|
@verbose = opts.fetch(:verbose) { false }
|
||||||
# default is one worker that is configured to use a pipe with one runner
|
# default is one worker that is configured to use a pipe with one runner
|
||||||
worker_cfg = opts.fetch(:workers) {
|
worker_cfg = opts.fetch(:workers) {
|
||||||
[ { :type => :local, :runners => 1} ]
|
[ { :type => :local, :runners => 1} ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$stdout.write "MASTER| Initialized\n" if @verbose
|
||||||
|
|
||||||
boot_workers worker_cfg
|
boot_workers worker_cfg
|
||||||
process_messages
|
process_messages
|
||||||
end
|
end
|
||||||
|
@ -44,26 +47,41 @@ module Hydra #:nodoc:
|
||||||
private
|
private
|
||||||
|
|
||||||
def boot_workers(workers)
|
def boot_workers(workers)
|
||||||
|
$stdout.write "MASTER| Booting workers\n" if @verbose
|
||||||
workers.select{|worker| worker[:type] == :local}.each do |worker|
|
workers.select{|worker| worker[:type] == :local}.each do |worker|
|
||||||
|
$stdout.write "MASTER| Booting local worker\n" if @verbose
|
||||||
boot_local_worker(worker)
|
boot_local_worker(worker)
|
||||||
end
|
end
|
||||||
workers.select{|worker| worker[:type] == :ssh}.each do |worker|
|
workers.select{|worker| worker[:type] == :ssh}.each do |worker|
|
||||||
|
$stdout.write "MASTER| Booting ssh worker\n" if @verbose
|
||||||
boot_ssh_worker(worker)
|
boot_ssh_worker(worker)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot_local_worker(worker)
|
def boot_local_worker(worker)
|
||||||
|
runners = worker.fetch(:runners) { raise "You must specify the number of runners" }
|
||||||
pipe = Hydra::Pipe.new
|
pipe = Hydra::Pipe.new
|
||||||
child = Process.fork do
|
child = Process.fork do
|
||||||
pipe.identify_as_child
|
pipe.identify_as_child
|
||||||
Hydra::Worker.new(:io => pipe, :runners => worker[:runners])
|
Hydra::Worker.new(:io => pipe, :runners => runners)
|
||||||
end
|
end
|
||||||
pipe.identify_as_parent
|
pipe.identify_as_parent
|
||||||
@workers << { :pid => child, :io => pipe, :idle => false }
|
@workers << { :pid => child, :io => pipe, :idle => false }
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot_ssh_worker(worker)
|
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
|
end
|
||||||
|
|
||||||
def process_messages
|
def process_messages
|
||||||
|
|
|
@ -12,6 +12,9 @@ module Hydra #:nodoc:
|
||||||
message = @reader.gets
|
message = @reader.gets
|
||||||
return nil unless message
|
return nil unless message
|
||||||
return Message.build(eval(message.chomp))
|
return Message.build(eval(message.chomp))
|
||||||
|
rescue SyntaxError => ex
|
||||||
|
$stderr.write "Not a message: [#{message.inspect}]\n"
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write a Message to the output IO object. It will automatically
|
# Write a Message to the output IO object. It will automatically
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'test/unit'
|
||||||
module Hydra #:nodoc:
|
module Hydra #:nodoc:
|
||||||
# Hydra class responsible for running test files.
|
# Hydra class responsible for running test files.
|
||||||
#
|
#
|
||||||
|
|
|
@ -58,5 +58,21 @@ class MasterTest < Test::Unit::TestCase
|
||||||
finish = Time.now
|
finish = Time.now
|
||||||
assert (finish-start) < 15, "took #{finish-start} seconds"
|
assert (finish-start) < 15, "took #{finish-start} seconds"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue