From 28af2b61481c2bc7af1e80d4a436ffc08ed6fd8f Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sat, 12 Sep 2015 12:07:10 +0300 Subject: 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 `' from /usr/local/bin/oxidized:23:in `load' from /usr/local/bin/oxidized:23:in `
' --- 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 --- lib/oxidized/core.rb | 3 +++ oxidized.gemspec | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1