- prtdiag fails in many different environments; abstracting this away into a
   utility module.
 - Updated unit tests to reflect the change
 - Solaris manufacturer fact now calls the utility module instead of
   directly.

Signed-off-by: Adrien Thebo <adr...@puppetlabs.com>
---
Local-branch: ticket/master/7038
 lib/facter/util/manufacturer.rb                    |    7 +-
 lib/facter/util/prtdiag.rb                         |   29 ++++
 .../manufacturer/solaris_sunfire_v120_prtdiag      |   33 +++++
 spec/fixtures/manufacturer/solaris_t5220_prtdiag   |  136 ++++++++++++++++++++
 spec/unit/util/manufacturer_spec.rb                |    7 -
 spec/unit/util/prtdiag_spec.rb                     |   56 ++++++++
 6 files changed, 258 insertions(+), 10 deletions(-)
 create mode 100644 lib/facter/util/prtdiag.rb
 create mode 100644 spec/fixtures/manufacturer/solaris_sunfire_v120_prtdiag
 create mode 100644 spec/fixtures/manufacturer/solaris_t5220_prtdiag
 create mode 100755 spec/unit/util/prtdiag_spec.rb

diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb
index 8e9bde2..33389c9 100644
--- a/lib/facter/util/manufacturer.rb
+++ b/lib/facter/util/manufacturer.rb
@@ -1,6 +1,8 @@
 # mamufacturer.rb
 # Support methods for manufacturer specific facts
 
+require 'facter/util/prtdiag'
+
 module Facter::Manufacturer
 
     def self.get_dmi_table()
@@ -62,11 +64,10 @@ module Facter::Manufacturer
     end
 
     def self.prtdiag_sparc_find_system_info()
-        # Parses prtdiag for a SPARC architecture string, won't work with 
Solaris x86
-        output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag')
 
+        # Parses prtdiag for a SPARC architecture string, won't work with 
Solaris x86
         # System Configuration:  Sun Microsystems  sun4u Sun SPARC Enterprise 
M3000 Server
-        sysconfig = output.split("\n")[0]
+        sysconfig = Facter::Util::Prtdiag.system_configuration
         if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ 
then
             Facter.add('manufacturer') do
                 setcode do
