summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2017-10-04 22:18:09 -0700
committerGitHub <noreply@github.com>2017-10-04 22:18:09 -0700
commit1dd9f211c5c18e8abb3a7b3547cfaab90c069732 (patch)
treea9572a55d3d725823843bcdb768215be9adbf413
parent978bcf908e9ac8321d79a1a55dd4d4c3e4c6666e (diff)
downloadohai-1dd9f211c5c18e8abb3a7b3547cfaab90c069732.tar.gz
Fix regression in #1047 (#1066)
PR #1047 allows a plugin to return partial data which may be incredibly dangerous. It's a totally reasonable thing to want, however, so we gate it behind a plugin config. However, the default behavior reverts to where it was. Signed-off-by: Phil Dibowitz <phil@ipom.com>
-rw-r--r--RELEASE_NOTES.md6
-rw-r--r--lib/ohai/plugins/linux/filesystem.rb8
-rw-r--r--spec/unit/plugins/linux/filesystem_spec.rb11
3 files changed, 23 insertions, 2 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 5f53e49e..71e7a524 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -8,6 +8,12 @@ Users can now specify a list of plugins which are `critical`. Critical plugins w
ohai.critical_plugins << :Filesystem
```
+### Filesystem now has a `allow_partial_data` configuration option
+
+The Filesystem plugin now has a `allow_partial_data` configuration option. If
+set, the filesystem will return whatever data it can even if some commands it
+ran failed.
+
# Ohai Release Notes 13.5
### Correctly detect IPv6 routes ending in ::
diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb
index 64acc32c..00c3705b 100644
--- a/lib/ohai/plugins/linux/filesystem.rb
+++ b/lib/ohai/plugins/linux/filesystem.rb
@@ -130,7 +130,10 @@ Ohai.plugin(:Filesystem) do
fs[key][:mount] = $6
end
end
- rescue Ohai::Exceptions::Exec
+ rescue Ohai::Exceptions::Exec => e
+ unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
+ raise e
+ end
Ohai::Log.warn("Plugin Filesystem: df binary is not available. Some data will not be available.")
end
@@ -148,6 +151,9 @@ Ohai.plugin(:Filesystem) do
end
end
rescue Ohai::Exceptions::Exec
+ unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
+ raise e
+ end
Ohai::Log.warn("Plugin Filesystem: mount binary is not available. Some data will not be available.")
end
diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb
index 13aeb248..451849be 100644
--- a/spec/unit/plugins/linux/filesystem_spec.rb
+++ b/spec/unit/plugins/linux/filesystem_spec.rb
@@ -533,8 +533,17 @@ BLKID_TYPE
end
%w{df mount}.each do |command|
- describe "when #{command} does not exist" do
+ describe "when :allow_partial_data set, #{command} does not exist" do
+ before do
+ Ohai.config[:plugin][:filesystem][:allow_partial_data] = true
+ end
+
+ after do
+ Ohai.config[:plugin][:filesystem][:allow_partial_data] = false
+ end
+
it "logs warning about #{command} missing" do
+ Ohai.config[:plugin][:filesystem][:allow_partial_data] = true
allow(plugin).to receive(:shell_out).with(/#{command}/).and_raise(Ohai::Exceptions::Exec)
expect(Ohai::Log).to receive(:warn).with("Plugin Filesystem: #{command} binary is not available. Some data will not be available.")
plugin.run