Skip to content

Commit

Permalink
Skip v7 plugins when refreshing a v6 plugin
Browse files Browse the repository at this point in the history
Fixes OHAI-562
  • Loading branch information
danielsdeleo committed Apr 9, 2014
1 parent 189aace commit 5942649
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/ohai/system.rb
Expand Up @@ -83,6 +83,13 @@ def run_plugins(safe = false, attribute_filter = nil)
@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|
Expand All @@ -94,6 +101,10 @@ def run_plugins(safe = false, attribute_filter = nil)
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"
Expand Down
23 changes: 23 additions & 0 deletions spec/unit/system_spec.rb
Expand Up @@ -517,6 +517,29 @@
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
Expand Down

0 comments on commit 5942649

Please sign in to comment.