summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamont-granquist <lamont@scriptkiddie.org>2014-01-07 17:15:54 -0800
committerlamont-granquist <lamont@scriptkiddie.org>2014-01-07 17:15:54 -0800
commitc17c663884a1858131bc8f166df90cc405552fc2 (patch)
tree60144642e14d3369852667ec32ec0e88982a37b6
parentbd95aa531d32c25270f0a88673eb07e66906d464 (diff)
parent71e57cb95f99260eda5b8ffb6fd577b10958fd60 (diff)
downloadohai-c17c663884a1858131bc8f166df90cc405552fc2.tar.gz
Merge pull request #261 from opscode/lcg/fix-network-listeners
Lcg/fix network listeners
-rw-r--r--lib/ohai/dsl/plugin.rb2
-rw-r--r--lib/ohai/exception.rb20
-rw-r--r--lib/ohai/plugins/network_listeners.rb2
-rw-r--r--lib/ohai/runner.rb22
-rw-r--r--spec/unit/runner_spec.rb4
5 files changed, 30 insertions, 20 deletions
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb
index 9dde1d83..177c6455 100644
--- a/lib/ohai/dsl/plugin.rb
+++ b/lib/ohai/dsl/plugin.rb
@@ -156,6 +156,8 @@ module Ohai
def safe_run
begin
self.run
+ rescue Ohai::Exceptions::Error => e
+ raise e
rescue => e
Ohai::Log.error("Plugin #{self.name} threw #{e.inspect}")
e.backtrace.each { |line| Ohai::Log.debug( line )}
diff --git a/lib/ohai/exception.rb b/lib/ohai/exception.rb
index 4e8ddfaf..b40273d2 100644
--- a/lib/ohai/exception.rb
+++ b/lib/ohai/exception.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,12 +19,14 @@
module Ohai
module Exceptions
class Exec < RuntimeError; end
- class InvalidPluginName < Exception; end
- class IllegalPluginDefinition < Exception; end
- class AttributeNotFound < Exception; end
- class ProviderNotFound < Exception; end
- class DependencyCycle < Exception; end
- class DependencyNotFound < Exception; end
- class AttributeSyntaxError < Exception; end
+ class Error < StandardError; end
+ class InvalidPlugin < Error; end
+ class InvalidPluginName < Error; end
+ class IllegalPluginDefinition < Error; end
+ class AttributeNotFound < Error; end
+ class ProviderNotFound < Error; end
+ class DependencyCycle < Error; end
+ class DependencyNotFound < Error; end
+ class AttributeSyntaxError < Error; end
end
end
diff --git a/lib/ohai/plugins/network_listeners.rb b/lib/ohai/plugins/network_listeners.rb
index fcfcf0ba..2450e008 100644
--- a/lib/ohai/plugins/network_listeners.rb
+++ b/lib/ohai/plugins/network_listeners.rb
@@ -21,7 +21,7 @@ Ohai.plugin(:NetworkListeners) do
depends "network", "counters/network"
- collect_data(:aix, :hpux, :sigar) do
+ collect_data do
require 'sigar'
flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER
diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb
index 4b654d66..60e779c3 100644
--- a/lib/ohai/runner.rb
+++ b/lib/ohai/runner.rb
@@ -34,7 +34,7 @@ module Ohai
# will be run even if they have been run before.
def run_plugin(plugin, force = false)
unless plugin.kind_of?(Ohai::DSL::Plugin)
- raise ArgumentError, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)"
+ raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)"
end
if Ohai::Config[:disabled_plugins].include?(plugin.name)
@@ -42,13 +42,19 @@ module Ohai
return false
end
- case plugin.version
- when :version7
- run_v7_plugin(plugin, force)
- when :version6
- run_v6_plugin(plugin, force)
- else
- raise ArgumentError, "Invalid plugin version #{plugin.version} for plugin #{plugin}"
+ begin
+ case plugin.version
+ when :version7
+ run_v7_plugin(plugin, force)
+ when :version6
+ run_v6_plugin(plugin, force)
+ else
+ raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}"
+ end
+ rescue Ohai::Exceptions::Error
+ raise
+ rescue Exception,Errno::ENOENT => e
+ Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
end
end
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb
index a515bdc5..b429fa8c 100644
--- a/spec/unit/runner_spec.rb
+++ b/spec/unit/runner_spec.rb
@@ -29,7 +29,7 @@ describe Ohai::Runner, "run_plugin" do
describe "when running an invalid plugin" do
it "should raise error" do
- lambda { @runner.run_plugin(double("Ohai::NotPlugin")) }.should raise_error(ArgumentError)
+ lambda { @runner.run_plugin(double("Ohai::NotPlugin")) }.should raise_error(Ohai::Exceptions::InvalidPlugin)
end
end
@@ -120,7 +120,7 @@ describe Ohai::Runner, "run_plugin" do
let(:version) { :versionBla }
it "should raise error" do
- lambda { @runner.run_plugin(plugin) }.should raise_error(ArgumentError)
+ lambda { @runner.run_plugin(plugin) }.should raise_error(Ohai::Exceptions::InvalidPlugin)
end
end