From 0b9b6c53a9ff72cfd2630f9adb832e15bccb0e55 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 26 Oct 2013 14:15:10 -0700 Subject: [PATCH 1/2] Detect virtualbox guests via dmidecode so guest additions aren't required --- lib/ohai/plugins/linux/virtualization.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index 95b57ef4b..c6fa9492d 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -56,9 +56,6 @@ elsif modules =~ /^vboxdrv/ virtualization[:system] = "vbox" virtualization[:role] = "host" - elsif modules =~ /^vboxguest/ - virtualization[:system] = "vbox" - virtualization[:role] = "guest" end end @@ -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 From 3dfa00ebc1f40b4b99666f94d49d51ace605d535 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 31 Oct 2013 11:04:30 -0700 Subject: [PATCH 2/2] Update Virtualbox guest test for the dmidecode detection --- .../unit/plugins/linux/virtualization_spec.rb | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index dfd8c3e44..2a8f076d5 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -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 @@ -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