summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-12-19 17:57:20 -0800
committerTim Smith <tsmith@chef.io>2016-12-19 18:27:40 -0800
commitb81243bff3b7adfdcbe9c2950f0762bf40701c49 (patch)
tree846575d2d70b411913d6871523d3aa1828a0a299
parentf46354f528ac5158de7ee817be10b38ee91e37ea (diff)
downloadohai-b81243bff3b7adfdcbe9c2950f0762bf40701c49.tar.gz
Better error handling if we can't determine Cumulus versioncumulus
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/platform.rb20
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb2
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 4a013868..aa5fece2 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -73,18 +73,26 @@ Ohai.plugin(:Platform) do
end
#
+ # Determines the platform version for Cumulus Linux systems
+ #
+ # @returns [String] cumulus Linux version from /etc/cumulus/etc.replace/os-release
+ #
+ def cumulus_version
+ release_contents = File.read("/etc/cumulus/etc.replace/os-release")
+ release_contents.match(/VERSION_ID=(.*)/)[1]
+ rescue NoMethodError, Errno::ENOENT, Errno::EACCES # rescue regex failure, file missing, or permission denied
+ Ohai::Log.warn("Detected Cumulus Linux, but /etc/cumulus/etc/replace/os-release could not be parsed to determine platform_version")
+ nil
+ end
+
+ #
# Determines the platform version for Debian based systems
#
# @returns [String] version of the platform
#
def debian_platform_version
if platform == "cumulus"
- if File.exist?("/etc/cumulus/etc.replace/os-release")
- release_contents = File.read("/etc/cumulus/etc.replace/os-release")
- release_contents.match(/VERSION_ID=(.*)/)[1] rescue nil
- else
- Ohai::Log.warn("Detected Cumulus Linux, but /etc/cumulus/etc/replace/os-release not found to determine platform_version")
- end
+ cumulus_version
else # not cumulus
File.read("/etc/debian_version").chomp
end
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 34b79254..47d81e23 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -176,7 +176,6 @@ describe Ohai::System, "Linux plugin platform" do
context "on cumulus" do
let(:have_cumulus_dir) { true }
- let(:have_cumulus_release) { true }
let(:cumulus_release_content) do
<<-OS_RELEASE
NAME="Cumulus Linux"
@@ -193,7 +192,6 @@ OS_RELEASE
end
before(:each) do
- expect(File).to receive(:exist?).with("/etc/cumulus/etc.replace/os-release").and_return(true)
expect(File).to receive(:read).with("/etc/cumulus/etc.replace/os-release").and_return(cumulus_release_content)
end