From bfc16f6bb9ffbd0064300e647481aab83b7f6212 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 22 Mar 2011 11:20:27 -0700 Subject: (#2714) Added timeout to prtdiag resulution - prtdiag would hang in specific cases, subsequently hanging facter. This should kill prtdiag if it takes excessively long. --- lib/facter/virtual.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 7c649ba..2801a43 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -119,8 +119,11 @@ Facter.add("virtual") do result = "vmware" if pd =~ /VMware/ result = "virtualbox" if pd =~ /VirtualBox/ end - else - output = Facter::Util::Resolution.exec('prtdiag') + elsif Facter.value(:kernel) == 'SunOS' + res = Facter::Util::Resolution.new('prtdiag') + res.timeout = 6 + res.setcode('prtdiag') + output = res.value if not output.nil? output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ -- cgit From 7f3e89de2d9da14bc7bef33709b79f48434eec6a Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 22 Mar 2011 12:40:16 -0700 Subject: (#2714) Fixed faulty test - Looks like some copy/paste added some linux tests that relied on prtdiag, which isn't possible. Corrected them to check against solaris. --- spec/unit/virtual_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index ac0a9bb..d169192 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -121,8 +121,10 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "virtualbox" end + end + describe "on Solaris" do it "should be vmware with VMWare vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") 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") @@ -130,7 +132,7 @@ describe "Virtual fact" do end it "should be parallels with Parallels vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") 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") @@ -138,7 +140,7 @@ describe "Virtual fact" do end it "should be virtualbox with VirtualBox vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") 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: innotek GmbH VirtualBox") -- cgit