Skip to content

Commit

Permalink
Warn on invalid plugin directories
Browse files Browse the repository at this point in the history
  • Loading branch information
tas50 committed Apr 20, 2016
1 parent e0a8bf5 commit b4978a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ohai/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b4978a5

Please sign in to comment.