summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-06 09:24:38 -0800
committerGitHub <noreply@github.com>2018-03-06 09:24:38 -0800
commit94426d82203d94a7d820d365b22f20749d284a0c (patch)
tree144dad4ee50e95ab1b1f7d3cc2e30323acc7e297
parent159c9046b14e86969d1e2373c4e28cb67ef3bc08 (diff)
parent8dc473d5d3f17ef4c6b05cc876e45d2bf5a9daef (diff)
downloadohai-94426d82203d94a7d820d365b22f20749d284a0c.tar.gz
Merge pull request #1140 from b1-systems/master
SUSE: Use /etc/os-release if present for all platform attributes
-rw-r--r--lib/ohai/plugins/linux/platform.rb14
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb183
2 files changed, 133 insertions, 64 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 55d939cf..7bc5e1a7 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -131,7 +131,7 @@ Ohai.plugin(:Platform) do
"rhel"
when /amazon/
"amazon"
- when /suse/
+ when /suse/, /sles/, /opensuse/
"suse"
when /fedora/, /pidora/, /arista_eos/
# In the broadest sense: RPM-based, fedora-derived distributions which are not strictly re-compiled RHEL (if it uses RPMs, and smells more like redhat and less like
@@ -280,8 +280,18 @@ Ohai.plugin(:Platform) do
elsif lsb[:id] # LSB can provide odd data that changes between releases, so we currently fall back on it rather than dealing with its subtleties
platform lsb[:id].downcase
platform_version lsb[:release]
+ # Use os-release (present on all modern linux distros) BUT use old *-release files as fallback.
+ # os-release will only be used if no other *-release file is present.
+ # We have to do this for compatibility reasons, or older OS releases might get different
+ # "platform" or "platform_version" attributes (e.g. SLES12, RHEL7).
+ elsif File.exist?("/etc/os-release")
+ platform os_release_info["ID"]
+ platform_version os_release_info["VERSION_ID"]
+ # platform_family also does not need to be hardcoded anymore.
+ # This would be the correct way, but we stick with "determine_platform_family" for compatibility reasons.
+ # platform_family os_release_info["ID_LIKE"]
end
- platform_family determine_platform_family
+ platform_family determine_platform_family if platform_family.nil?
end
end
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index efe2884e..88f5dacc 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -686,86 +686,145 @@ CISCO_RELEASE
describe "on suse" do
- let(:have_suse_release) { true }
+ context "on versions that have /etc/os-release and no /etc/SuSE-release (e.g. SLES15)" do
- describe "with lsb_release results" do
- before(:each) do
- @plugin[:lsb][:id] = "SUSE LINUX"
- end
+ let(:have_suse_release) { false }
+ let(:have_os_release) { true }
- it "should read the platform as opensuse on openSUSE" do
- @plugin[:lsb][:release] = "12.1"
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
- @plugin.run
- expect(@plugin[:platform]).to eq("opensuse")
- expect(@plugin[:platform_family]).to eq("suse")
- end
- end
+ let(:os_release_content) do
+ <<-OS_RELEASE
+VERSION="15"
+VERSION_ID="15"
+PRETTY_NAME="SUSE Linux Enterprise Server 15"
+ID="sles"
+ID_LIKE="suse"
+ANSI_COLOR="0;32"
+CPE_NAME="cpe:/o:suse:sles:15"
- describe "without lsb_release results" do
- before(:each) do
- @plugin.lsb = nil
+OS_RELEASE
end
- it "should set platform and platform_family to suse and bogus verion to 10.0" do
- expect(File).to receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
- @plugin.run
- expect(@plugin[:platform]).to eq("suse")
- expect(@plugin[:platform_family]).to eq("suse")
+ before do
+ expect(File).to_not receive(:read).with("/etc/SuSE-release")
+ expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
end
- it "should read the version as 10.1 for bogus SLES 10" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n")
+ it "correctly detects SLES15" do
@plugin.run
- expect(@plugin[:platform]).to eq("suse")
- expect(@plugin[:platform_version]).to eq("10.1")
+ expect(@plugin[:platform]).to eq("sles")
+ expect(@plugin[:platform_version]).to eq("15")
expect(@plugin[:platform_family]).to eq("suse")
end
- it "should read the version as 11.2" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
- @plugin.run
- expect(@plugin[:platform]).to eq("suse")
- expect(@plugin[:platform_version]).to eq("11.2")
- expect(@plugin[:platform_family]).to eq("suse")
- end
+ end
- it "[OHAI-272] should read the version as 11.3" do
- expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
- @plugin.run
- expect(@plugin[:platform]).to eq("opensuse")
- expect(@plugin[:platform_version]).to eq("11.3")
- expect(@plugin[:platform_family]).to eq("suse")
- end
+ context "on versions that have both /etc/os-release and /etc/SuSE-release (e.g. SLES12)" do
+ let(:have_suse_release) { true }
+ let(:have_os_release) { true }
- it "[OHAI-272] should read the version as 9.1" do
- expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
- @plugin.run
- expect(@plugin[:platform]).to eq("suse")
- expect(@plugin[:platform_version]).to eq("9.1")
- expect(@plugin[:platform_family]).to eq("suse")
- end
+ describe "with lsb_release results" do
+ before(:each) do
+ @plugin[:lsb][:id] = "SUSE LINUX"
+ end
- it "[OHAI-272] should read the version as 11.4" do
- expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
- @plugin.run
- expect(@plugin[:platform]).to eq("opensuse")
- expect(@plugin[:platform_version]).to eq("11.4")
- expect(@plugin[:platform_family]).to eq("suse")
+ it "should read the platform as opensuse on openSUSE" do
+ @plugin[:lsb][:release] = "12.1"
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("opensuse")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
end
+ end
- it "should read the platform as opensuse on openSUSE" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
- @plugin.run
- expect(@plugin[:platform]).to eq("opensuse")
- expect(@plugin[:platform_family]).to eq("suse")
+ context "on versions that have no /etc/os-release but /etc/SuSE-release (e.g. SLES11)" do
+ let(:have_suse_release) { true }
+ let(:have_os_release) { false }
+
+ describe "with lsb_release results" do
+ before(:each) do
+ @plugin[:lsb][:id] = "SUSE LINUX"
+ end
+
+ it "should read the platform as opensuse on openSUSE" do
+ @plugin[:lsb][:release] = "12.1"
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("opensuse")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
end
+ end
- it "should read the platform as opensuseleap on openSUSE Leap" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
- @plugin.run
- expect(@plugin[:platform]).to eq("opensuseleap")
- expect(@plugin[:platform_family]).to eq("suse")
+ context "on openSUSE and older SLES versions" do
+ let(:have_suse_release) { true }
+ let(:have_os_release) { true }
+
+ describe "without lsb_release results" do
+ before(:each) do
+ @plugin.lsb = nil
+ end
+
+ it "should set platform and platform_family to suse and bogus verion to 10.0" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("suse")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "should read the version as 10.1 for bogus SLES 10" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("suse")
+ expect(@plugin[:platform_version]).to eq("10.1")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "should read the version as 11.2" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("suse")
+ expect(@plugin[:platform_version]).to eq("11.2")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "[OHAI-272] should read the version as 11.3" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("opensuse")
+ expect(@plugin[:platform_version]).to eq("11.3")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "[OHAI-272] should read the version as 9.1" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("suse")
+ expect(@plugin[:platform_version]).to eq("9.1")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "[OHAI-272] should read the version as 11.4" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("opensuse")
+ expect(@plugin[:platform_version]).to eq("11.4")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "should read the platform as opensuse on openSUSE" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("opensuse")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
+
+ it "should read the platform as opensuseleap on openSUSE Leap" do
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("opensuseleap")
+ expect(@plugin[:platform_family]).to eq("suse")
+ end
end
end
end