summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2013-12-16 14:54:27 -0800
committersersut <serdar@opscode.com>2013-12-17 14:09:47 -0800
commit9dbe6a2e71bc9946713e6afc02fc9884add221f6 (patch)
tree70b9fbd8a26b397e5aa2bbbd34abf55ed0e89ecd
parent9915bf8d23ccb83f2944e41c88163f49b7fb7965 (diff)
downloadohai-9dbe6a2e71bc9946713e6afc02fc9884add221f6.tar.gz
Handle AttributeNotFound exception correctly.
-rw-r--r--Gemfile2
-rw-r--r--lib/ohai/system.rb9
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/unit/system_spec.rb23
4 files changed, 32 insertions, 4 deletions
diff --git a/Gemfile b/Gemfile
index 2b17af9c..7fc756f5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -12,7 +12,7 @@ group :development do
gem "sigar", :platform => "ruby"
gem 'plist'
- # gem 'pry-debugger'
+ gem 'pry-debugger'
# gem 'pry-stack_explorer'
end
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index c1467784..8e3eca25 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -120,11 +120,16 @@ module Ohai
else
# While looking up V7 plugins we need to convert the plugin_ref to an attribute.
attribute = plugin_ref.gsub("::", "/")
- plugins = @provides_map.find_providers_for([attribute])
+ begin
+ plugins = @provides_map.find_providers_for([attribute])
+ rescue Ohai::Exceptions::AttributeNotFound
+ Ohai::Log.debug("Can not find any v7 plugin that provides #{attribute}")
+ plugins = [ ]
+ end
end
if plugins.empty?
- raise DependencyNotFound, "Can not find a plugin for dependency #{plugin_ref}"
+ raise Ohai::Exceptions::DependencyNotFound, "Can not find a plugin for dependency #{plugin_ref}"
else
plugins.each do |plugin|
begin
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 374fcab2..ef088af9 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,6 +1,6 @@
require 'rspec'
-# require 'pry-debugger'
+require 'pry-debugger'
# require 'pry-stack_explorer'
$:.unshift(File.expand_path("../..", __FILE__))
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index c07ed836..1d6d8b87 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -390,5 +390,28 @@ EOF
end
end
+ when_plugins_directory "a v6 plugin that requires non-existing v7 plugin" do
+ with_plugin("message.rb", <<EOF)
+provides 'message'
+
+require_plugin 'v7message'
+
+message v7message
+EOF
+
+ before do
+ @ohai = Ohai::System.new
+ @original_config = Ohai::Config[:plugin_path]
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
+ end
+
+ after do
+ Ohai::Config[:plugin_path] = @original_config
+ end
+
+ it "should raise DependencyNotFound" do
+ lambda { @ohai.all_plugins }.should raise_error(Ohai::Exceptions::DependencyNotFound)
+ end
+ end
end
end