Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use /etc/os-release for SUSE detection (Adopted) #505

Merged
merged 5 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this go backwards?

@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