summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Nordsieck <theo@opscode.com>2013-09-09 14:46:46 -0700
committerTheodore Nordsieck <theo@opscode.com>2013-09-11 16:13:23 -0700
commitec610d7d7a7e6bacbd44bd501d62d77cd039af8c (patch)
tree35f2cf0d9a8c9eb0a1916b62a973a234d0c291d4
parent2b79939d5b046fb1141a83415ac782a13a6dbd99 (diff)
downloadohai-ec610d7d7a7e6bacbd44bd501d62d77cd039af8c.tar.gz
Converted plugins/solaris2/kernel to Mixlib::ShellOut.
-rw-r--r--lib/ohai/plugins/solaris2/kernel.rb22
-rw-r--r--spec/spec_helper.rb3
-rw-r--r--spec/unit/plugins/solaris2/kernel_spec.rb8
3 files changed, 15 insertions, 18 deletions
diff --git a/lib/ohai/plugins/solaris2/kernel.rb b/lib/ohai/plugins/solaris2/kernel.rb
index 770205f2..9e14f458 100644
--- a/lib/ohai/plugins/solaris2/kernel.rb
+++ b/lib/ohai/plugins/solaris2/kernel.rb
@@ -20,21 +20,19 @@ Ohai.plugin do
provides "kernel/os"
collect_data do
- kernel[:os] = from("uname -s")
+ so = shell_out("uname -s")
+ kernel[:os] = so.stdout.split($/)[0]
modules = Mash.new
- popen4("modinfo") do |pid, stdin, stdout, stderr|
- stdin.close
-
- # EXAMPLE:
- # Id Loadaddr Size Info Rev Module Name
- # 6 1180000 4623 1 1 specfs (filesystem for specfs)
- module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
- stdout.each do |line|
- if mod = module_description.match(line)
- modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
- end
+ so = shell_out("modinfo")
+ # EXAMPLE:
+ # Id Loadaddr Size Info Rev Module Name
+ # 6 1180000 4623 1 1 specfs (filesystem for specfs)
+ module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
+ so.stdout.lines do |line|
+ if mod = module_description.match(line)
+ modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index cb541905..39db6136 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -53,12 +53,13 @@ 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(:from).with(from).and_return(value)
+ @plugin.should_receive(:shell_out).with(from).and_return(value)
@plugin.run
end
it "should set the #{mash.inspect}[:#{attribute}] to the value from '#{from}'" do
@plugin.run
+ value = value[1].split($/)[0]
if mash.is_a?(String)
@plugin[mash][attribute].should == value
elsif mash.is_a?(Array)
diff --git a/spec/unit/plugins/solaris2/kernel_spec.rb b/spec/unit/plugins/solaris2/kernel_spec.rb
index 23a6505f..008672ec 100644
--- a/spec/unit/plugins/solaris2/kernel_spec.rb
+++ b/spec/unit/plugins/solaris2/kernel_spec.rb
@@ -136,13 +136,11 @@ describe Ohai::System, "Solaris2.X kernel plugin" do
before(:each) do
@plugin = get_plugin("solaris2/kernel")
@plugin[:kernel] = Mash.new
- @plugin.stub(:from).with("uname -s").and_return("SunOS")
- stdin = StringIO.new
- @modinfo_stdout = StringIO.new(MODINFO)
- @plugin.stub(:popen4).with("modinfo").and_yield(nil, stdin, @modinfo_stdout, nil)
+ @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "SunOS\n", ""))
+ @plugin.stub(:shell_out).with("modinfo").and_return(mock_shell_out(0, MODINFO, ""))
end
- it_should_check_from_deep_mash("solaris2::kernel", "kernel", "os", "uname -s", "SunOS")
+ it_should_check_from_deep_mash("solaris2::kernel", "kernel", "os", "uname -s", [0, "SunOS\n", ""])
it "gives excruciating detail about kernel modules" do
@plugin.run