Skip to content

Commit

Permalink
Use /etc/os-release for SUSE detection (Adopted) (#505)
Browse files Browse the repository at this point in the history
Use /etc/os-release for SUSE detection (Adopted)
  • Loading branch information
clintoncwolfe authored Aug 6, 2019
2 parents 4ed7977 + 38feb25 commit 6cc325a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/train/platforms/detect/specifications/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,27 @@ def self.load
# suse family
plat.family("suse").in_family("linux")
.detect do
unless (suse = unix_file_contents("/etc/SuSE-release")).nil?
if linux_os_release && linux_os_release["ID_LIKE"] =~ /suse/i
@platform[:release] = linux_os_release["VERSION"]
true
elsif !(suse = unix_file_contents("/etc/SuSE-release")).nil?
# https://rubular.com/r/UKaYWolCYFMfp1
version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
# https://rubular.com/r/xegcPXKEXJrJl5
version = suse[/VERSION *= *("?)([\d\.]{2,})\1$/, 2] if version == ""
# https://rubular.com/r/b5PN3hZDxa5amV
version = suse[/VERSION\s?=\s?"?([\d\.]{2,})"?/, 1] if version == ""
@platform[:release] = version
true
end
end
plat.name("opensuse").title("OpenSUSE Linux").in_family("suse")
.detect do
true if unix_file_contents("/etc/SuSE-release") =~ /^opensuse/i
true if (linux_os_release && linux_os_release["NAME"] =~ /^opensuse/i) ||
unix_file_contents("/etc/SuSE-release") =~ /^opensuse/i
end
plat.name("suse").title("Suse Linux").in_family("suse")
.detect do
true if unix_file_contents("/etc/SuSE-release") =~ /suse/i
true if (linux_os_release && linux_os_release["NAME"] =~ /^sles/i) ||
unix_file_contents("/etc/SuSE-release") =~ /suse/i
end

# arch
Expand Down
59 changes: 59 additions & 0 deletions test/unit/platforms/os_detect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ def debian_scan(id, version)
end
end

describe "windows" do
it "sets the correct family/release for windows " do
platform = scan_with_windows

platform[:name].must_equal("windows_6.3.9600")
platform[:family].must_equal("windows")
platform[:release].must_equal("6.3.9600")
end
end

describe "/etc/coreos/update.conf" do
it "sets the correct family/release for coreos" do
lsb_release = "DISTRIB_ID=Container Linux by CoreOS\nDISTRIB_RELEASE=27.9"
Expand Down Expand Up @@ -217,6 +227,55 @@ def debian_scan(id, version)
platform[:release].must_equal("cisco123")
end
end

describe "when on a suse build" do
describe "when /etc/os-release is present" do
it "sets the correct family/release for SLES" do
files = {
"/etc/os-release" => "NAME=\"SLES\"\nVERSION=\"15.1\"\nID=\"sles\"\nID_LIKE=\"suse\"\n",
}
platform = scan_with_files("linux", files)

platform[:name].must_equal("suse")
platform[:family].must_equal("suse")
platform[:release].must_equal("15.1")
end

it "sets the correct family/release for openSUSE" do
files = {
"/etc/os-release" => "NAME=\"openSUSE Leap\"\nVERSION=\"15.1\"\nID=\"opensuse-leap\"\nID_LIKE=\"suse opensuse\"\n",
}
platform = scan_with_files("linux", files)

platform[:name].must_equal("opensuse")
platform[:family].must_equal("suse")
platform[:release].must_equal("15.1")
end
end
describe "when /etc/os-release is not present" do
it "sets the correct family/release for SLES" do
files = {
"/etc/SuSE-release" => "SUSE Linux Enterprise Server 11 (x86_64)\nVERSION = 11\nPATCHLEVEL = 2",
}
platform = scan_with_files("linux", files)

platform[:name].must_equal("suse")
platform[:family].must_equal("suse")
platform[:release].must_equal("11.2")
end

it "sets the correct family/release for openSUSE" do
files = {
"/etc/SuSE-release" => "openSUSE 10.2 (x86_64)\nVERSION = 10.2",
}
platform = scan_with_files("linux", files)

platform[:name].must_equal("opensuse")
platform[:family].must_equal("suse")
platform[:release].must_equal("10.2")
end
end
end
end

describe "qnx" do
Expand Down

0 comments on commit 6cc325a

Please sign in to comment.