From 1985528c9e70095116f84d4f4849c149602fffec Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 30 Nov 2010 10:59:42 -0800 Subject: (#4754) Change is_virtual logic to not enumerate virtual types While looking at the patch for adding parallels to the virtual types David Schmitt noticed that it might be easier just to list the types that are NOT virtual since there's fewer of them. Paired-with: Nick Lewis --- lib/facter/virtual.rb | 3 +-- spec/unit/virtual.rb | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index a3b7163..8412a0a 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -106,8 +106,7 @@ Facter.add("is_virtual") do 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", "parallels" + if Facter.value(:virtual) != "physical" && Facter.value(:virtual) != "xen0" "true" else "false" diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb index d607960..9e8e358 100644 --- a/spec/unit/virtual.rb +++ b/spec/unit/virtual.rb @@ -135,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") -- cgit