Skip to content

Commit

Permalink
Converted plugins/freebsd/kernel to Mixlib::ShellOut.
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodore Nordsieck committed Sep 11, 2013
1 parent 0c4d9e6 commit c6e6708
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions lib/ohai/plugins/freebsd/kernel.rb
Expand Up @@ -21,17 +21,17 @@

collect_data do
kernel[:os] = kernel[:name]
kernel[:ident] = from("uname -i")
kernel[:securelevel] = from_with_regex("sysctl kern.securelevel", /kern.securelevel: (.+)$/)
so = shell_out("uname -i")
kernel[:ident] = so.stdout.split($/)[0]
so = shell_out("sysctl kern.securelevel")
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }

kld = Mash.new
popen4("#{ Ohai.abs_path( "/sbin/kldstat" )}") do |pid, stdin, stdout, stderr|
stdin.close
stdout.each do |line|
# 1 7 0xc0400000 97f830 kernel
if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
kld[$5] = { :size => $4, :refcount => $2 }
end
so = shell_out("#{ Ohai.abs_path( "/sbin/kldstat" )}")
so.stdout.lines do |line|
# 1 7 0xc0400000 97f830 kernel
if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
kld[$5] = { :size => $4, :refcount => $2 }
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/plugins/freebsd/kernel_spec.rb
Expand Up @@ -22,9 +22,9 @@
describe Ohai::System, "FreeBSD kernel plugin" do
before(:each) do
@plugin = get_plugin("freebsd/kernel")
@plugin.stub(:from).with("uname -i").and_return("foo")
@plugin.stub(:from_with_regex).with("sysctl kern.securelevel", /kern.securelevel: (.+)$/).and_return("kern.securelevel: 1")
@plugin.stub(:popen4).with("/sbin/kldstat").and_yield(0, StringIO.new, StringIO.new, StringIO.new)
@plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo\n", ""))
@plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1", ""))
@plugin.stub(:shell_out).with( Ohai.abs_path( "/sbin/kldstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", ""))
@plugin[:kernel] = Mash.new
@plugin[:kernel][:name] = "freebsd"
end
Expand Down

0 comments on commit c6e6708

Please sign in to comment.