summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2014-01-15 15:15:00 -0800
committersersut <serdar@opscode.com>2014-01-15 15:15:08 -0800
commitec77e7d31f27cc0463f5186558f596bdb900a691 (patch)
tree9582cd6886d6dc7a1202a170adcf6c487436196b
parent7769246d1d2f9551cfafe2066018cce87235e840 (diff)
downloadohai-ec77e7d31f27cc0463f5186558f596bdb900a691.tar.gz
Find the plugins for the first parent for a given attribute in CLI if there are no plugins that provide any of the subattributes.
-rw-r--r--lib/ohai/provides_map.rb24
-rw-r--r--spec/unit/provides_map_spec.rb9
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/ohai/provides_map.rb b/lib/ohai/provides_map.rb
index c2da2124..18a76d25 100644
--- a/lib/ohai/provides_map.rb
+++ b/lib/ohai/provides_map.rb
@@ -60,19 +60,35 @@ module Ohai
plugins.uniq
end
- # gather plugins providing each of the attributes listed along
- # with providers of subattributes
+ # This function is used to fetch the plugins for the attributes specified
+ # in the CLI options to Ohai.
+ # It first attempts to find the plugins for the attributes
+ # or the sub attributes given.
+ # If it can't find any, it looks for plugins that might
+ # provide the parents of a given attribute and returns the
+ # first parent found.
def deep_find_providers_for(attributes)
plugins = []
attributes.each do |attribute|
attrs = select_subtree(@map, attribute)
- raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless attrs
+
+ unless attrs
+ attrs = select_closest_subtree(@map, attribute)
+
+ unless attrs
+ raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'"
+ end
+ end
+
collect_plugins_in(attrs, plugins)
end
+
plugins.uniq
end
- # gather plugins providing each of the attributes listed, or the
+ # This function is used to fetch the plugins from
+ # 'depends "languages"' statements in plugins.
+ # It gathers plugins providing each of the attributes listed, or the
# plugins providing the closest parent attribute
def find_closest_providers_for(attributes)
plugins = []
diff --git a/spec/unit/provides_map_spec.rb b/spec/unit/provides_map_spec.rb
index 3db88d21..9fa9a8f5 100644
--- a/spec/unit/provides_map_spec.rb
+++ b/spec/unit/provides_map_spec.rb
@@ -116,20 +116,25 @@ describe Ohai::ProvidesMap do
end
end
- describe "when looking for attribute and subattribute providers" do
+ describe "when looking for providers of attributes specified in CLI" do
before do
provides_map.set_providers_for(plugin_1, ["cat/whiskers"])
provides_map.set_providers_for(plugin_2, ["cat/paws", "cat/paws/toes"])
provides_map.set_providers_for(plugin_3, ["cat/mouth/teeth"])
end
- it "should find providers for subattributes even when the attribute doesn't have a provider" do
+ it "should find providers for subattributes if any exists when the attribute doesn't have a provider" do
providers = provides_map.deep_find_providers_for(["cat"])
expect(providers).to have(3).plugins
expect(providers).to include(plugin_1)
expect(providers).to include(plugin_2)
expect(providers).to include(plugin_3)
end
+
+ it "should find providers for the first parent attribute when the attribute or any subattributes doesn't have a provider" do
+ providers = provides_map.deep_find_providers_for(["cat/paws/front"])
+ expect(providers).to eq([plugin_2])
+ end
end
describe "when looking for the closest providers" do