The interface collection regex was leaving trailing
':' characters on the interface names, which meant
individual interfaces weren't quite right.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/facter/util/ip.rb |   16 ++++++----------
 spec/unit/util/ip.rb  |   16 +++++++++++++---
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 55b5e92..ca73a26 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -45,17 +45,13 @@ module Facter::Util::IP
     end
 
     def self.get_interfaces
-        int = nil
+        return [] unless output = Facter::Util::IP.get_all_interface_output()
 
-        output =  Facter::Util::IP.get_all_interface_output()
-
-        # We get lots of warnings on platforms that don't get an output
-        # made.
-        if output
-            int = output.scan(/^\w+[.:]?\d+[.:]?\d*/)
-        else
-            []
-        end
+        # Our regex appears to be stupid, in that it leaves colons sitting
+        # 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*/).collect { |i| i.sub(/:$/, '') }
     end
 
     def self.get_all_interface_output
diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip.rb
index 4f6e2c0..a1d2458 100644
--- a/spec/unit/util/ip.rb
+++ b/spec/unit/util/ip.rb
@@ -37,7 +37,7 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == []
     end
 
-    it "should return interface information for directly supported platforms" 
do
+    it "should return netmask information for Solaris" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/solaris_ifconfig_single_interface"
         solaris_ifconfig_interface = File.new(sample_output_file).read()
 
@@ -47,7 +47,7 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == 
"255.255.255.0"
     end
 
-    it "should return interface information for platforms supported via an 
alias" do
+    it "should return interface information for FreeBSD supported via an 
alias" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/6.0-STABLE_FreeBSD_ifconfig"
         ifconfig_interface = File.new(sample_output_file).read()
 
@@ -57,7 +57,7 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == 
"00:0e:0c:68:67:7c"
     end
 
-    it "should return interface information for OS X" do
+    it "should return macaddress information for OS X" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/Mac_OS_X_10.5.5_ifconfig"
         ifconfig_interface = File.new(sample_output_file).read()
 
@@ -67,6 +67,16 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interface_value("en1", "macaddress").should == 
"00:1b:63:ae:02:66"
     end
 
+    it "should return all interfaces correctly on OS X" do
+        sample_output_file = File.dirname(__FILE__) + 
"/../data/Mac_OS_X_10.5.5_ifconfig"
+        ifconfig_interface = File.new(sample_output_file).read()
+
+        
Facter::Util::IP.expects(:get_all_interface_output).returns(ifconfig_interface)
+        Facter.stubs(:value).with(:kernel).returns("Darwin")
+
+        Facter::Util::IP.get_interfaces().should == ["lo0", "gif0", "stf0", 
"en0", "fw0", "en1", "vmnet8", "vmnet1"]
+    end
+
     it "should return a human readable netmask on Solaris" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/solaris_ifconfig_single_interface"
         solaris_ifconfig_interface = File.new(sample_output_file).read()
-- 
1.6.1


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

Reply via email to