diff options
author | danielsdeleo <dan@getchef.com> | 2014-04-09 11:34:06 -0700 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2014-04-09 11:34:58 -0700 |
commit | 594264998dd3fd9fd36164c2b26a907c6a193804 (patch) | |
tree | d997df45f5e410a061e7d7b182aec8ac9a9125fb | |
parent | 189aace71e4af28ca2a5a2e93dbb0552c3760914 (diff) | |
download | ohai-594264998dd3fd9fd36164c2b26a907c6a193804.tar.gz |
Skip v7 plugins when refreshing a v6 plugin
Fixes OHAI-562
-rw-r--r-- | lib/ohai/system.rb | 11 | ||||
-rw-r--r-- | spec/unit/system_spec.rb | 23 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index f844504c..6d941b45 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -83,6 +83,13 @@ module Ohai @runner.run_plugin(v6plugin) end + # Users who are migrating from ohai 6 may give one or more Ohai 6 plugin + # names as the +attribute_filter+. In this case we return early because + # the v7 plugin provides map will not have an entry for this plugin. + if attribute_filter and Array(attribute_filter).all? {|filter_item| have_v6_plugin?(filter_item) } + return true + end + # Then run all the version 7 plugins begin @provides_map.all_plugins(attribute_filter).each { |plugin| @@ -94,6 +101,10 @@ module Ohai end end + def have_v6_plugin?(name) + @v6_dependency_solver.values.any? {|v6plugin| v6plugin.name == name } + end + def pathify_v6_plugin(plugin_name) path_components = plugin_name.split("::") File.join(path_components) + ".rb" diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index 0ab66ab4..d452447a 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -517,6 +517,29 @@ EOF end describe "when Chef OHAI resource executes :reload action" do + + when_plugins_directory "contains a v6 plugin" do + with_plugin("a_v6plugin.rb", <<-E) + plugin_data Mash.new + plugin_data[:foo] = :bar + E + + before do + @original_config = Ohai::Config[:plugin_path] + Ohai::Config[:plugin_path] = [ path_to(".") ] + end + + after do + Ohai::Config[:plugin_path] = @original_config + end + + it "reloads only the v6 plugin when given a specific plugin to load" do + ohai.all_plugins + lambda { ohai.all_plugins("a_v6plugin") }.should_not raise_error + end + + end + when_plugins_directory "contains a random plugin" do with_plugin("random.rb", <<-E) Ohai.plugin(:Random) do |