diff --git a/lib/facter/util/prtdiag.rb b/lib/facter/util/prtdiag.rb
new file mode 100644
index 0000000..5edce5b
--- /dev/null
+++ b/lib/facter/util/prtdiag.rb
@@ -0,0 +1,29 @@
+# Module to safely query prtdiag
+#
+# prtdiag will fail if it is called on a non-solaris host, or if it is in a
+# zone, and it will hang if a service that prtdiag relies on is crashed.
+# This should abstract safely retrieving information from prtdiag
+
+require 'timeout'
+
+module Facter::Util::Prtdiag
+
+  def self.system_configuration
+    begin
+      Timeout.timeout(6) do
+        output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag')
+        if output
+          output.each_line do |pd|
+            return pd if pd =~ /System Configuration/
+          end
+        end
+      end
+    rescue Timeout::Error => detail
+      warn "Timed out while calling prtdiag"
+      # This call avoids zombies -- basically, create a thread that will
+      # dezombify all of the child processes that we're ignoring because
+      # of the timeout.
+      Thread.new { Process.waitall }
+    end
+  end
+end
diff --git a/spec/fixtures/manufacturer/solaris_sunfire_v120_prtdiag 
b/spec/fixtures/manufacturer/solaris_sunfire_v120_prtdiag
new file mode 100644
index 0000000..e9949b5
--- /dev/null
+++ b/spec/fixtures/manufacturer/solaris_sunfire_v120_prtdiag
@@ -0,0 +1,33 @@
+System Configuration:  Sun Microsystems  sun4u Sun Fire V120 (UltraSPARC-IIe 
648MHz)
+System clock frequency: 100 MHz
+Memory size: 2048 Megabytes
+
+========================= CPUs =========================
+
+                    Run   Ecache   CPU    CPU
+Brd  CPU   Module   MHz     MB    Impl.   Mask
+---  ---  -------  -----  ------  ------  ----
+ 0     0     0      648     0.5   13       3.3
+
+
+========================= IO Cards =========================
+
+     Bus#  Freq
+Brd  Type  MHz   Slot  Name                              Model
+---  ----  ----  ----  --------------------------------  ----------------------
+ 0   PCI-1  33    12   ebus                                                    
+ 0   PCI-1  33     3   pmu-pci10b9,7101                                        
+ 0   PCI-1  33     3   lomp                                                    
+ 0   PCI-1  33     7   isa                                                     
+ 0   PCI-1  33    12   network-pci108e,1101              SUNW,pci-eri          
+ 0   PCI-1  33    12   usb-pci108e,1103.1                                      
+ 0   PCI-1  33    13   ide-pci10b9,5229                                        
+ 0   PCI-1  33     5   network-pci108e,1101              SUNW,pci-eri          
+ 0   PCI-1  33     5   usb-pci108e,1103.1                                      
+ 0   PCI-2  33     8   scsi-glm                          Symbios,53C896        
+ 0   PCI-2  33     8   scsi-glm                          Symbios,53C896        
+ 0   PCI-2  33     5   network-pci108e,2bad              SUNW,pci-gem          
+
+
+No failures found in System
+===========================
diff --git a/spec/fixtures/manufacturer/solaris_t5220_prtdiag 
b/spec/fixtures/manufacturer/solaris_t5220_prtdiag
new file mode 100644
index 0000000..91a428d
--- /dev/null
+++ b/spec/fixtures/manufacturer/solaris_t5220_prtdiag
@@ -0,0 +1,136 @@
+System Configuration:  Sun Microsystems  sun4v SPARC Enterprise T5220
+Memory size: 32640 Megabytes
+
+================================ Virtual CPUs ================================
+
+
+CPU ID Frequency Implementation         Status
+------ --------- ---------------------- -------
+0      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+1      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+2      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+3      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+4      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+5      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+6      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+7      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+8      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+9      1165 MHz  SUNW,UltraSPARC-T2     on-line  
+10     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+11     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+12     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+13     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+14     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+15     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+16     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+17     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+18     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+19     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+20     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+21     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+22     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+23     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+24     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+25     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+26     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+27     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+28     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+29     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+30     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+31     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+32     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+33     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+34     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+35     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+36     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+37     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+38     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+39     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+40     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+41     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+42     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+43     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+44     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+45     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+46     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+47     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+48     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+49     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+50     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+51     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+52     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+53     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+54     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+55     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+56     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+57     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+58     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+59     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+60     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+61     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+62     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+63     1165 MHz  SUNW,UltraSPARC-T2     on-line  
+
+======================= Physical Memory Configuration ========================
+Segment Table:
+--------------------------------------------------------------
+Base           Segment  Interleave  Bank     Contains
+Address        Size     Factor      Size     Modules
+--------------------------------------------------------------
+0x0            32 GB    8           4 GB     MB/CMP0/BR0/CH0/D0
+                                             MB/CMP0/BR0/CH1/D0
+                                    4 GB     MB/CMP0/BR0/CH0/D1
+                                             MB/CMP0/BR0/CH1/D1
+                                    4 GB     MB/CMP0/BR1/CH0/D0
+                                             MB/CMP0/BR1/CH1/D0
+                                    4 GB     MB/CMP0/BR1/CH0/D1
+                                             MB/CMP0/BR1/CH1/D1
+                                    4 GB     MB/CMP0/BR2/CH0/D0
+                                             MB/CMP0/BR2/CH1/D0
+                                    4 GB     MB/CMP0/BR2/CH0/D1
+                                             MB/CMP0/BR2/CH1/D1
+                                    4 GB     MB/CMP0/BR3/CH0/D0
+                                             MB/CMP0/BR3/CH1/D0
+                                    4 GB     MB/CMP0/BR3/CH0/D1
+                                             MB/CMP0/BR3/CH1/D1
+
+
+================================ IO Devices ================================
+Slot +            Bus   Name +                            Model   
+Status            Type  Path                                      
+----------------------------------------------------------------------------
+MB/NET0           PCIE  network-pciex8086,105e                    
+                        /pci@0/pci@0/pci@1/pci@0/pci@2/network@0    
+MB/NET1           PCIE  network-pciex8086,105e                    
+                        /pci@0/pci@0/pci@1/pci@0/pci@2/network@0,1  
+MB/NET2           PCIE  network-pciex8086,105e                    
+                        /pci@0/pci@0/pci@1/pci@0/pci@3/network@0    
+MB/NET3           PCIE  network-pciex8086,105e                    
+                        /pci@0/pci@0/pci@1/pci@0/pci@3/network@0,1  
+MB/SASHBA         PCIE  scsi-pciex1000,58                 LSI,1068E
+                        /pci@0/pci@0/pci@2/scsi@0                   
+MB                PCIX  usb-pciclass,0c0310                       
+                        /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0  
+MB                PCIX  usb-pciclass,0c0310                       
+                        /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,1
+MB                PCIX  usb-pciclass,0c0320                       
+                        /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2
+
+============================ Environmental Status ============================
+Fan sensors:
+All fan sensors are OK.
+
+Temperature sensors:
+All temperature sensors are OK.
+
+Current sensors:
+All current sensors are OK.
+
+Voltage sensors:
+All voltage sensors are OK.
+
+Voltage indicators:
+All voltage indicators are OK.
+
+============================ FRU Status ============================
+All FRUs are enabled.
diff --git a/spec/unit/util/manufacturer_spec.rb 
b/spec/unit/util/manufacturer_spec.rb
index c3b372e..77644af 100644
--- a/spec/unit/util/manufacturer_spec.rb
+++ b/spec/unit/util/manufacturer_spec.rb
@@ -16,13 +16,6 @@ describe Facter::Manufacturer do
         Facter::Manufacturer.get_dmi_table().should be_nil
     end
 
