summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-04-20 15:11:50 -0700
committerTim Smith <tsmith84@gmail.com>2016-04-22 09:35:58 -0700
commit898d8f57c5e16734982938f5c6e1cdfd6baa21b5 (patch)
tree0300ee779a245a593ae5aa9ecbba47e9a252ed4f
parent972c55c43821d9f0886396d0633dd9b9920443fb (diff)
downloadohai-898d8f57c5e16734982938f5c6e1cdfd6baa21b5.tar.gz
Warn on invalid plugin directories
-rw-r--r--lib/ohai/loader.rb6
-rw-r--r--spec/unit/loader_spec.rb8
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb
index c5603afe..72bfb621 100644
--- a/lib/ohai/loader.rb
+++ b/lib/ohai/loader.rb
@@ -39,7 +39,13 @@ module Ohai
# Finds all the *.rb files under the configured paths in :plugin_path
def self.find_all_in(plugin_dir)
+ unless Dir.exist?(plugin_dir)
+ Ohai::Log.warn("The plugin path #{plugin_dir} does not exist. Skipping...")
+ return []
+ end
+
Ohai::Log.debug("Searching for Ohai plugins in #{plugin_dir}")
+
# escape_glob_dir does not exist in 12.7 or below
if ChefConfig::PathHelper.respond_to?(:escape_glob_dir)
escaped = ChefConfig::PathHelper.escape_glob_dir(plugin_dir)
diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb
index f211a7b1..bfe2aa83 100644
--- a/spec/unit/loader_spec.rb
+++ b/spec/unit/loader_spec.rb
@@ -219,6 +219,14 @@ EOF
expect { loader.load_plugin(path_to("bad_name.rb")) }.not_to raise_error
end
end
+
+ describe "when plugin directory does not exist" do
+ it "logs an invalid plugin path warning" do
+ expect(Ohai::Log).to receive(:warn).with(/The plugin path.*does not exist/)
+ allow(Dir).to receive(:exist?).with("/bogus/dir").and_return(false)
+ Ohai::Loader::PluginFile.find_all_in("/bogus/dir")
+ end
+ end
end
end
end