From 89c16e11c4636f46476a18d7a4671d5b66234490 Mon Sep 17 00:00:00 2001 From: Rob Aldred Date: Fri, 14 May 2010 14:16:50 +0100 Subject: [PATCH 1/2] use erb to parse the config file, useful for putting dynamic values also mkdir -p the directory the ssh class cd's to, to avoid errors if the dir is not there. --- lib/hydra/master.rb | 16 +++++++++++++++- lib/hydra/ssh.rb | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/hydra/master.rb b/lib/hydra/master.rb index 76891b2..e0f99d8 100644 --- a/lib/hydra/master.rb +++ b/lib/hydra/master.rb @@ -1,6 +1,7 @@ require 'hydra/hash' require 'open3' require 'tmpdir' +require 'erb' require 'yaml' module Hydra #:nodoc: # Hydra class responsible for delegate work down to workers. @@ -31,7 +32,20 @@ module Hydra #:nodoc: opts.stringify_keys! config_file = opts.delete('config') { nil } if config_file - opts.merge!(YAML.load_file(config_file).stringify_keys!) + + begin + config_erb = ERB.new(IO.read(config_file)).result(binding) + rescue Exception => e + raise(YmlLoadError,"config file was found, but could not be parsed with ERB.\n#{$!.inspect}") + end + + begin + config_yml = YAML::load(config_erb) + rescue StandardError => e + raise(YmlLoadError,"config file was found, but could not be parsed.\n#{$!.inspect}") + end + + opts.merge!(config_yml.stringify_keys!) end @files = Array(opts.fetch('files') { nil }) raise "No files, nothing to do" if @files.empty? diff --git a/lib/hydra/ssh.rb b/lib/hydra/ssh.rb index 002f0da..01f3b91 100644 --- a/lib/hydra/ssh.rb +++ b/lib/hydra/ssh.rb @@ -27,6 +27,7 @@ module Hydra #:nodoc: # list all the files. def initialize(connection_options, directory, command) @writer, @reader, @error = popen3("ssh -tt #{connection_options}") + @writer.write("mkdir -p #{directory}\n") @writer.write("cd #{directory}\n") @writer.write(command+"\n") end From c8e08fabf6fbeb747f33415e478cf6058640a366 Mon Sep 17 00:00:00 2001 From: Rob Aldred Date: Fri, 14 May 2010 14:23:29 +0100 Subject: [PATCH 2/2] added YmlLoadError class which is raised when yml file cannot be parsed --- lib/hydra/master.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/hydra/master.rb b/lib/hydra/master.rb index e0f99d8..379f80f 100644 --- a/lib/hydra/master.rb +++ b/lib/hydra/master.rb @@ -3,10 +3,13 @@ require 'open3' require 'tmpdir' require 'erb' require 'yaml' + module Hydra #:nodoc: # Hydra class responsible for delegate work down to workers. # # The Master is run once for any given testing session. + class YmlLoadError < StandardError; end + class Master include Hydra::Messages::Master include Open3