summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2021-11-05 13:25:19 -0700
committerTim Smith <tsmith84@gmail.com>2021-11-05 13:50:51 -0700
commitd8fe14d6eafc9c0a22be18c2b1117697cc4e81ef (patch)
tree5127c4694a1b996056be615432853d95d57afd09
parent3ed3f8ccea7b317e4e4d0571eec7f6c75477dc6b (diff)
downloadohai-linux_os.tar.gz
Backport Linux OS detection improvements from Chef 17linux_os
https://github.com/chef/ohai/pull/1632 https://github.com/chef/ohai/pull/1635 https://github.com/chef/ohai/pull/1670 Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/platform.rb23
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb23
2 files changed, 25 insertions, 21 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 3cb7206e..026e9d66 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -54,7 +54,7 @@ Ohai.plugin(:Platform) do
end
#
- # Cached /etc/os-release info Hash. Also has logic for Cisco Nexus
+ # Cached /etc/os-release info Hash. Also has logic for Cisco Nexus
# switches that pulls the chained CISCO_RELEASE_INFO file into the Hash (other
# distros can also reuse this method safely).
#
@@ -122,7 +122,7 @@ Ohai.plugin(:Platform) do
"sles_sap" => "suse",
"sles" => "suse",
"xenenterprise" => "xenserver",
- }[id] || id
+ }[id.downcase] || id.downcase
end
#
@@ -134,20 +134,22 @@ Ohai.plugin(:Platform) do
#
def platform_family_from_platform(plat)
case plat
- when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /cumulus/, /kali/, /pop/
+ when /ubuntu/, /debian/, /linuxmint/, /raspbian/, /cumulus/, /kali/, /pop/
# apt-get+dpkg almost certainly goes here
"debian"
- when /oracle/, /centos/, /redhat/, /almalinux/, /rocky/, /scientific/, /enterpriseenterprise/, /xcp/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/, /clearos/, /bigip/, /alibabalinux/, /sangoma/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
+ when /centos/, /redhat/, /oracle/, /almalinux/, /rocky/, /scientific/, /enterpriseenterprise/, /xenserver/, /xcp-ng/, /cloudlinux/, /alibabalinux/, /sangoma/, /clearos/, /parallels/, /ibm_powerkvm/, /nexus_centos/, /bigip/, /virtuozzo/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
# NOTE: "rhel" should be reserved exclusively for recompiled rhel versions that are nearly perfectly compatible down to the platform_version.
# The operating systems that are "rhel" should all be as compatible as rhel7 = centos7 = oracle7 = scientific7 (98%-ish core RPM version compatibility
# and the version numbers MUST track the upstream). The appropriate EPEL version repo should work nearly perfectly. Some variation like the
- # oracle kernel version differences and tuning and extra packages are clearly acceptable. Almost certainly some distros above (xenserver?)
- # should not be in this list. Please use fedora, below, instead. Also note that this is the only platform_family with this strict of a rule,
+ # oracle kernel version differences and tuning and extra packages are clearly acceptable. Almost certainly some distros above (xenserver?)
+ # should not be in this list. Please use fedora, below, instead. Also note that this is the only platform_family with this strict of a rule,
# see the example of the debian platform family for how the rest of the platform_family designations should be used.
+ #
+ # TODO: when XCP-NG 7.4 support ends we can remove the xcp-ng match. 7.5+ reports as xenenterprise which we remap to xenserver
"rhel"
when /amazon/
"amazon"
- when /suse/, /sles/, /opensuse/, /opensuseleap/, /sled/
+ when /suse/, /sles/, /opensuseleap/, /opensuse/, /sled/
"suse"
when /fedora/, /pidora/, /arista_eos/
# In the broadest sense: RPM-based, fedora-derived distributions which are not strictly re-compiled RHEL (if it uses RPMs, and smells more like redhat and less like
@@ -157,8 +159,6 @@ Ohai.plugin(:Platform) do
"wrlinux"
when /gentoo/
"gentoo"
- when /slackware/
- "slackware"
when /arch/, /manjaro/, /antergos/
"arch"
when /exherbo/
@@ -169,6 +169,8 @@ Ohai.plugin(:Platform) do
"clearlinux"
when /mangeia/
"mandriva"
+ when /slackware/
+ "slackware"
end
end
@@ -271,9 +273,6 @@ Ohai.plugin(:Platform) do
elsif /XenServer/i.match?(lsb[:id])
platform "xenserver"
platform_version lsb[:release]
- elsif /XCP/i.match?(lsb[:id])
- platform "xcp"
- platform_version lsb[:release]
elsif lsb[:id] # LSB can provide odd data that changes between releases, so we currently fall back on it rather than dealing with its subtleties
platform lsb[:id].downcase
platform_version lsb[:release]
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 64976b8e..6d2b74d9 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -82,51 +82,56 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "#platform_id_remap" do
- # https://github.com/chef/os_release/blob/master/redhat_7
+ # https://github.com/chef/os_release/blob/main/redhat_7
it "returns redhat for rhel os-release id" do
expect(plugin.platform_id_remap("rhel")).to eq("redhat")
end
- # https://github.com/chef/os_release/blob/master/amazon_2018
+ # https://github.com/chef/os_release/blob/main/amazon_2018
it "returns amazon for amzn os-release id" do
expect(plugin.platform_id_remap("amzn")).to eq("amazon")
end
- # https://github.com/chef/os_release/blob/master/oracle_7
+ # https://github.com/chef/os_release/blob/main/oracle_7
it "returns oracle for ol os-release id" do
expect(plugin.platform_id_remap("ol")).to eq("oracle")
end
- # https://github.com/chef/os_release/blob/master/sles_sap_12_3
+ # https://github.com/chef/os_release/blob/main/sles_sap_12_3
it "returns suse for sles_sap os-release id" do
expect(plugin.platform_id_remap("sles_sap")).to eq("suse")
end
- # https://github.com/chef/os_release/blob/master/archarm
+ # https://github.com/chef/os_release/blob/main/archarm
it "returns arch for archarm" do
expect(plugin.platform_id_remap("archarm")).to eq("arch")
end
- # https://github.com/chef/os_release/blob/master/sles_15_0
+ # https://github.com/chef/os_release/blob/main/sles_15_0
it "returns suse for sles os-release id" do
expect(plugin.platform_id_remap("sles")).to eq("suse")
end
- # https://github.com/chef/os_release/blob/master/opensuseleap_15_0
+ # https://github.com/chef/os_release/blob/main/opensuseleap_15_0
it "returns opensuseleap for opensuse-leap os-release id" do
expect(plugin.platform_id_remap("opensuse-leap")).to eq("opensuseleap")
end
- # https://github.com/chef/os_release/blob/master/xenserver_7_6
+ # https://github.com/chef/os_release/blob/main/xenserver_7_6
it "returns xenserver for xenenterprise os-release id" do
expect(plugin.platform_id_remap("xenenterprise")).to eq("xenserver")
end
- # https://github.com/chef/os_release/blob/master/cumulus_3_7
+ # https://github.com/chef/os_release/blob/main/cumulus_3_7
it "returns cumulus for cumulus-linux os-release id" do
expect(plugin.platform_id_remap("cumulus-linux")).to eq("cumulus")
end
+ # See https://github.com/chef/os_release/blob/main/xcp-ng_7_4#L3 for an example of why we do this
+ it "returns a downcased ID value" do
+ expect(plugin.platform_id_remap("XCP-ng")).to eq("xcp-ng")
+ end
+
it "does not transformation for any other platform" do
expect(plugin.platform_id_remap("ubuntu")).to eq("ubuntu")
end