Skip to content

Commit

Permalink
Merge branch 'detect-suse-15' of https://github.com/russellcardullo/t…
Browse files Browse the repository at this point in the history
…rain into cw/update-suse-detection
  • Loading branch information
clintoncwolfe committed Aug 6, 2019
2 parents 4ed7977 + 96d38cd commit d639f05
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/train/platforms/detect/specifications/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,30 @@ def self.load

# suse family
plat.family("suse").in_family("linux")
.detect do
unless (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 == ""
@platform[:release] = version
true
.detect do
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
version = suse[/VERSION\s?=\s?"?([\d\.]{2,})"?/, 1] if version == ""
@platform[:release] = version
true
end
end
end
plat.name("opensuse").title("OpenSUSE Linux").in_family("suse")
.detect do
true if unix_file_contents("/etc/SuSE-release") =~ /^opensuse/i
end
.detect do
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
end
.detect do
true if (linux_os_release && linux_os_release["NAME"] =~ /^sles/i) ||
unix_file_contents("/etc/SuSE-release") =~ /suse/i
end

# arch
plat.name("arch").title("Arch Linux").in_family("linux")
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 d639f05

Please sign in to comment.