diff options
author | Tim Smith <tsmith@chef.io> | 2018-11-26 20:58:32 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-11-26 20:58:32 -0800 |
commit | 5d4e074e491eace039d48e98a0aa8f5ff88f440c (patch) | |
tree | 2d5e41bc47fdecf1ab8300247ad67b70ea0c0018 | |
parent | 4dc35bb70e4b34e5ddfd7782973630bb5fe78996 (diff) | |
download | ohai-5d4e074e491eace039d48e98a0aa8f5ff88f440c.tar.gz |
Fix platform remapping on nexus_centos
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/linux/platform.rb | 9 | ||||
-rw-r--r-- | spec/unit/plugins/linux/platform_spec.rb | 244 |
2 files changed, 118 insertions, 135 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb index 9a71f19a..1097cf4c 100644 --- a/lib/ohai/plugins/linux/platform.rb +++ b/lib/ohai/plugins/linux/platform.rb @@ -30,7 +30,6 @@ Ohai.plugin(:Platform) do "opensuse-leap" => "opensuseleap", "xenenterprise" => "xenserver", "cumulus-linux" => "cumulus", - "nexus" => "nexus_centos", "clear-linux-os" => "clearlinux", }.freeze end @@ -124,6 +123,10 @@ Ohai.plugin(:Platform) do # @returns [String] the platform name to use in Ohai # def platform_id_remap(id) + # this catches the centos guest shell in the nexus switch which identifies itself as centos + return "nexus_centos" if id == "centos" && os_release_file_is_cisco? + + # remap based on the hash of platforms PLATFORM_MAPPINGS[id] || id end @@ -294,8 +297,8 @@ Ohai.plugin(:Platform) do # @return String the OS version def determine_os_version # centos only includes the major version in os-release for some reason - if os_release_info['ID'] == 'centos' - get_redhatish_version + if os_release_info["ID"] == "centos" + get_redhatish_version(File.read("/etc/redhat-release").chomp) else os_release_info["VERSION_ID"] || `/bin/uname -r`.strip end diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 8f0bbb9b..5ca6eae4 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -109,13 +109,50 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin.platform_id_remap("cumulus-linux")).to eq("cumulus") end - it "returns nexus_centos for nexus os-release id" do - expect(plugin.platform_id_remap("nexus")).to eq("nexus_centos") + it "returns clearlinux for clear-linux-os os-release id" do + expect(plugin.platform_id_remap("clear-linux-os")).to eq("clearlinux") end it "does not transformation for any other platform" do expect(plugin.platform_id_remap("ubuntu")).to eq("ubuntu") end + + context "on a centos subshell on a nexus switch" do + let(:os_release_content) do + <<~OS_RELEASE + NAME="CentOS Linux" + VERSION="7 (Core)" + ID="centos" + ID_LIKE="rhel fedora" + VERSION_ID="7" + PRETTY_NAME="CentOS Linux 7 (Core)" + + CISCO_RELEASE_INFO=/etc/shared/os-release + OS_RELEASE + end + + let(:cisco_release_content) do + <<~CISCO_RELEASE + ID=nexus + ID_LIKE=wrlinux + NAME=Nexus + VERSION="7.0(3)I2(0.475E.6)" + VERSION_ID="7.0(3)I2" + PRETTY_NAME="Nexus 7.0(3)I2" + HOME_URL=http://www.cisco.com + BUILD_ID=6 + CISCO_RELEASE_INFO=/etc/shared/os-release + CISCO_RELEASE + end + + it "returns nexus_centos for centos os-release id" do + expect(File).to receive(:exist?).at_least(:once).with("/etc/shared/os-release").and_return(true) + expect(File).to receive(:exist?).at_least(:once).with("/etc/os-release").and_return(true) + expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content) + expect(File).to receive(:read).with("/etc/shared/os-release").and_return(cisco_release_content) + expect(plugin.platform_id_remap("centos")).to eq("nexus_centos") + end + end end describe "#platform_family_from_platform" do @@ -218,10 +255,6 @@ OS_DATA ID_LIKE="suse opensuse" VERSION_ID="15.0" PRETTY_NAME="openSUSE Leap 15.0" - ANSI_COLOR="0;32" - CPE_NAME="cpe:/o:opensuse:leap:15.0" - BUG_REPORT_URL="https://bugs.opensuse.org" - HOME_URL="https://www.opensuse.org/" OS_DATA end @@ -236,12 +269,36 @@ OS_DATA expect(plugin[:platform_version]).to eq("15.0") end end + + context "when on centos where version data in os-release is wrong" do + let(:os_data) do + <<~OS_DATA + NAME="CentOS Linux" + VERSION="7 (Core)" + ID="centos" + ID_LIKE="rhel fedora" + VERSION_ID="7" + PRETTY_NAME="CentOS Linux 7 (Core)" +OS_DATA + end + + before(:each) do + expect(File).to receive(:read).with("/etc/os-release").and_return(os_data) + expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)") + end + + it "should set platform, platform_family, and platform_version from os-release" do + plugin.run + expect(plugin[:platform]).to eq("centos") + expect(plugin[:platform_family]).to eq("rhel") + expect(plugin[:platform_version]).to eq("7.5.1804") + end + end end context "on system without /etc/os-release (legacy)" do let(:have_debian_version) { false } let(:have_redhat_release) { false } - let(:have_gentoo_release) { false } let(:have_exherbo_release) { false } let(:have_eos_release) { false } let(:have_suse_release) { false } @@ -262,7 +319,6 @@ OS_DATA plugin[:lsb] = Mash.new allow(File).to receive(:exist?).with("/etc/debian_version").and_return(have_debian_version) allow(File).to receive(:exist?).with("/etc/redhat-release").and_return(have_redhat_release) - allow(File).to receive(:exist?).with("/etc/gentoo-release").and_return(have_gentoo_release) allow(File).to receive(:exist?).with("/etc/exherbo-release").and_return(have_exherbo_release) allow(File).to receive(:exist?).with("/etc/Eos-release").and_return(have_eos_release) allow(File).to receive(:exist?).with("/etc/SuSE-release").and_return(have_suse_release) @@ -369,60 +425,60 @@ OS_DATA plugin.run expect(plugin[:platform]).to eq("ubuntu") end + end - describe "on 'guestshell' with /etc/os-release and overrides for Cisco Nexus" do + describe "on 'guestshell' with /etc/os-release and overrides for Cisco Nexus" do - let(:have_os_release) { true } + let(:have_os_release) { true } - let(:os_release_content) do - <<~OS_RELEASE - NAME="CentOS Linux" - VERSION="7 (Core)" - ID="centos" - ID_LIKE="rhel fedora" - VERSION_ID="7" - PRETTY_NAME="CentOS Linux 7 (Core)" - ANSI_COLOR="0;31" - CPE_NAME="cpe:/o:centos:centos:7" - HOME_URL="https://www.centos.org/" - BUG_REPORT_URL="https://bugs.centos.org/" - - CENTOS_MANTISBT_PROJECT="CentOS-7" - CENTOS_MANTISBT_PROJECT_VERSION="7" - REDHAT_SUPPORT_PRODUCT="centos" - REDHAT_SUPPORT_PRODUCT_VERSION="7" - - CISCO_RELEASE_INFO=/etc/shared/os-release - OS_RELEASE - end + let(:os_release_content) do + <<~OS_RELEASE + NAME="CentOS Linux" + VERSION="7 (Core)" + ID="centos" + ID_LIKE="rhel fedora" + VERSION_ID="7" + PRETTY_NAME="CentOS Linux 7 (Core)" + ANSI_COLOR="0;31" + CPE_NAME="cpe:/o:centos:centos:7" + HOME_URL="https://www.centos.org/" + BUG_REPORT_URL="https://bugs.centos.org/" + + CENTOS_MANTISBT_PROJECT="CentOS-7" + CENTOS_MANTISBT_PROJECT_VERSION="7" + REDHAT_SUPPORT_PRODUCT="centos" + REDHAT_SUPPORT_PRODUCT_VERSION="7" + + CISCO_RELEASE_INFO=/etc/shared/os-release + OS_RELEASE + end - let(:have_cisco_release) { true } - - let(:cisco_release_content) do - <<~CISCO_RELEASE - ID=nexus - ID_LIKE=wrlinux - NAME=Nexus - VERSION="7.0(3)I2(0.475E.6)" - VERSION_ID="7.0(3)I2" - PRETTY_NAME="Nexus 7.0(3)I2" - HOME_URL=http://www.cisco.com - BUILD_ID=6 - CISCO_RELEASE_INFO=/etc/shared/os-release - CISCO_RELEASE - end + let(:have_cisco_release) { true } - before do - expect(File).to receive(:read).at_least(:once).with("/etc/os-release").and_return(os_release_content) - expect(File).to receive(:read).with("/etc/shared/os-release").and_return(cisco_release_content) - end + let(:cisco_release_content) do + <<~CISCO_RELEASE + ID=nexus + ID_LIKE=wrlinux + NAME=Nexus + VERSION="7.0(3)I2(0.475E.6)" + VERSION_ID="7.0(3)I2" + PRETTY_NAME="Nexus 7.0(3)I2" + HOME_URL=http://www.cisco.com + BUILD_ID=6 + CISCO_RELEASE_INFO=/etc/shared/os-release + CISCO_RELEASE + end - it "should set platform to nexus_guestshell and platform_family to rhel" do - plugin.run - expect(plugin[:platform]).to eq("nexus_centos") - expect(plugin[:platform_family]).to eq("rhel") - expect(plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)") - end + before do + expect(File).to receive(:read).at_least(:once).with("/etc/os-release").and_return(os_release_content) + expect(File).to receive(:read).with("/etc/shared/os-release").and_return(cisco_release_content) + end + + it "should set platform to nexus_guestshell and platform_family to rhel" do + plugin.run + expect(plugin[:platform]).to eq("nexus_centos") + expect(plugin[:platform_family]).to eq("rhel") + expect(plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)") end end @@ -448,27 +504,6 @@ OS_DATA end end - describe "on gentoo" do - - let(:have_gentoo_release) { true } - - before(:each) do - plugin.lsb = nil - end - - it "should set platform and platform_family to gentoo" do - plugin.run - expect(plugin[:platform]).to eq("gentoo") - expect(plugin[:platform_family]).to eq("gentoo") - end - - it "should set platform_version to kernel release" do - expect(plugin).to receive(:`).with("/bin/uname -r").and_return("3.18.7-gentoo") - plugin.run - expect(plugin[:platform_version]).to eq("3.18.7-gentoo") - end - end - describe "on arista eos" do let(:have_eos_release) { true } @@ -814,7 +849,6 @@ OS_DATA context "on openSUSE and older SLES versions" do let(:have_suse_release) { true } - let(:have_os_release) { true } describe "without lsb_release results" do before(:each) do @@ -868,59 +902,5 @@ OS_DATA end end end - - describe "on Wind River Linux 5 for Cisco Nexus" do - let(:have_os_release) { true } - let(:os_release_info) do - { - "ID" => "nexus", - "ID_LIKE" => "wrlinux", - "NAME" => "Nexus", - "VERSION" => "7.0(3)I2(0.475E.6)", - "VERSION_ID" => "7.0(3)I2", - "PRETTY_NAME" => "Nexus 7.0(3)I2", - "HOME_URL" => "http://www.cisco.com", - "BUILD_ID" => "6", - "CISCO_RELEASE_INFO" => "/etc/os-release", - } - end - - it "should set platform to nexus and platform_family to wrlinux" do - allow(plugin).to receive(:os_release_info).and_return(os_release_info) - plugin.lsb = nil - plugin.run - - expect(plugin[:platform]).to eq("nexus") - expect(plugin[:platform_family]).to eq("wrlinux") - expect(plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)") - end - end - - describe "on Wind River Linux 7 for Cisco IOS-XR" do - let(:have_os_release) { true } - let(:os_release_info) do - { - "ID" => "ios_xr", - "ID_LIKE" => "cisco-wrlinux wrlinux", - "NAME" => "IOS XR", - "VERSION" => "6.0.0.14I", - "VERSION_ID" => "6.0.0.14I", - "PRETTY_NAME" => "Cisco IOS XR Software, Version 6.0.0.14I", - "BUILD_ID" => "2015-09-10-15-50-17", - "HOME_URL" => "http://www.cisco.com", - "CISCO_RELEASE_INFO" => "/etc/os-release", - } - end - - it "should set platform to ios_xr and platform_family to wrlinux" do - allow(plugin).to receive(:os_release_info).and_return(os_release_info) - plugin.lsb = nil - plugin.run - - expect(plugin[:platform]).to eq("ios_xr") - expect(plugin[:platform_family]).to eq("wrlinux") - expect(plugin[:platform_version]).to eq("6.0.0.14I") - end - end end end |