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 #476

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 8 additions & 3 deletions lib/train/platforms/detect/specifications/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ def self.load
# suse family
plat.family("suse").in_family("linux")
.detect do
if !(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/b5PN3hZDxa5amV
Expand All @@ -247,11 +250,13 @@ def self.load
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
69 changes: 59 additions & 10 deletions test/unit/platforms/os_detect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ 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 "everything else" do
it "sets the correct family/release for debian " do
platform = debian_scan("some_debian", "12.99")
Expand All @@ -175,6 +165,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 +217,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