Skip to content

Commit

Permalink
Merge branch 'OHAI-495'
Browse files Browse the repository at this point in the history
  • Loading branch information
btm committed Nov 4, 2013
2 parents a436cd2 + 3dfa00e commit 217afd9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
8 changes: 5 additions & 3 deletions lib/ohai/plugins/linux/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
elsif modules =~ /^vboxdrv/
virtualization[:system] = "vbox"
virtualization[:role] = "host"
elsif modules =~ /^vboxguest/
virtualization[:system] = "vbox"
virtualization[:role] = "guest"
end
end

Expand Down Expand Up @@ -103,6 +100,11 @@
virtualization[:system] = "xen"
virtualization[:role] = "guest"
end
when /Manufacturer: Oracle Corporation/
if so.stdout =~ /Product Name: VirtualBox/
virtualization[:system] = "vbox"
virtualization[:role] = "guest"
end
else
nil
end
Expand Down
28 changes: 20 additions & 8 deletions spec/unit/plugins/linux/virtualization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@
@plugin[:virtualization][:role].should == "host"
end

it "should set vbox guest if /proc/modules contains vboxguest" do
File.should_receive(:exists?).with("/proc/modules").and_return(true)
File.stub(:read).with("/proc/modules").and_return("vboxguest 177749 2 vboxsf")
@plugin.run
@plugin[:virtualization][:system].should == "vbox"
@plugin[:virtualization][:role].should == "guest"
end

it "should not set virtualization if vbox isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
@plugin.run
Expand Down Expand Up @@ -156,6 +148,26 @@
@plugin[:virtualization][:role].should == "guest"
end

it "should set vbox guest if dmidecode detects Oracle Corporation" do
vbox_dmidecode=<<-VBOX
Base Board Information
Manufacturer: Oracle Corporation
Product Name: VirtualBox
Version: 1.2
Serial Number: 0
Asset Tag: Not Specified
Features:
Board is a hosting board
Location In Chasis: Not Specified
Type: Motherboard
Contained Object Handles: 0
VBOX
@plugin.stub(:shell_out).with("dmidecode").and_return(mock_shell_out(0, vbox_dmidecode, ""))
@plugin.run
@plugin[:virtualization][:system].should == "vbox"
@plugin[:virtualization][:role].should == "guest"
end

it "should run dmidecode and not set virtualization if nothing is detected" do
@plugin.stub(:shell_out).with("dmidecode").and_return(mock_shell_out(0, "", ""))
@plugin.run
Expand Down

0 comments on commit 217afd9

Please sign in to comment.