-    it "should parse prtdiag output" do
-        Facter::Util::Resolution.stubs(:exec).returns("System Configuration:  
Sun Microsystems  sun4u Sun SPARC Enterprise M3000 Server")
-        Facter::Manufacturer.prtdiag_sparc_find_system_info()
-        Facter.value(:manufacturer).should == "Sun Microsystems"
-        Facter.value(:productname).should == "Sun SPARC Enterprise M3000 
Server"
-    end
-
     it "should strip white space on dmi output with spaces" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/linux_dmidecode_with_spaces"
         dmidecode_output = File.new(sample_output_file).read()
diff --git a/spec/unit/util/prtdiag_spec.rb b/spec/unit/util/prtdiag_spec.rb
new file mode 100755
index 0000000..3301c04
--- /dev/null
+++ b/spec/unit/util/prtdiag_spec.rb
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+require 'facter/util/prtdiag'
+
+def fixture_data(fixture_name)
+  fixture_path = File.join(SPECDIR, 'fixtures', 'manufacturer')
+  File.read(File.join(fixture_path, fixture_name))
+end
+
+describe Facter::Util::Prtdiag, 'prtdiag' do
+  describe 'on a solaris sunfire v120' do
+    before do
+      
Facter::Util::Prtdiag.expects("system_configuration").returns(fixture_data('solaris_sunfire_v120_prtdiag'))
+      Facter::Manufacturer.prtdiag_sparc_find_system_info()
+    end
+
+    it 'sets the correct manufacturer fact' do
+      Facter.value(:manufacturer).should == "Sun Microsystems"
+    end
+
+    it 'sets the correct productname fact' do
+      Facter.value(:productname).should == "Sun Fire V120 (UltraSPARC-IIe 
648MHz)"
+    end
+  end
+
+  describe 'on a solaris t5520' do
+    before do
+      
Facter::Util::Prtdiag.expects("system_configuration").returns(fixture_data('solaris_t5220_prtdiag'))
+      Facter::Manufacturer.prtdiag_sparc_find_system_info()
+    end
+
+    it 'sets the correct manufacturer fact' do
+      Facter.value(:manufacturer).should == "Sun Microsystems"
+    end
+
+    it 'sets the correct productname fact' do
+      Facter.value(:productname).should == "SPARC Enterprise T5220"
+    end
+  end
+
+  describe 'on an unknown SunOS sparc system' do
+    before do
+      Facter::Util::Prtdiag.expects("system_configuration").returns(nil)
+      Facter::Manufacturer.prtdiag_sparc_find_system_info()
+    end
+
+    it 'clears the manufacturer fact' do
+      Facter.value(:manufacturer).should be_nil
+    end
+
+    it 'clears the productname fact' do
+      Facter.value(:productname).should be_nil
+    end
+  end
+end
-- 
1.7.4.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to