1. Fixed IP return to not filter lo/localhost and return it
as a proper interface

2. Fixed HP-UX netstat return to remove extraneous first line
of naming.

3. Updated tests to reflect changes

Signed-off-by: James Turnbull <ja...@lovedthanlost.net>
---
Local-branch: tickets/master/6495
 lib/facter/util/ip.rb                      |   18 ++++++++----------
 spec/unit/data/hpux_netstat_all_interfaces |    9 +++------
 spec/unit/util/ip_spec.rb                  |   20 ++++++++++----------
 3 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 23eeb9c..e4370dc 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -59,7 +59,7 @@ module Facter::Util::IP
         # at the end of interfaces.  So, we have to trim those trailing
         # characters.  I tried making the regex better but supporting all
         # platforms with a single regex is probably a bit too much.
-        output.scan(/^[-\w]+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| 
i.sub(/:$/, '') }.uniq
+        output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq
     end
 
     def self.get_all_interface_output
@@ -69,7 +69,7 @@ module Facter::Util::IP
         when 'SunOS'
             output = %x{/usr/sbin/ifconfig -a}
         when 'HP-UX'
-            output = %x{/bin/netstat -i}
+            output = %x{/bin/netstat -in | sed -e 1d}
         end
         output
     end
@@ -141,15 +141,13 @@ module Facter::Util::IP
         else
             output_int = get_single_interface_output(interface)
 
-            if interface != /^lo[0:]?\d?/
-                output_int.each_line do |s|
-                    if s =~ regex
-                        value = $1
+            output_int.each_line do |s|
+                if s =~ regex
+                    value = $1
                         if label == 'netmask' && convert_from_hex?(kernel)
                             value = value.scan(/../).collect do |byte| 
byte.to_i(16) end.join('.')
                         end
-                        tmp1.push(value)
-                    end
+                    tmp1.push(value)
                 end
             end
 
@@ -158,13 +156,13 @@ module Facter::Util::IP
             end
         end
     end
-  
+
     def self.get_network_value(interface)
         require 'ipaddr'
 
         ipaddress = get_interface_value(interface, "ipaddress")
         netmask = get_interface_value(interface, "netmask")
-        
+
         if ipaddress && netmask
             ip = IPAddr.new(ipaddress, Socket::AF_INET)
             subnet = IPAddr.new(netmask, Socket::AF_INET)
diff --git a/spec/unit/data/hpux_netstat_all_interfaces 
b/spec/unit/data/hpux_netstat_all_interfaces
index 7745fa8..0e8f9dc 100644
--- a/spec/unit/data/hpux_netstat_all_interfaces
+++ b/spec/unit/data/hpux_netstat_all_interfaces
@@ -1,6 +1,3 @@
-Name      Mtu  Network         Address         Ipkts   Ierrs Opkts   Oerrs Coll
-lan1      1500 15.12.0.0       host1.default.com 
-                                               572527659 0     1129421249 0    
 0   
-lan0      1500 172.54.85.0     host2.default.com 
-                                               519222647 0     329127145 0     
0   
-lo0       4136 loopback        localhost       14281117 0     14281125 0     0 
+lan1      1500 192.168.100.0   192.168.100.182 12964   0     900     0     0
+lan0      1500 192.168.100.0   192.168.100.181 12964   0     715     0     0   
+lo0       4136 127.0.0.0       127.0.0.1       98      0     98      0     0   
diff --git a/spec/unit/util/ip_spec.rb b/spec/unit/util/ip_spec.rb
index ceceb3f..1a545b8 100755
--- a/spec/unit/util/ip_spec.rb
+++ b/spec/unit/util/ip_spec.rb
@@ -20,11 +20,11 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interfaces().should == []
     end
 
-    it "should return a list with a single interface on Linux with a single 
interface" do
+    it "should return a list with a single interface and the loopback 
interface on Linux with a single interface" do
         sample_output_file = File.dirname(__FILE__) + 
'/../data/linux_ifconfig_all_with_single_interface'
         linux_ifconfig = File.new(sample_output_file).read()
         
Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig)
-        Facter::Util::IP.get_interfaces().should == ["eth0"]
+        Facter::Util::IP.get_interfaces().should == ["eth0", "lo"]
     end
 
     it "should return a list two interfaces on Darwin with two interfaces" do
@@ -46,7 +46,7 @@ describe Facter::Util::IP do
         hpux_netstat = File.new(sample_output_file).read()
         Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
         Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
-    end 
+    end
 
     it "should return a list of six interfaces on a GNU/kFreeBSD with six 
interfaces" do
         sample_output_file = File.dirname(__FILE__) + 
'/../data/debian_kfreebsd_ifconfig'
@@ -102,7 +102,7 @@ describe Facter::Util::IP do
         Facter.stubs(:value).with(:kernel).returns("HP-UX")
 
         Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == 
"168.24.80.71"
-    end 
+    end
 
     it "should return macaddress information for HP-UX" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/hpux_ifconfig_single_interface"
@@ -112,7 +112,7 @@ describe Facter::Util::IP do
         Facter.stubs(:value).with(:kernel).returns("HP-UX")
 
         Facter::Util::IP.get_interface_value("lan0", "macaddress").should == 
"00:13:21:BD:9C:B7"
-    end 
+    end
 
     it "should return macaddress with leading zeros stripped off for 
GNU/kFreeBSD" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/debian_kfreebsd_ifconfig"
@@ -132,7 +132,7 @@ describe Facter::Util::IP do
         Facter.stubs(:value).with(:kernel).returns("HP-UX")
 
         Facter::Util::IP.get_interface_value("lan0", "netmask").should == 
"255.255.255.0"
-    end 
+    end
 
     it "should return calculated network information for HP-UX" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/hpux_ifconfig_single_interface"
@@ -142,7 +142,7 @@ describe Facter::Util::IP do
         Facter.stubs(:value).with(:kernel).returns("HP-UX")
 
         Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0"
-    end 
+    end
 
     it "should return interface information for FreeBSD supported via an 
alias" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/6.0-STABLE_FreeBSD_ifconfig"
@@ -192,7 +192,7 @@ describe Facter::Util::IP do
         Facter.stubs(:value).with(:kernel).returns("HP-UX")
 
         Facter::Util::IP.get_interface_value("lan0", "netmask").should == 
"255.255.255.0"
-    end 
+    end
 
     it "should return a human readable netmask on Darwin" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/darwin_ifconfig_single_interface"
@@ -204,7 +204,7 @@ describe Facter::Util::IP do
 
         Facter::Util::IP.get_interface_value("en1", "netmask").should == 
"255.255.255.0"
     end
-    
+
     it "should return a human readable netmask on GNU/kFreeBSD" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/debian_kfreebsd_ifconfig"
 
@@ -218,7 +218,7 @@ describe Facter::Util::IP do
 
     it "should not get bonding master on interface aliases" do
         Facter.stubs(:value).with(:kernel).returns("Linux")
-        
+
         Facter::Util::IP.get_bonding_master("eth0:1").should be_nil
     end
 
-- 
1.7.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