summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2015-09-12 12:07:10 +0300
committerSaku Ytti <saku@ytti.fi>2015-09-12 12:07:10 +0300
commit28af2b61481c2bc7af1e80d4a436ffc08ed6fd8f (patch)
treec09ca1f552e6f9b85a50a0a9d6a1df1b3cf63478
parent516059d5d1cd6ab147ffb2420044e6c27f56944a (diff)
Fix FloatDomainError when 0 nodes are found
Oxidized would throw: ---- /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/jobs.rb:36:in `to_i': NaN (FloatDomainError) from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/jobs.rb:36:in `new_count' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/jobs.rb:28:in `duration' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/jobs.rb:16:in `initialize' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/worker.rb:7:in `new' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/worker.rb:7:in `initialize' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/core.rb:21:in `new' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/core.rb:21:in `initialize' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/core.rb:12:in `new' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/core.rb:12:in `new' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/lib/oxidized/cli.rb:9:in `run' from /var/lib/gems/2.1.0/gems/oxidized-0.7.2/bin/oxidized:9:in `<top (required)>' from /usr/local/bin/oxidized:23:in `load' from /usr/local/bin/oxidized:23:in `<main>' --- When nodes.size == 0, this may happen when you have say one node in router.db which has non-existing model. Actual problem happens in jobs.rb: @duration = @durations.inject(:+).to_f / @nodes.size ... @want = ((@nodes.size * @duration) / @interval).to_i Simplified: a = 0.0 / 0 b = a.to_i
-rw-r--r--lib/oxidized/core.rb3
-rw-r--r--oxidized.gemspec2
2 files changed, 4 insertions, 1 deletions
diff --git a/lib/oxidized/core.rb b/lib/oxidized/core.rb
index b70443c..6e7a352 100644
--- a/lib/oxidized/core.rb
+++ b/lib/oxidized/core.rb
@@ -14,10 +14,13 @@ module Oxidized
end
class Core
+ class NoNodesFound < OxidizedError; end
+
def initialize args
Oxidized.mgr = Manager.new
Oxidized.Hooks = HookManager.from_config CFG
nodes = Nodes.new
+ raise NoNodesFound, 'source returns no usable nodes' if nodes.size == 0
@worker = Worker.new nodes
trap('HUP') { nodes.load }
if CFG.rest?
diff --git a/oxidized.gemspec b/oxidized.gemspec
index 4ad6e92..bc626e2 100644
--- a/oxidized.gemspec
+++ b/oxidized.gemspec
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'slop', '~> 3.5'
s.add_runtime_dependency 'net-ssh', '~> 2.8'
s.add_runtime_dependency 'rugged', '~> 0.21', '>= 0.21.4'
- s.add_development_dependency 'pry'
+ s.add_development_dependency 'pry', '~> 0'
end