summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Nordsieck <theo@opscode.com>2013-09-10 12:01:18 -0700
committerTheodore Nordsieck <theo@opscode.com>2013-09-11 16:13:25 -0700
commit5a6ae9c9c4975895841bbddbd6a2d7e059fed7fe (patch)
treee2942b33f86a01ba82eb68a659617aecfa6f43e3
parent7b34d7e41f4efd8dc5554da1c3d5069d56288cf6 (diff)
downloadohai-5a6ae9c9c4975895841bbddbd6a2d7e059fed7fe.tar.gz
Converted plugins/linux/kernel converted to Mixlib::ShellOut.
-rw-r--r--lib/ohai/plugins/linux/kernel.rb13
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/unit/plugins/linux/kernel_spec.rb17
3 files changed, 21 insertions, 11 deletions
diff --git a/lib/ohai/plugins/linux/kernel.rb b/lib/ohai/plugins/linux/kernel.rb
index c080f8c8..47a83569 100644
--- a/lib/ohai/plugins/linux/kernel.rb
+++ b/lib/ohai/plugins/linux/kernel.rb
@@ -20,15 +20,14 @@ Ohai.plugin do
provides "kernel"
collect_data do
- kernel[:os] = from("uname -o")
+ so = shell_out("uname -o")
+ kernel[:os] = so.stdout.split($/)[0]
kext = Mash.new
- popen4("env lsmod") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
- kext[$1] = { :size => $2, :refcount => $3 }
- end
+ so = shell_out("env lsmod")
+ so.stdout.lines do |line|
+ if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
+ kext[$1] = { :size => $2, :refcount => $3 }
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 39db6136..51786d15 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -53,7 +53,7 @@ end
# the mash variable may be an array listing multiple levels of Mash hierarchy
def it_should_check_from_deep_mash(plugin, mash, attribute, from, value)
it "should get the #{mash.inspect}[:#{attribute}] value from '#{from}'" do
- @plugin.should_receive(:shell_out).with(from).and_return(value)
+ @plugin.should_receive(:shell_out).with(from).and_return(mock_shell_out(value[0], value[1], value[2]))
@plugin.run
end
diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb
index 462d4b5a..557a0d00 100644
--- a/spec/unit/plugins/linux/kernel_spec.rb
+++ b/spec/unit/plugins/linux/kernel_spec.rb
@@ -23,14 +23,25 @@ require File.expand_path(File.dirname(__FILE__) + '/../../path/ohai_plugin_commo
describe Ohai::System, "Linux kernel plugin" do
before(:each) do
+ @env_lsmod = <<-ENV_LSMOD
+Module Size Used by
+dm_crypt 22321 0
+psmouse 81038 0
+acpiphp 23314 0
+microcode 18286 0
+serio_raw 13031 0
+virtio_balloon 13168 0
+floppy 55441 0
+ENV_LSMOD
@plugin = get_plugin("linux/kernel")
- @plugin.stub(:from).with("uname -o").and_return("Linux")
- @plugin.should_receive(:popen4).with("env lsmod").at_least(1).times
+ @plugin.stub(:shell_out).with("uname -o").and_return(mock_shell_out(0, "Linux", ""))
+ @plugin.stub(:shell_out).with("env lsmod").and_return(mock_shell_out(0, @env_lsmod, ""))
+ @plugin.should_receive(:shell_out).with("env lsmod").at_least(1).times
@plugin[:kernel] = {}
@plugin.run
end
- it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", "Linux")
+ it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", [0, "Linux", ""])
test_plugin([ "kernel", "linux/kernel" ], [ "uname", "env" ]) do | p |
p.test([ "centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04" ], [ "x86", "x64" ], [[]],