summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2010-11-30 11:13:08 -0800
committerMatt Robinson <matt@puppetlabs.com>2010-11-30 11:13:08 -0800
commit3ebb5a550a6ce474dbc8edffbf15f90d60d3b711 (patch)
treec770be95c2851937278013ed0784432fb35289fd
parent2cbbc2c1063cc46b1fb77e69e41a872d2e5bfae1 (diff)
parent1985528c9e70095116f84d4f4849c149602fffec (diff)
downloadfacter-3ebb5a550a6ce474dbc8edffbf15f90d60d3b711.tar.gz
facter-3ebb5a550a6ce474dbc8edffbf15f90d60d3b711.tar.xz
facter-3ebb5a550a6ce474dbc8edffbf15f90d60d3b711.zip
Merge branch 'ticket/next/4754' into next
* ticket/next/4754: (#4754) Change is_virtual logic to not enumerate virtual types (#4754) Add support for Darwin and Parallels VM to "virtual" fact
-rw-r--r--lib/facter/virtual.rb36
-rw-r--r--spec/unit/virtual.rb97
2 files changed, 126 insertions, 7 deletions
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index a8afb60..8412a0a 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -1,6 +1,24 @@
require 'facter/util/virtual'
Facter.add("virtual") do
+ confine :kernel => "Darwin"
+
+ setcode do
+ require 'facter/util/macosx'
+ result = "physical"
+ output = Facter::Util::Macosx.profiler_data("SPDisplaysDataType")
+ 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/
+ end
+ result
+ end
+end
+
+
+Facter.add("virtual") do
confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX}
result = "physical"
@@ -53,18 +71,23 @@ Facter.add("virtual") do
# --- look for the vmware video card to determine if it is virtual => vmware.
# --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
result = "vmware" if p =~ /VM[wW]are/
+ # --- look for pci vendor id used by Parallels video card
+ # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005
+ result = "parallels" if p =~ /1ab8:|[Pp]arallels/
end
else
output = Facter::Util::Resolution.exec('dmidecode')
if not output.nil?
output.each_line do |pd|
- result = "vmware" if pd =~ /VMware|Parallels/
+ result = "parallels" if pd =~ /Parallels/
+ result = "vmware" if pd =~ /VMware/
end
else
output = Facter::Util::Resolution.exec('prtdiag')
if not output.nil?
output.each_line do |pd|
- result = "vmware" if pd =~ /VMware|Parallels/
+ result = "parallels" if pd =~ /Parallels/
+ result = "vmware" if pd =~ /VMware/
end
end
end
@@ -78,15 +101,14 @@ Facter.add("virtual") do
result
end
end
-
+
Facter.add("is_virtual") do
- confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX}
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin}
setcode do
- case Facter.value(:virtual)
- when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail", "zone", "hpvm"
+ if Facter.value(:virtual) != "physical" && Facter.value(:virtual) != "xen0"
"true"
- else
+ else
"false"
end
end
diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb
index a7767c9..9e8e358 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual.rb
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'facter'
require 'facter/util/virtual'
+require 'facter/util/macosx'
describe "Virtual fact" do
@@ -29,6 +30,91 @@ describe "Virtual fact" do
Facter::Util::Virtual.stubs(:hpvm?).returns(true)
Facter.fact(:virtual).value.should == "hpvm"
end
+
+ describe "on Darwin" do
+ it "should be parallels with Parallels vendor id" do
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
+ Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" })
+ Facter.fact(:virtual).value.should == "parallels"
+ end
+
+ it "should be parallels with Parallels vendor name" do
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
+ 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.fact(:kernel).stubs(:value).returns("Darwin")
+ Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" })
+ Facter.fact(:virtual).value.should == "vmware"
+ end
+
+ it "should be vmware with VMWare vendor name" do
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
+ Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" })
+ Facter.fact(:virtual).value.should == "vmware"
+ end
+ end
+
+ describe "on Linux" do
+ before do
+ Facter::Util::Virtual.stubs(:zone?).returns(false)
+ Facter::Util::Virtual.stubs(:openvz?).returns(false)
+ Facter::Util::Virtual.stubs(:vserver?).returns(false)
+ Facter::Util::Virtual.stubs(:xen?).returns(false)
+ Facter::Util::Virtual.stubs(:kvm?).returns(false)
+ end
+
+ it "should be parallels with Parallels vendor id from lspci" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005")
+ Facter.fact(:virtual).value.should == "parallels"
+ end
+
+ it "should be parallels with Parallels vendor name from lspci" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Parallels Display Adapter")
+ Facter.fact(:virtual).value.should == "parallels"
+ end
+
+ it "should be vmware with VMware vendor name from lspci" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter")
+ Facter.fact(:virtual).value.should == "vmware"
+ end
+
+ it "should be vmware with VMWare vendor name from dmidecode" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II")
+ Facter.fact(:virtual).value.should == "vmware"
+ end
+
+ it "should be parallels with Parallels vendor name from dmidecode" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device Information\nType: Video\nStatus: Disabled\nDescription: Parallels Video Adapter")
+ Facter.fact(:virtual).value.should == "parallels"
+ end
+
+ it "should be vmware with VMWare vendor name from prtdiag" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
+ Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform")
+ Facter.fact(:virtual).value.should == "vmware"
+ end
+
+ it "should be parallels with Parallels vendor name from prtdiag" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
+ Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform")
+ Facter.fact(:virtual).value.should == "parallels"
+ end
+ end
+
end
describe "is_virtual fact" do
@@ -49,6 +135,12 @@ describe "is_virtual fact" do
Facter.fact(:is_virtual).value.should == "false"
end
+ it "should be false when running on physical" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter.fact(:virtual).stubs(:value).returns("physical")
+ Facter.fact(:is_virtual).value.should == "false"
+ end
+
it "should be true when running on vmware" do
Facter.fact(:kernel).stubs(:value).returns("Linux")
Facter.fact(:virtual).stubs(:value).returns("vmware")
@@ -85,4 +177,9 @@ describe "is_virtual fact" do
Facter.fact(:is_virtual).value.should == "true"
end
+ it "should be true when running on parallels" do
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
+ Facter.fact(:virtual).stubs(:value).returns("parallels")
+ Facter.fact(:is_virtual).value.should == "true"
+ end
end