summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Asuncion <jose.asuncion@gmail.com>2017-08-23 18:32:32 -0700
committerJose Asuncion <jose.asuncion@gmail.com>2017-08-23 18:33:00 -0700
commit094ccf036ec26d16219ab65386f4368c8773ef71 (patch)
tree7b6929c7d3297554f084e0ddf473f2ddfef13048
parent2203f34929e5a186a8a54c4358dfb0947176ae83 (diff)
downloadohai-094ccf036ec26d16219ab65386f4368c8773ef71.tar.gz
rescue shell_out exceptions as error handling instead of which
Signed-off-by: Jose Asuncion <jeunito@gmail.com>
-rw-r--r--lib/ohai/plugins/linux/filesystem.rb8
-rw-r--r--spec/unit/plugins/linux/filesystem_spec.rb2
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb
index 27d407a9..e15e94f2 100644
--- a/lib/ohai/plugins/linux/filesystem.rb
+++ b/lib/ohai/plugins/linux/filesystem.rb
@@ -95,7 +95,7 @@ Ohai.plugin(:Filesystem) do
fs = Mash.new
# Grab filesystem data from df
- if which("df")
+ begin
so = shell_out("df -P")
so.stdout.each_line do |line|
case line
@@ -130,12 +130,12 @@ Ohai.plugin(:Filesystem) do
fs[key][:mount] = $6
end
end
- else
+ rescue Ohai::Exceptions::Exec
Ohai::Log.warn("df is not available")
end
# Grab mount information from /bin/mount
- if which("mount")
+ begin
so = shell_out("mount")
so.stdout.each_line do |line|
if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
@@ -147,7 +147,7 @@ Ohai.plugin(:Filesystem) do
fs[key][:mount_options] = $4.split(",")
end
end
- else
+ rescue Ohai::Exceptions::Exec
Ohai::Log.warn("mount is not available")
end
diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb
index 88fc7215..65265cd4 100644
--- a/spec/unit/plugins/linux/filesystem_spec.rb
+++ b/spec/unit/plugins/linux/filesystem_spec.rb
@@ -535,7 +535,7 @@ BLKID_TYPE
%w{df mount}.each do |command|
describe "when #{command} does not exist" do
it "logs warning about #{command} missing" do
- allow(plugin).to receive(:which).with(command).and_return(nil)
+ allow(plugin).to receive(:shell_out).with(/#{command}/).and_raise(Ohai::Exceptions::Exec)
expect(Ohai::Log).to receive(:warn).with("#{command} is not available")
plugin.run
end