summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-26 10:15:37 -0800
committerTim Smith <tsmith@chef.io>2018-11-26 10:15:37 -0800
commit4bd9041d28a3fb2badf7a4b8ca4b33fc417432fc (patch)
treeb3b54cc41a08586be4af4c76ce7a5b066f2b438d
parent1ce923c827fb396fdf4f25aa9771399509468265 (diff)
downloadohai-4bd9041d28a3fb2badf7a4b8ca4b33fc417432fc.tar.gz
Add a simple method for platform version detection
Break out more logic into simpler methods that can be tested Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/platform.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index c96a2981..c928d503 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -247,7 +247,7 @@ Ohai.plugin(:Platform) do
platform_version File.read("/etc/Eos-release").strip.split[-1]
elsif os_release_file_is_cisco?
raise "unknown Cisco /etc/os-release or /etc/cisco-release ID_LIKE field" if
- os_release_info["ID_LIKE"].nil? || ! os_release_info["ID_LIKE"].include?("wrlinux")
+ os_release_info["ID_LIKE"].nil? || !os_release_info["ID_LIKE"].include?("wrlinux")
case os_release_info["ID"]
when "nexus"
@@ -334,6 +334,14 @@ Ohai.plugin(:Platform) do
end
end
+ # Grab the version from the VERSION_ID field and use the kernel release if that's not
+ # available. It should be there for everything, but rolling releases like arch / gentoo
+ # where we've traditionally used the kernel as the version
+ # @return String the OS version
+ def determine_os_version
+ os_release_info["VERSION_ID"] || `uname -r`.strip
+ end
+
collect_data(:linux) do
if ::File.exist?("/etc/os-release")
logger.trace("Plugin platform: Using /etc/os-release for platform detection")
@@ -341,8 +349,7 @@ Ohai.plugin(:Platform) do
# fixup os-release names to ohai platform names
platform platform_id_remap(os_release_info["ID"])
- # unless we already set it in a specific way above set the plaform_version from os-release file
- platform_version os_release_info["VERSION_ID"] if platform_version.nil?
+ platform_version determine_os_version
else # we're on an old Linux distro
legacy_platform_detection
end