[Pkg-puppet-devel] [facter] 45/180: (FACT-231) Avoid system stutter for Darwin virtual fact

Stig Sandbeck Mathisen ssm at debian.org
Mon Jun 30 15:06:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 7387801eececb18909edb310995672c412146fba
Author: Samuel Keeley <samuel at dropbox.com>
Date:   Sun Jan 19 00:11:50 2014 -0600

    (FACT-231) Avoid system stutter for Darwin virtual fact
    
    Using SPDisplaysDataType causes lagging issues on pre-2013 Macs, so use
    other sources from system_profiler which do not have the issue and are
    also more reliable.
---
 lib/facter/virtual.rb     | 29 ++++++++++++++++++-----------
 spec/unit/virtual_spec.rb | 19 +++++++------------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index 98c2451..05f5e79 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -5,9 +5,11 @@
 # Resolution:
 #   Assumes physical unless proven otherwise.
 #
-#   On Darwin, use the macosx util module to acquire the SPDisplaysDataType,
-#   from that parse it to see if it's VMWare or Parallels pretending to be the
-#   display.
+#   On Darwin, use the macosx util module to acquire the SPHardwareDataType and
+#   SPEthernetDataType, from which it is possible to determine if the host is a
+#   VMware, Parallels, or VirtualBox.  This previously used SPDisplaysDataType
+#   which was not reliable if running headless, and also caused lagging issues
+#   on actual Macs.
 #
 #   On Linux, BSD, Solaris and HPUX:
 #   Much of the logic here is obscured behind util/virtual.rb, which rather
@@ -16,9 +18,9 @@
 #   contents of files in there.
 #   If after all the other tests, it's still seen as physical, then it tries to
 #   parse the output of the "lspci", "dmidecode" and "prtdiag" and parses them
-#   for obvious signs of being under VMWare, Parallels or VirtualBox.
+#   for obvious signs of being under VMware, Parallels or VirtualBox.
 #   Finally it checks for the existence of vmware-vmx, which would hint it's
-#   VMWare.
+#   VMware.
 #
 # Caveats:
 #   Many checks rely purely on existence of files.
@@ -32,13 +34,18 @@ Facter.add("virtual") do
   setcode do
     require 'facter/util/macosx'
     result = "physical"
-    output = Facter::Util::Macosx.profiler_data("SPDisplaysDataType")
+    # use SPHardwareDataType for VMware and VirtualBox, since it is the most
+    # reliable source.
+    output = Facter::Util::Macosx.profiler_data("SPHardwareDataType")
     if output.is_a?(Hash)
-      result = "parallels" if output["spdisplays_vendor-id"] =~ /0x1ab8/
-      result = "parallels" if output["spdisplays_vendor"] =~ /[Pp]arallels/
-      result = "vmware" if output["spdisplays_vendor-id"] =~ /0x15ad/
-      result = "vmware" if output["spdisplays_vendor"] =~ /VM[wW]are/
-      result = "virtualbox" if output["spdisplays_vendor-id"] =~ /0x80ee/
+      result = "vmware" if output["machine_model"] =~ /VMware/
+      result = "virtualbox" if output["boot_rom_version"] =~ /VirtualBox/
+    end
+    # Parallels passes through almost all of the host's hardware info to the
+    # virtual machine, so use a different field.
+    output = Facter::Util::Macosx.profiler_data("SPEthernetDataType")
+    if output.is_a?(Hash)
+      result = "parallels" if output["spethernet_subsystem-vendor-id"] =~ /0x1ab8/
     end
     result
   end
diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb
index a733abd..21afa14 100755
--- a/spec/unit/virtual_spec.rb
+++ b/spec/unit/virtual_spec.rb
@@ -52,23 +52,18 @@ describe "Virtual fact" do
       Facter.fact(:kernel).stubs(:value).returns("Darwin")
     end
 
-    it "should be parallels with Parallels vendor id" do
-      Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" })
+    it "should be parallels with Parallels ethernet vendor id" do
+      Facter::Util::Macosx.stubs(:profiler_data).returns({ "spethernet_subsystem-vendor-id" => "0x1ab8" })
       Facter.fact(:virtual).value.should == "parallels"
     end
 
-    it "should be parallels with Parallels vendor name" do
-      Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" })
-      Facter.fact(:virtual).value.should == "parallels"
-    end
-
-    it "should be vmware with VMWare vendor id" do
-      Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" })
-      Facter.fact(:virtual).value.should == "vmware"
+    it "should be virtualbox with VirtualBox boot rom name" do
+      Facter::Util::Macosx.stubs(:profiler_data).returns({ "boot_rom_version" => "VirtualBox" })
+      Facter.fact(:virtual).value.should == "virtualbox"
     end
 
-    it "should be vmware with VMWare vendor name" do
-      Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" })
+    it "should be vmware with VMware machine model" do
+      Facter::Util::Macosx.stubs(:profiler_data).returns({ "machine_model" => "VMware7,1" })
       Facter.fact(:virtual).value.should == "vmware"
     end
   end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list