summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-12-20 09:22:58 -0800
committerGitHub <noreply@github.com>2016-12-20 09:22:58 -0800
commitf6daf869b0460c8e60411010a6c2f7bb7347c915 (patch)
tree0062611186e94e23c8550d3d7bf564dbc4d6fcc5
parent39f4a10a6da874b66d701730d29c70873038f138 (diff)
parent1209a1aaab2728961ba33394372b3395fb24146e (diff)
downloadohai-f6daf869b0460c8e60411010a6c2f7bb7347c915.tar.gz
Merge pull request #921 from chef/cumulus
Properly detect Cumulus Linux platform / version
-rw-r--r--RELEASE_NOTES.md19
-rw-r--r--lib/ohai/plugins/linux/platform.rb125
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb44
3 files changed, 127 insertions, 61 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 58db5409..2bc88693 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -9,21 +9,6 @@ Details about the thing that changed that needs to get included in the Release N
# Ohai Release Notes:
-## Haskell Language plugin
+## Cumulus Linux Platform
-Haskell is now detected in a new haskell language plugin:
-
-```javascript
-"languages": {
- "haskell": {
- "stack": {
- "version": "1.2.0",
- "description": "Version 1.2.0 x86_64 hpack-0.14.0"
- }
- }
-}
-```
-
-## LSB Release Detection
-
-The lsb_release command line tool is now preferred to the contents of /etc/lsb-release. This resolves an issue where a distro can be upgraded, but /etc/lsb-release is not upgraded to reflect the change
+Cumulus Linux will now be detected as platform `cumulus` instead of `debian` and the `platform_version` will be properly set to the Cumulus Linux release.
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index aa7771e8..7fdabbe2 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -72,6 +72,62 @@ Ohai.plugin(:Platform) do
File.exist?("/etc/os-release") && os_release_info["CISCO_RELEASE_INFO"]
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"
+ cumulus_version
+ else # not cumulus
+ File.read("/etc/debian_version").chomp
+ end
+ end
+
+ #
+ # Determines the platform_family based on the platform
+ #
+ # @returns [String] platform_family value
+ #
+ def determine_platform_family
+ case platform
+ when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /cumulus/
+ "debian"
+ when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
+ "rhel"
+ when /suse/
+ "suse"
+ when /fedora/, /pidora/, /arista_eos/
+ "fedora"
+ when /nexus/, /ios_xr/
+ "wrlinux"
+ when /gentoo/
+ "gentoo"
+ when /slackware/
+ "slackware"
+ when /arch/
+ "arch"
+ when /exherbo/
+ "exherbo"
+ when /alpine/
+ "alpine"
+ end
+ end
+
collect_data(:linux) do
# platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
if File.exist?("/etc/oracle-release")
@@ -94,10 +150,12 @@ Ohai.plugin(:Platform) do
else
if File.exist?("/usr/bin/raspi-config")
platform "raspbian"
+ elsif Dir.exist?("/etc/cumulus")
+ platform "cumulus"
else
platform "debian"
end
- platform_version File.read("/etc/debian_version").chomp
+ platform_version debian_platform_version
end
elsif File.exist?("/etc/parallels-release")
contents = File.read("/etc/parallels-release").chomp
@@ -116,12 +174,6 @@ Ohai.plugin(:Platform) do
contents = File.read("/etc/system-release").chomp
platform get_redhatish_platform(contents)
platform_version get_redhatish_version(contents)
- elsif File.exist?("/etc/gentoo-release")
- platform "gentoo"
- # the gentoo release version is the base version used to bootstrap
- # a node and doesn't have a lot of meaning in a rolling release distro
- # kernel release will be used - ex. 3.18.7-gentoo
- platform_version `uname -r`.strip
elsif File.exist?("/etc/SuSE-release")
suse_release = File.read("/etc/SuSE-release")
suse_version = suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
@@ -137,22 +189,6 @@ Ohai.plugin(:Platform) do
else
platform "suse"
end
- elsif File.exist?("/etc/slackware-version")
- platform "slackware"
- platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
- elsif File.exist?("/etc/arch-release")
- platform "arch"
- # no way to determine platform_version in a rolling release distribution
- # kernel release will be used - ex. 2.6.32-ARCH
- platform_version `uname -r`.strip
- elsif File.exist?("/etc/exherbo-release")
- platform "exherbo"
- # no way to determine platform_version in a rolling release distribution
- # kernel release will be used - ex. 3.13
- platform_version `uname -r`.strip
- elsif File.exist?("/etc/alpine-release")
- platform "alpine"
- platform_version File.read("/etc/alpine-release").strip()
elsif File.exist?("/etc/Eos-release")
platform "arista_eos"
platform_version File.read("/etc/Eos-release").strip.split[-1]
@@ -172,6 +208,28 @@ Ohai.plugin(:Platform) do
platform_family "wrlinux"
platform_version os_release_info["VERSION"]
+ elsif File.exist?("/etc/gentoo-release")
+ platform "gentoo"
+ # the gentoo release version is the base version used to bootstrap
+ # a node and doesn't have a lot of meaning in a rolling release distro
+ # kernel release will be used - ex. 3.18.7-gentoo
+ platform_version `uname -r`.strip
+ elsif File.exist?("/etc/slackware-version")
+ platform "slackware"
+ platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
+ elsif File.exist?("/etc/arch-release")
+ platform "arch"
+ # no way to determine platform_version in a rolling release distribution
+ # kernel release will be used - ex. 2.6.32-ARCH
+ platform_version `uname -r`.strip
+ elsif File.exist?("/etc/exherbo-release")
+ platform "exherbo"
+ # no way to determine platform_version in a rolling release distribution
+ # kernel release will be used - ex. 3.13
+ platform_version `uname -r`.strip
+ elsif File.exist?("/etc/alpine-release")
+ platform "alpine"
+ platform_version File.read("/etc/alpine-release").strip()
elsif lsb[:id] =~ /RedHat/i
platform "redhat"
platform_version lsb[:release]
@@ -189,25 +247,6 @@ Ohai.plugin(:Platform) do
platform_version lsb[:release]
end
- case platform
- when /debian/, /ubuntu/, /linuxmint/, /raspbian/
- platform_family "debian"
- when /fedora/, /pidora/
- platform_family "fedora"
- when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
- platform_family "rhel"
- when /suse/
- platform_family "suse"
- when /gentoo/
- platform_family "gentoo"
- when /slackware/
- platform_family "slackware"
- when /arch/
- platform_family "arch"
- when /exherbo/
- platform_family "exherbo"
- when /alpine/
- platform_family "alpine"
- end
+ platform_family determine_platform_family
end
end
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 5bff78e4..47d81e23 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -17,7 +17,6 @@
#
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
-require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
describe Ohai::System, "Linux plugin platform" do
@@ -37,6 +36,7 @@ describe Ohai::System, "Linux plugin platform" do
let(:have_raspi_config) { false }
let(:have_os_release) { false }
let(:have_cisco_release) { false }
+ let(:have_cumulus_dir) { false }
before(:each) do
@plugin = get_plugin("linux/platform")
@@ -58,6 +58,7 @@ describe Ohai::System, "Linux plugin platform" do
allow(File).to receive(:exist?).with("/usr/bin/raspi-config").and_return(have_raspi_config)
allow(File).to receive(:exist?).with("/etc/os-release").and_return(have_os_release)
allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release)
+ allow(Dir).to receive(:exist?).with("/etc/cumulus").and_return(have_cumulus_dir)
allow(File).to receive(:read).with("PLEASE STUB ALL File.read CALLS")
end
@@ -171,6 +172,41 @@ describe Ohai::System, "Linux plugin platform" do
expect(@plugin[:platform_family]).to eq("debian")
end
end
+
+ context "on cumulus" do
+
+ let(:have_cumulus_dir) { true }
+ let(:cumulus_release_content) do
+ <<-OS_RELEASE
+NAME="Cumulus Linux"
+VERSION_ID=3.1.2
+VERSION="Cumulus Linux 3.1.2"
+PRETTY_NAME="Cumulus Linux"
+ID=cumulus-linux
+ID_LIKE=debian
+CPE_NAME=cpe:/o:cumulusnetworks:cumulus_linux:3.1.2
+HOME_URL="http://www.cumulusnetworks.com/"
+SUPPORT_URL="http://support.cumulusnetworks.com/"
+
+OS_RELEASE
+ end
+
+ before(:each) do
+ expect(File).to receive(:read).with("/etc/cumulus/etc.replace/os-release").and_return(cumulus_release_content)
+ end
+
+ # Cumulus is a debian derivative
+ it "should detect Cumulus as itself with debian as the family" do
+ @plugin.run
+ expect(@plugin[:platform]).to eq("cumulus")
+ expect(@plugin[:platform_family]).to eq("debian")
+ end
+
+ it "should detect Cumulus platform_version" do
+ @plugin.run
+ expect(@plugin[:platform_version]).to eq("3.1.2")
+ end
+ end
end
describe "on slackware" do
@@ -187,6 +223,12 @@ describe Ohai::System, "Linux plugin platform" do
expect(@plugin[:platform]).to eq("slackware")
expect(@plugin[:platform_family]).to eq("slackware")
end
+
+ it "should set platform_version on slackware" do
+ expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
+ @plugin.run
+ expect(@plugin[:platform_version]).to eq("12.0.0")
+ end
end
describe "on arch" do