diff options
author | Tim Smith <tsmith@chef.io> | 2018-11-26 15:52:58 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-11-26 15:52:58 -0800 |
commit | 1153542771a5c2ab7bc30a414693b326220389f1 (patch) | |
tree | 6c4fb6b11bdcc93f60064eaa270852b7f00d15a3 | |
parent | e7fa47a00774fc48f85b86349261e50db48ae47f (diff) | |
download | ohai-1153542771a5c2ab7bc30a414693b326220389f1.tar.gz |
Use /etc/os-release detection for cumulus
I've confirmed this works on a cumulus system. Not sure where the previous logic came from.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/linux/platform.rb | 34 | ||||
-rw-r--r-- | spec/unit/plugins/linux/platform_spec.rb | 37 |
2 files changed, 3 insertions, 68 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb index a51a8e2c..0d487a27 100644 --- a/lib/ohai/plugins/linux/platform.rb +++ b/lib/ohai/plugins/linux/platform.rb @@ -83,21 +83,6 @@ Ohai.plugin(:Platform) do end # - # Determines the platform version for Cumulus Linux systems - # - # @deprecated - # - # @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 - logger.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 F5 Big-IP systems # # @deprecated @@ -113,21 +98,6 @@ Ohai.plugin(:Platform) do end # - # Determines the platform version for Debian based systems - # - # @deprecated - # - # @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 # # @param plat [String] the platform name @@ -203,12 +173,10 @@ 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 debian_platform_version + platform_version File.read("/etc/debian_version").chomp end elsif File.exist?("/etc/parallels-release") contents = File.read("/etc/parallels-release").chomp diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 9446b5be..74aec866 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -247,6 +247,7 @@ OS_DATA let(:have_oracle_release) { false } let(:have_parallels_release) { false } let(:have_os_release) { false } + let(:have_os_release) { false } let(:have_usr_lib_os_release) { false } let(:have_cisco_release) { false } let(:have_f5_release) { false } @@ -267,6 +268,7 @@ OS_DATA allow(File).to receive(:exist?).with("/etc/oracle-release").and_return(have_oracle_release) allow(File).to receive(:exist?).with("/etc/parallels-release").and_return(have_parallels_release) 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/f5-release").and_return(have_f5_release) allow(File).to receive(:exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release) allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release) @@ -419,41 +421,6 @@ OS_DATA expect(plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)") 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 |