From c482b3e3e7cfef27c9ee48cfd3664e5b20241f9b Mon Sep 17 00:00:00 2001 From: Russell Cardullo Date: Thu, 11 Jul 2019 15:43:52 -0700 Subject: [PATCH 1/3] Move windows detection test outside of debian block Moves the windows test into it's own block since it's not part of the set of debian tests. Signed-off-by: Russell Cardullo --- test/unit/platforms/os_detect_test.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/unit/platforms/os_detect_test.rb b/test/unit/platforms/os_detect_test.rb index caa92bc8..bdf9a793 100644 --- a/test/unit/platforms/os_detect_test.rb +++ b/test/unit/platforms/os_detect_test.rb @@ -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") @@ -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" From 77bbcf06489d9c5ca0cab302abb46d3bb640bb4f Mon Sep 17 00:00:00 2001 From: Russell Cardullo Date: Thu, 11 Jul 2019 16:34:11 -0700 Subject: [PATCH 2/3] Use os-release instead of SuSE-release to detect SUSE The /etc/SuSE-release file was deprecated in older SUSE versions and as of openSUSE/SLES 15.X is no longer present on these systems. This changes the detection methods to use /etc/os-release which should be present on new as well as older systems. Signed-off-by: Russell Cardullo --- .../platforms/detect/specifications/os.rb | 12 ++++------ test/unit/platforms/os_detect_test.rb | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/train/platforms/detect/specifications/os.rb b/lib/train/platforms/detect/specifications/os.rb index a7181cbb..95f0c998 100644 --- a/lib/train/platforms/detect/specifications/os.rb +++ b/lib/train/platforms/detect/specifications/os.rb @@ -236,22 +236,18 @@ def self.load # suse family plat.family("suse").in_family("linux") .detect do - if !(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 + if linux_os_release && linux_os_release["ID_LIKE"] =~ /suse/i + @platform[:release] = linux_os_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 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 end # arch diff --git a/test/unit/platforms/os_detect_test.rb b/test/unit/platforms/os_detect_test.rb index bdf9a793..d81b3c8a 100644 --- a/test/unit/platforms/os_detect_test.rb +++ b/test/unit/platforms/os_detect_test.rb @@ -217,6 +217,30 @@ def debian_scan(id, version) platform[:release].must_equal("cisco123") end end + + describe "when on a suse build" 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 end describe "qnx" do From 96d38cdb9a2ca40369e7471355cbbac60feb83ee Mon Sep 17 00:00:00 2001 From: Russell Cardullo Date: Fri, 12 Jul 2019 10:54:14 -0700 Subject: [PATCH 3/3] Add fallback to detect SUSE versions without /etc/os-release Older versions of SUSE won't have the /etc/os-release file so fallback to the /etc/SuSE-release file in those cases. Signed-off-by: Russell Cardullo --- .../platforms/detect/specifications/os.rb | 13 +++- test/unit/platforms/os_detect_test.rb | 63 +++++++++++++------ 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/lib/train/platforms/detect/specifications/os.rb b/lib/train/platforms/detect/specifications/os.rb index 95f0c998..e9ad7b36 100644 --- a/lib/train/platforms/detect/specifications/os.rb +++ b/lib/train/platforms/detect/specifications/os.rb @@ -239,15 +239,24 @@ def self.load 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 plat.name("opensuse").title("OpenSUSE Linux").in_family("suse") .detect do - true if linux_os_release && linux_os_release["NAME"] =~ /^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 linux_os_release && linux_os_release["NAME"] =~ /^sles/i + true if (linux_os_release && linux_os_release["NAME"] =~ /^sles/i) || + unix_file_contents("/etc/SuSE-release") =~ /suse/i end # arch diff --git a/test/unit/platforms/os_detect_test.rb b/test/unit/platforms/os_detect_test.rb index d81b3c8a..b561fdc6 100644 --- a/test/unit/platforms/os_detect_test.rb +++ b/test/unit/platforms/os_detect_test.rb @@ -219,26 +219,51 @@ def debian_scan(id, version) end describe "when on a suse build" 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") + 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 - - 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") + 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