Skip to content

Commit

Permalink
OHAI-525 : can now detect qemu/kvm according the cpu type
Browse files Browse the repository at this point in the history
  • Loading branch information
tibux authored and btm committed Nov 25, 2013
1 parent f7b5d70 commit bed2a6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ohai/plugins/linux/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# It would be great if we could read pv_info in the kernel
# Wait for reply to: http://article.gmane.org/gmane.comp.emulators.kvm.devel/27885
if File.exists?("/proc/cpuinfo")
if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU/
if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
virtualization[:system] = "kvm"
virtualization[:role] = "guest"
end
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/plugins/linux/virtualization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@
@plugin[:virtualization][:role].should == "guest"
end

it "should set kvm guest if /proc/cpuinfo contains Common KVM processor" do
File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
File.stub(:read).with("/proc/cpuinfo").and_return("Common KVM processor")
@plugin.run
@plugin[:virtualization][:system].should == "kvm"
@plugin[:virtualization][:role].should == "guest"
end

it "should set kvm guest if /proc/cpuinfo contains Common 32-bit KVM processor" do
File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
File.stub(:read).with("/proc/cpuinfo").and_return("Common 32-bit KVM processor")
@plugin.run
@plugin[:virtualization][:system].should == "kvm"
@plugin[:virtualization][:role].should == "guest"
end

it "should not set virtualization if kvm isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
@plugin.run
Expand Down

0 comments on commit bed2a6a

Please sign in to comment.