diff options
author | Claire McQuin <mcquin@users.noreply.github.com> | 2014-01-07 12:19:44 -0800 |
---|---|---|
committer | Claire McQuin <mcquin@users.noreply.github.com> | 2014-01-07 12:19:44 -0800 |
commit | 12e4a5b607ad45c91cc488f6a0308268648eb7c4 (patch) | |
tree | 9d6eb2f83cad2daf8b86db19063290e74169544e | |
parent | 67f77fec4af5b8cfabd70ecbc177b71df4bdc7f8 (diff) | |
parent | 8eb8828bd7f652293bded73c40a48dd61dfa9e3f (diff) | |
download | ohai-12e4a5b607ad45c91cc488f6a0308268648eb7c4.tar.gz |
Merge pull request #256 from opscode/kernel-plugin-fix
Fix kernel[:modules] on :darwin
-rw-r--r-- | lib/ohai/plugins/kernel.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/darwin/kernel_spec.rb | 24 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb index 66af66c8..ee734379 100644 --- a/lib/ohai/plugins/kernel.rb +++ b/lib/ohai/plugins/kernel.rb @@ -86,7 +86,7 @@ Ohai.plugin(:Kernel) do so = shell_out("kextstat -k -l") so.stdout.lines do |line| if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/ - kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 } + modules[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 } end end diff --git a/spec/unit/plugins/darwin/kernel_spec.rb b/spec/unit/plugins/darwin/kernel_spec.rb index d2033a45..2df35d7d 100644 --- a/spec/unit/plugins/darwin/kernel_spec.rb +++ b/spec/unit/plugins/darwin/kernel_spec.rb @@ -24,23 +24,45 @@ describe Ohai::System, "Darwin kernel plugin" do @plugin = get_plugin("kernel") @plugin.stub(:collect_os).and_return(:darwin) @plugin.stub(:init_kernel).and_return({}) - @plugin.should_receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) + end + + it "should populate kernel[:modules] from `kextstat -k -l`" do + @plugin.stub(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "0", "")) + @plugin.stub(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, <<EOF, "")) + 8 0 0xffffff7f81aed000 0x41000 0x41000 com.apple.kec.corecrypto (1.0) <7 6 5 4 3 1> + 9 22 0xffffff7f807f3000 0x9000 0x9000 com.apple.iokit.IOACPIFamily (1.4) <7 6 4 3> + 10 30 0xffffff7f80875000 0x29000 0x29000 com.apple.iokit.IOPCIFamily (2.8) <7 6 5 4 3> +EOF + + modules = { + "com.apple.kec.corecrypto"=> + {"version"=>"1.0", "size"=>266240, "index"=>"8", "refcount"=>"0"}, + "com.apple.iokit.IOACPIFamily"=> + {"version"=>"1.4", "size"=>36864, "index"=>"9", "refcount"=>"22"}, + "com.apple.iokit.IOPCIFamily"=> + {"version"=>"2.8", "size"=>167936, "index"=>"10", "refcount"=>"30"}} + + @plugin.run + @plugin[:kernel][:modules].should eql(modules) end it "should not set kernel_machine to x86_64" do @plugin.stub(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "0", "")) + @plugin.stub(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) @plugin.run @plugin[:kernel][:machine].should_not == 'x86_64' end it "should set kernel_machine to x86_64" do @plugin.stub(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "1", "")) + @plugin.stub(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) @plugin.run @plugin[:kernel][:machine].should == 'x86_64' end it "should set the kernel_os to the kernel_name value" do @plugin.stub(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "1", "")) + @plugin.stub(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) @plugin.run @plugin[:kernel][:os].should == @plugin[:kernel][:name] end |