diff options
author | Claire McQuin <claire@opscode.com> | 2013-08-20 14:35:32 -0700 |
---|---|---|
committer | Claire McQuin <claire@opscode.com> | 2013-08-20 14:35:32 -0700 |
commit | 8a95352b53e3806166da79158b94b90e21f787c2 (patch) | |
tree | 225334ecc0a5f82b6d382209486746fa9ae7b69a | |
parent | 591bb31f0395d4085b8b6574fcb7ec75592aaca3 (diff) | |
download | ohai-8a95352b53e3806166da79158b94b90e21f787c2.tar.gz |
fix error/exception handling for loading plugins
-rw-r--r-- | lib/ohai/dsl/plugin.rb | 9 | ||||
-rw-r--r-- | lib/ohai/loader.rb | 24 | ||||
-rw-r--r-- | lib/ohai/system.rb | 3 | ||||
-rw-r--r-- | spec/ohai/dsl/plugin_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/fail_spec.rb | 10 |
5 files changed, 24 insertions, 24 deletions
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb index b76bbb88..12ba11b5 100644 --- a/lib/ohai/dsl/plugin.rb +++ b/lib/ohai/dsl/plugin.rb @@ -106,10 +106,13 @@ module Ohai #===================================================== # plugin DSL methods #===================================================== - # @note: v6 plugins only def require_plugin(*args) - # @todo: log deprecation message - @controller.require_plugin(*args) + if self.class.version == :version6 + Ohai::Log.warn("[DEPRECATION] \'require_plugin\' is deprecated. Please use \'depends\' instead.") + @controller.require_plugin(*args) + else + Ohai::Log.warn("[UNSUPPORTED OPERATION] \'require_plugin\' is no longer supported. Please use \'depends\' instead.\nIgnoring plugin(s) #{args.join(", ")}") + end end def hints diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index 2007ed57..6e31d2fd 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -35,11 +35,9 @@ module Ohai contents = "" begin - contents = IO.read(plugin_path) - rescue SystemExit, Interrupt - raise + contents << IO.read(plugin_path) rescue IOError, Errno::ENOENT - Ohai::Log.debug("Unable to open or read #{plugin_path}") + Ohai::Log.warn("Unable to open or read plugin at #{plugin_path}") return plugin end @@ -49,22 +47,22 @@ module Ohai rescue SystemExit, Interrupt raise rescue NoMethodError => e - Ohai::Log.debug("Undefined method \'#{e.name.to_s}\' \"#{e.args.join(", ")}\"") + Ohai::Log.warn("[UNSUPPORTED OPERATION] Plugin at #{plugin_path} used unsupported operation \'#{e.name.to_s}\'") rescue Exception, Errno::ENOENT => e - Ohai::Log.debug("Plugin at #{plugin_path} threw exception #{e.inspect} #{e.backtrace.join("\n")}") + Ohai::Log.warn("Plugin at #{plugin_path} threw exception #{e.inspect} #{e.backtrace.join("\n")}") end - collect_provides(plugin) unless plugin.nil? + return plugin if plugin.nil? + collect_provides(plugin) else plugin = Ohai.v6plugin do collect_contents contents end + if plugin.nil? + Ohai::Log.warn("Unable to load plugin at #{plugin_path}") + return plugin + end end - if plugin.nil? - Ohai::Log.debug("Unable to load plugin at #{plugin_path}") - else - @v6_dependency_solver[plugin_path] = plugin - end - + @v6_dependency_solver[plugin_path] = plugin plugin end diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index 31f89146..a1c8a15d 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -59,8 +59,7 @@ module Ohai md = file_regex.match(file) if md plugin_path = md[0] - plugin_name = md[1] - loader.load_plugin(plugin_path, plugin_name) unless @v6_dependency_solver.has_key?(plugin_path) + loader.load_plugin(plugin_path) unless @v6_dependency_solver.has_key?(plugin_path) end end end diff --git a/spec/ohai/dsl/plugin_spec.rb b/spec/ohai/dsl/plugin_spec.rb index d83a8aa7..139d2c30 100644 --- a/spec/ohai/dsl/plugin_spec.rb +++ b/spec/ohai/dsl/plugin_spec.rb @@ -25,7 +25,6 @@ shared_examples "Ohai::DSL::Plugin" do before(:each) do @ohai = ohai @plugin = instance.new(@ohai) - @plugin.stub(:attribute_declared?).and_return(true) end context "when accessing data via method_missing" do @@ -67,7 +66,6 @@ shared_examples "Ohai::DSL::Plugin" do context "when getting attributes" do before(:each) do - @plugin.set_attribute(:tea, "is soothing") end diff --git a/spec/unit/plugins/fail_spec.rb b/spec/unit/plugins/fail_spec.rb index 1f3fa941..33f0e5d5 100644 --- a/spec/unit/plugins/fail_spec.rb +++ b/spec/unit/plugins/fail_spec.rb @@ -64,7 +64,7 @@ shared_examples "a v7 loading failure" do end it "should write to Ohai::Log" do - Ohai::Log.should_receive(:debug).twice + Ohai::Log.should_receive(:warn).once @loader.load_plugin("#{tmp}/plugins/fail.rb") end end @@ -112,7 +112,7 @@ shared_examples "a v7 loading success" do end it "should not write to Ohai::Log" do - Ohai::Log.should_not_receive(:debug) + Ohai::Log.should_not_receive(:warn) @loader.load_plugin("#{tmp}/plugins/fail.rb") end end @@ -155,11 +155,12 @@ shared_examples "a v7 run failure" do end it "should write to Ohai::Log" do - Ohai::Log.should_receive(:debug).once + Ohai::Log.should_receive(:warn).once @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run end end +=begin shared_examples "a v6 run failure" do before(:all) do begin @@ -198,10 +199,11 @@ shared_examples "a v6 run failure" do end it "should write to Ohai::Log" do - Ohai::Log.should_receive(:debug).twice + Ohai::Log.should_receive(:warn).once @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run end end +=end describe "when using DSL commands outside Ohai.plugin block" do failstr1 = "provides \"fail\"\nOhai.plugin do\nend\n" |