summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-12-13 19:48:44 -0800
committerTim Smith <tsmith@chef.io>2016-12-15 16:12:37 -0800
commitfcde4543dcab14ccbe7ef33b00e643ada2d9761d (patch)
treeedf4d1f1111ff219119dcc8083224ced60b84940
parentb8427163ad659179af16171e329d77c5344d537a (diff)
downloadohai-fcde4543dcab14ccbe7ef33b00e643ada2d9761d.tar.gz
Properly detect Cumulus Linux platform / version
Detect cumulus Linux systems if they have /etc/cumulus directory. Use platform of ‘cumulus’ and platform_family debian since it’s Debian 8.5. Parse version from their config directory. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/platform.rb73
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb46
2 files changed, 97 insertions, 22 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index aa7771e8..76c9d0a5 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -72,6 +72,54 @@ Ohai.plugin(:Platform) do
File.exist?("/etc/os-release") && os_release_info["CISCO_RELEASE_INFO"]
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
+ else # not cumulus
+ File.read("/etc/debian_version").chomp
+ end
+ end
+
+ #
+ # Determines the platform_family based on the platform_family
+ #
+ # @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 +142,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
@@ -189,25 +239,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..34b79254 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,43 @@ 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(:have_cumulus_release) { 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(: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
+
+ # 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 +225,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