diff options
author | Tim Smith <tsmith@chef.io> | 2018-11-26 14:45:54 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-11-26 14:45:54 -0800 |
commit | e7fa47a00774fc48f85b86349261e50db48ae47f (patch) | |
tree | 5be3f7a3a79064794a25d17e3d6e1973588020c1 | |
parent | 4bd9041d28a3fb2badf7a4b8ca4b33fc417432fc (diff) | |
download | ohai-e7fa47a00774fc48f85b86349261e50db48ae47f.tar.gz |
Use the absolute path to uname
Avoid having to search path when it's always in the same path
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/linux/platform.rb | 8 | ||||
-rw-r--r-- | spec/unit/plugins/linux/platform_spec.rb | 33 |
2 files changed, 29 insertions, 12 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb index c928d503..a51a8e2c 100644 --- a/lib/ohai/plugins/linux/platform.rb +++ b/lib/ohai/plugins/linux/platform.rb @@ -264,7 +264,7 @@ Ohai.plugin(:Platform) do # the gentoo release version is the base version used to bootstrap # a node and doesn't have a lot of meaning in a rolling release distro # kernel release will be used - ex. 3.18.7-gentoo - platform_version `uname -r`.strip + platform_version `/bin/uname -r`.strip elsif File.exist?("/etc/slackware-version") platform "slackware" platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join @@ -272,12 +272,12 @@ Ohai.plugin(:Platform) do platform "arch" # no way to determine platform_version in a rolling release distribution # kernel release will be used - ex. 2.6.32-ARCH - platform_version `uname -r`.strip + platform_version `/bin/uname -r`.strip elsif File.exist?("/etc/exherbo-release") platform "exherbo" # no way to determine platform_version in a rolling release distribution # kernel release will be used - ex. 3.13 - platform_version `uname -r`.strip + platform_version `/bin/uname -r`.strip elsif File.exist?("/etc/alpine-release") platform "alpine" platform_version File.read("/etc/alpine-release").strip @@ -339,7 +339,7 @@ Ohai.plugin(:Platform) do # where we've traditionally used the kernel as the version # @return String the OS version def determine_os_version - os_release_info["VERSION_ID"] || `uname -r`.strip + os_release_info["VERSION_ID"] || `/bin/uname -r`.strip end collect_data(:linux) do diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 76fef939..9446b5be 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -158,12 +158,6 @@ describe Ohai::System, "Linux plugin platform" do allow(::File).to receive(:exist?).with("/etc/os-release").and_return(true) end - # @todo - # - fix and test arch version detection - # - test fallback platform_family mapping - # - test the platform_family remap method - # - test the platform remap method - context "when os-release data is correct" do let(:os_data) do <<~OS_DATA @@ -188,6 +182,29 @@ OS_DATA end end + context "when os-release data is missing a version_id" do + let(:os_data) do + <<~OS_DATA + NAME="Arch Linux" + PRETTY_NAME="Arch Linux" + ID=arch + ID_LIKE=archlinux +OS_DATA + end + + before(:each) do + expect(File).to receive(:read).with("/etc/os-release").and_return(os_data) + end + + it "should set platform_version using kernel version from uname" do + expect(plugin).to receive(:`).with("/bin/uname -r").and_return("3.18.2-2-ARCH") + plugin.run + expect(plugin[:platform]).to eq("arch") + expect(plugin[:platform_family]).to eq("arch") + expect(plugin[:platform_version]).to eq("3.18.2-2-ARCH") + end + end + context "when platform requires remapping" do let(:os_data) do <<~OS_DATA @@ -476,7 +493,7 @@ OS_DATA end it "should set platform_version to kernel release" do - expect(plugin).to receive(:`).with("uname -r").and_return("3.18.7-gentoo") + 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 @@ -548,7 +565,7 @@ OS_DATA end it "should set platform_version to kernel release" do - expect(plugin).to receive(:`).with("uname -r").and_return("3.18.2-2-ARCH") + expect(plugin).to receive(:`).with("/bin/uname -r").and_return("3.18.2-2-ARCH") plugin.run expect(plugin[:platform_version]).to eq("3.18.2-2-ARCH") end |