From b4978a5e92bd07beded8bf77caf745ab09705afe Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 20 Apr 2016 15:11:50 -0700 Subject: [PATCH] Warn on invalid plugin directories --- lib/ohai/loader.rb | 6 ++++++ spec/unit/loader_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index c5603afe1..72bfb6218 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -39,7 +39,13 @@ class PluginFile < Struct.new(:path, :plugin_root) # 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 f211a7b13..6b6418caa 100644 --- a/spec/unit/loader_spec.rb +++ b/spec/unit/loader_spec.rb @@ -219,6 +219,14 @@ 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 and 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