Skip to content

Commit

Permalink
Merge pull request #1297 from chef/opensuse15
Browse files Browse the repository at this point in the history
Correctly detect openSUSE leap 15+
  • Loading branch information
tas50 authored Nov 27, 2018
2 parents 2cde15d + 6b14655 commit d691f78
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/ohai/plugins/linux/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ def determine_platform_family
# 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"] == "sles" ? "suse" : os_release_info["ID"] # SLES is wrong. We call it SUSE
case os_release_info["ID"]
when "sles"
platform "suse" # SLES is wrong. We call it SUSE
when "opensuse-leap"
platform "opensuseleap"
else
platform os_release_info["ID"]
end
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.
Expand Down
34 changes: 32 additions & 2 deletions spec/unit/plugins/linux/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,39 @@
end

describe "on suse" do
context "on openSUSE 15+" do

context "on versions that have /etc/os-release and no /etc/SuSE-release (e.g. SLES15)" do
let(:have_suse_release) { false }
let(:have_os_release) { true }

let(:os_release_content) do
<<~OS_RELEASE
NAME="openSUSE Leap"
VERSION="15.0"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.0"
PRETTY_NAME="openSUSE Leap 15.0"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.0"
OS_RELEASE
end

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 "correctly detects opensuseleap 15" do
@plugin.run
expect(@plugin[:platform]).to eq("opensuseleap")
expect(@plugin[:platform_version]).to eq("15.0")
expect(@plugin[:platform_family]).to eq("suse")
end

end

context "on SLES 15+" do

let(:have_suse_release) { false }
let(:have_os_release) { true }
Expand Down Expand Up @@ -732,7 +763,6 @@
expect(@plugin[:platform_version]).to eq("15")
expect(@plugin[:platform_family]).to eq("suse")
end

end

context "on versions that have both /etc/os-release and /etc/SuSE-release (e.g. SLES12)" do
Expand Down

0 comments on commit d691f78

Please sign in to comment.