Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Coherent exception handling

  • Loading branch information...
commit ba3886a8139f744d0d0d9de2cc8e27ae75c88031 1 parent 9d43610
@kschiess authored
View
3  lib/ndo/host.rb
@@ -1,6 +1,9 @@
require 'stringio'
require 'open4'
+# Runs a command via ssh on a host. This is initially stolen from vlad (the
+# deployer), then rewritten and modified.
+#
class Ndo::Host
attr_reader :name
def initialize(hostname)
View
2  lib/ndo/multi_command.rb
@@ -34,7 +34,7 @@ def run_for_host(host)
begin
Ndo::Host.new(host).run(@command).first
rescue => b
- "Failure: #{b}"
+ b
end
end
end
View
16 lib/ndo/results.rb
@@ -5,17 +5,19 @@ def initialize
end
def [](host)
- @map[host].value
+ begin
+ val = @map[host].value
+ # Swallow exception returns.
+ val.instance_of?(String) ? val : nil
+ rescue Procrastinate::ChildDeath
+ nil
+ end
end
include Enumerable
def each
- @map.each { |host, future|
- begin
- yield host, future.value
- rescue Procrastinate::ChildDeath
-
- end }
+ @map.each { |host, _|
+ yield host, self[host] }
end
def store(host, future)
View
15 spec/ndo/multi_command_spec.rb
@@ -8,11 +8,11 @@
end
describe Ndo::MultiCommand, 'integration' do
- let(:multi_cmd) { Ndo::MultiCommand.new('cat /etc/hostname', spec_hosts) }
- context "result" do
+ context "when the command suceeds (spec_hosts)" do
+ let(:multi_cmd) { Ndo::MultiCommand.new('cat /etc/hostname', spec_hosts) }
let(:result) { multi_cmd.run }
-
+
spec_hosts.each do |host|
context "[#{host.inspect}]" do
subject { result[host] }
@@ -21,4 +21,13 @@
end
end
end
+ context "when the command fails" do
+ let(:multi_cmd) { Ndo::MultiCommand.new('failing command', %w(unknown)) }
+
+ context "result['unknown']" do
+ subject { multi_cmd.run['unknown'] }
+
+ it { should be_nil }
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.