summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-26 21:06:48 -0800
committerTim Smith <tsmith@chef.io>2018-11-26 21:06:48 -0800
commit1ce3724e057afaeeca45ce24d313893bd3c944a9 (patch)
treed25e27963fcc5081186ebc2626ea98404d280604
parentb6b2d17b2729e991d5073839d8d57b8d2702b3e4 (diff)
downloadohai-1ce3724e057afaeeca45ce24d313893bd3c944a9.tar.gz
Use shellout properly for kernel version detection
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/platform.rb8
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb16
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index f7007685..8571e7f2 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -20,7 +20,9 @@ Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_family"
depends "lsb"
- # the platform mappings between /etc/os-release values and ohai platforms
+ # the platform mappings between the 'ID' field in /etc/os-release and the value
+ # ohai uses. If you're adding a new platform here and you want to change the name
+ # you'll want to add it here and then add a spec for the platform_id_remap method
unless defined?(PLATFORM_MAPPINGS)
PLATFORM_MAPPINGS = {
"rhel" => "redhat",
@@ -260,7 +262,7 @@ Ohai.plugin(:Platform) do
platform "exherbo"
# no way to determine platform_version in a rolling release distribution
# kernel release will be used - ex. 3.13
- platform_version `/bin/uname -r`.strip
+ platform_version shell_out("/bin/uname -r").stdout.strip
elsif File.exist?("/usr/lib/os-release")
contents = File.read("/usr/lib/os-release")
if /Clear Linux/ =~ contents
@@ -294,7 +296,7 @@ Ohai.plugin(:Platform) do
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
+ os_release_info["VERSION_ID"] || shell_out("/bin/uname -r").stdout.strip
end
end
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 3614d3d8..05d77763 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -238,7 +238,7 @@ 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")
+ allow(plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", ""))
plugin.run
expect(plugin[:platform]).to eq("arch")
expect(plugin[:platform_family]).to eq("arch")
@@ -273,12 +273,12 @@ OS_DATA
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)"
+ NAME="CentOS Linux"
+ VERSION="7 (Core)"
+ ID="centos"
+ ID_LIKE="rhel fedora"
+ VERSION_ID="7"
+ PRETTY_NAME="CentOS Linux 7 (Core)"
OS_DATA
end
@@ -541,6 +541,7 @@ OS_DATA
let(:have_exherbo_release) { true }
before(:each) do
+ allow(plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", ""))
plugin.lsb = nil
end
@@ -551,7 +552,6 @@ OS_DATA
end
it "should set platform_version to kernel release" do
- 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